0.2.1 • Published 5 years ago

babel-plugin-remove-test-code v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

babel-plugin-remove-test-code

Babel plugin that remove test codes from the file

Usage

You can write a unit-test in the same file. This Babel plugin removes all test code not to bundle it into the production build.

// main.js
const message = "!";

while (1) {
  alert(message);
}

test("message", () => {
  expect(message).toBe("!");
});

will be below in after be processed by this plugin

// main.js
const message = "!";

while (1) {
  alert(message);
}

Currently, this supports MagicComment (default) and Jest.

Configuration

When you use Jest as a test framework,

{
  "plugins": [["babel-plugin-remove-test-code", { "targets": ["Jest"] }]]
}

TODO

  • magic comments to remove or not to remove
  • cares declared variable by nested destructuring
  • (Jest) the Jest Object & mockFn
  • Examples
  • cares global objects (global, window, self, this, etc...)

Notes

  • binging API instead of manual variable declaration search
    (not possible for assignment of global can't be detected)
  • skip children if out of range
    (not possible due to enter exit)

License

MIT