Bug fixing for Node 10 (#7931)
This commit is contained in:
parent
f03adbadf4
commit
51db3e9a5d
@ -33,7 +33,9 @@ testContext.global = testContext;
|
||||
runModuleInTestContext("@babel/polyfill", __filename);
|
||||
|
||||
// Populate the "babelHelpers" global with Babel's helper utilities.
|
||||
runCodeInTestContext(buildExternalHelpers());
|
||||
runCodeInTestContext(buildExternalHelpers(), {
|
||||
filename: path.join(__dirname, "babel-helpers-in-memory.js"),
|
||||
});
|
||||
|
||||
/**
|
||||
* A basic implementation of CommonJS so we can execute `@babel/polyfill` inside our test context.
|
||||
@ -75,13 +77,10 @@ function runModuleInTestContext(id: string, relativeFilename: string) {
|
||||
*
|
||||
* Exposed for unit tests, not for use as an API.
|
||||
*/
|
||||
export function runCodeInTestContext(
|
||||
code: string,
|
||||
opts: { filename?: string } = {},
|
||||
) {
|
||||
const filename = opts.filename || null;
|
||||
const dirname = filename ? path.dirname(filename) : null;
|
||||
const req = filename ? id => runModuleInTestContext(id, filename) : null;
|
||||
export function runCodeInTestContext(code: string, opts: { filename: string }) {
|
||||
const filename = opts.filename;
|
||||
const dirname = path.dirname(filename);
|
||||
const req = id => runModuleInTestContext(id, filename);
|
||||
|
||||
const module = {
|
||||
id: filename,
|
||||
|
||||
@ -4,20 +4,35 @@ describe("helper-transform-fixture-test-runner", function() {
|
||||
it("should not execute code in Node's global context", function() {
|
||||
try {
|
||||
global.foo = "outer";
|
||||
runCodeInTestContext(`
|
||||
expect(global.foo).toBeUndefined();
|
||||
global.foo = "inner";
|
||||
`);
|
||||
runCodeInTestContext(
|
||||
`
|
||||
expect(global.foo).toBeUndefined();
|
||||
global.foo = "inner";
|
||||
`,
|
||||
{
|
||||
filename: `${__filename}.fake1`,
|
||||
},
|
||||
);
|
||||
|
||||
expect(global.foo).toBe("outer");
|
||||
runCodeInTestContext(`
|
||||
expect(global.foo).toBe("inner");
|
||||
`);
|
||||
runCodeInTestContext(
|
||||
`
|
||||
expect(global.foo).toBe("inner");
|
||||
`,
|
||||
{
|
||||
filename: `${__filename}.fake2`,
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
delete global.foo;
|
||||
runCodeInTestContext(`
|
||||
delete global.foo;
|
||||
`);
|
||||
runCodeInTestContext(
|
||||
`
|
||||
delete global.foo;
|
||||
`,
|
||||
{
|
||||
filename: `${__filename}.fake3`,
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user