New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run Babel's unittests in a custom sandbox. #5135
Conversation
@loganfsmyth, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hzoo, @frantic and @zertosh to be potential reviewers. |
e03e5ed
to
8cff117
Compare
8cff117
to
a34b5b6
Compare
Current coverage is 89.23% (diff: 96.96%)@@ master #5135 diff @@
==========================================
Files 203 203
Lines 9828 9853 +25
Methods 1071 1072 +1
Messages 0 0
Branches 2616 2622 +6
==========================================
+ Hits 8768 8792 +24
- Misses 1060 1061 +1
Partials 0 0
|
Alright they actually pass now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍. It does not affect the build time so much.
I think it's only slow on node 0.10/0.12 but we are dropping anyway. |
result = babel.transform(execCode, execOpts); | ||
execCode = result.code; | ||
|
||
try { | ||
resultExec = runExec(execOpts, execCode, execDirName); | ||
resultExec = runCodeInTestContext(execCode, execOpts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if the test files would (default) export a function / promise / boolean instead of relying on top level return, but fixing this would require refactoring all tests 😖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All internal/non breaking so someone can do it 😄
filename = require.resolve(path.resolve(path.dirname(relativeFilename), id)); | ||
} else { | ||
// This code is a gross hack using internal APIs, but we also have the same logic in babel-core | ||
// to resolve presets and plugins, so if this breaks, we'll have even worse issues to deal with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
const relativeMod = new Module(); | ||
relativeMod.id = relativeFilename; | ||
relativeMod.filename = relativeFilename; | ||
relativeMod.paths = Module._nodeModulePaths(path.dirname(relativeFilename)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, for resolving inside node_modules
dirs as would be seen by the test file
}; | ||
|
||
// Expose the test options as "opts", but otherwise run the test in a CommonJS-like environment. | ||
// Note: This isn't doing .call(module.exports, ...) because some of our tests currently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, the top level this
in sloppy commonjs is supposed to be the exports? 😱
Per Slack conversations, this will allow us to be more confident that Babel itself isn't accidentally relying on logic polyfilled by
babel-polyfill
as it is no longer loaded globally, but rather sandboxed to its own context.