Skip to content

Commit

Permalink
Add tests for sandboxing behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Feb 4, 2017
1 parent 7f52dca commit b888759
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ function runModuleInTestContext(id: string, relativeFilename: string) {
}

/**
* Run the given snippet of code inside a CommonJS module
* Run the given snippet of code inside a CommonJS module.
*
* Exposed for unit tests, not for use as an API.
*/
function runCodeInTestContext(code: string, opts: {filename?: string} = {}) {
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;
Expand Down
17 changes: 17 additions & 0 deletions packages/babel-helper-transform-fixture-test-runner/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from "assert";
import { runCodeInTestContext } from "..";

describe("helper-transform-fixture-test-runner", function() {
it("should not execute code in Node's global context", function() {
runCodeInTestContext(`
global.foo = 4;
`);
const foo = global.foo;
runCodeInTestContext(`
var foo = global.foo;
delete global.foo;
assert.equal(foo, 4);
`);
assert.equal(foo, undefined);
});
});

0 comments on commit b888759

Please sign in to comment.