babel-tape-runner icon indicating copy to clipboard operation
babel-tape-runner copied to clipboard

Why does this lib require babel-polyfill?

Open olegskl opened this issue 8 years ago • 7 comments

I'm a maintainer of gulp-stylelint which uses babel-tape-runner to run tests. The tests are run on Travis in Node v0.12, v4, and v5.

One day I've added Object.assign to my code, oblivious to the fact that it doesn't exist in Node v0.12. The tests didn't fail, so I published a release and soon received a bug report.

I've looked at the babel-tape-runner code and found this line:

require('babel-polyfill')

Which obviously polyfills Object.assign, but I'm not sure why babel-tape-runner itself needs it. There's nothing to polyfill in babel-tape-runner.

The problem is that polyfills are also applied to the code under test. Is it possible to remove them?

olegskl avatar Apr 14 '16 08:04 olegskl

Reference: https://github.com/wavded/babel-tape-runner/issues/7

Historically, Babel 5 had it included by default in their register. No way to include it in the .babelrc (still?) so if you wanted it, you'd have to either include it in every test file or in the first test that is "required".

See your point though, perhaps a flag to turn it off?

wavded avatar Apr 14 '16 12:04 wavded

Perhaps, instead of a flag, it would be an interesting idea to add a --require option similar to what mocha does. So we could do:

babel-tape-runner test/*.js --require babel-polyfill

olegskl avatar Apr 14 '16 14:04 olegskl

I like that. Care to do a PR? That would be breaking change but feels like a better API to me.

wavded avatar Apr 14 '16 14:04 wavded

After forking and looking at the code more closely I came to a conclusion that this library is not needed at all and can safely be deprecated in favor of using vanilla tape which already has the require flag.

My scenario calls for:

tape -r babel-register test/*.spec.js

People using async/await in their tests might be interested in:

tape -r babel-register -r babel-polyfill test/*.spec.js

olegskl avatar Apr 15 '16 09:04 olegskl

@olegskl how is this coming along? Can you submit a PR? I concur it isn't required anymore. /cc @wavded

snuggs avatar Aug 30 '16 04:08 snuggs

This is not required anymore. Tape can work with babel out of the box.

olegskl avatar Aug 30 '16 08:08 olegskl

Yep, @olegskl is right. This lib is not needed anymore. It would be preferred to use the tape lib directly.

wavded avatar Aug 30 '16 14:08 wavded