Skip to content

Commit

Permalink
fix: incorrect fixture callsite position
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Oct 16, 2019
1 parent 6b6b5ef commit 9875daf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -62,11 +62,12 @@ function runModuleInTestContext(id: string, relativeFilename: string) {
const req = id => runModuleInTestContext(id, filename);

const src = fs.readFileSync(filename, "utf8");
const code = `(function (exports, require, module, __filename, __dirname) {${src}\n});`;
const code = `(function (exports, require, module, __filename, __dirname) {\n${src}\n});`;

vm.runInContext(code, testContext, {
filename,
displayErrors: true,
lineOffset: 1,
}).call(module.exports, module.exports, req, module, filename, dirname);

return module.exports;
Expand Down Expand Up @@ -94,10 +95,11 @@ export function runCodeInTestContext(code: string, opts: { filename: string }) {
// 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
// rely on 'this === global'.
const src = `(function(exports, require, module, __filename, __dirname, opts) {${code}\n});`;
const src = `(function(exports, require, module, __filename, __dirname, opts) {\n${code}\n});`;
return vm.runInContext(src, testContext, {
filename,
displayErrors: true,
lineOffset: 1,
})(module.exports, req, module, filename, dirname, opts);
} finally {
process.chdir(oldCwd);
Expand Down
Expand Up @@ -40,7 +40,7 @@ describe("helper-transform-fixture-test-runner", function() {
filename: `${__filename}.fake4`,
};
runCodeInTestContext(
`try { throw new Error()} catch (e) {
`try { throw new Error() } catch (e) {
opts.stack = e.stack
}
`,
Expand Down

0 comments on commit 9875daf

Please sign in to comment.