Skip to content

Commit

Permalink
Hide more jest frames
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 24, 2022
1 parent fefa347 commit 2fb805c
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions packages/babel-core/test/errors-stacks.js
Expand Up @@ -9,19 +9,22 @@ function expectError(run) {
run();
} catch (e) {
let { stack } = e;
stack = replaceAll(stack, import.meta.url, "<URL PLACEHOLDER>").replace(
/(?:\n\s*at[^\n]+?<URL PLACEHOLDER>[^\n]+)+/g,
"\n ... frames from this test file ...",
);
// Remove absolute URLs
stack = replaceAll(stack, process.cwd(), "<CWD>");
stack = replaceAll(stack, "file://<CWD>", "<CWD>");
// Remove jest-related stack frames
stack = stack.replace(
/(?:\n\s*at[^\n]+?node_modules\/(?:jest|piscina)[^\n]+)+/g,
"\n ... internal jest frames ...",
/(?:\n\s*at ((?:async )?[\w.]+)?[^\n]+?node_modules\/(?:@?jest|piscina)[^\n]+)+/g,
"\n at $1 (... internal jest frames ...)",
);
// Remove node internal frames, since they change by version
stack = stack.replace(
/(?:\n\s*at ((?:async )?[\w.]+)? ?\((?:node:)?internal\/[^\n]+)+/g,
"\n at $1 (... internal node frames ...)",
);
stack = replaceAll(stack, process.cwd(), "<CWD>");
// Replace line/column numbers, since they are affected by how
// the code is compiled.
stack = stack.replace(/:\d+:\d+\)$/gm, ":_:_)");
stack = stack.replace(/\d*:\d+:\d+(\)?)$/gm, ":_:_$1");
return expect(stack);
}
throw new Error("It should have thrown an error.");
Expand All @@ -40,8 +43,10 @@ describe("@babel/core errors", function () {
"Error: Error inside config!
at myConfig (<CWD>/packages/babel-core/test/fixtures/errors/error-config-function/babel.config.js:_:_)
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -56,8 +61,10 @@ describe("@babel/core errors", function () {
at g (<CWD>/packages/babel-core/test/fixtures/errors/error-config-function-more-frames/babel.config.js:_:_)
at myConfig (<CWD>/packages/babel-core/test/fixtures/errors/error-config-function-more-frames/babel.config.js:_:_)
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async runTestBlock (... internal jest frames ...)"
`);
});

Expand All @@ -69,14 +76,10 @@ describe("@babel/core errors", function () {
}).toMatchInlineSnapshot(`
"Error: Error inside config!
at Object.<anonymous> (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file/babel.config.js:_:_)
at Module._compile (node:internal/modules/cjs/loader:_:_)
at Module._extensions..js (node:internal/modules/cjs/loader:_:_)
at Module.load (node:internal/modules/cjs/loader:_:_)
at Module._load (node:internal/modules/cjs/loader:_:_)
at Module.require (node:internal/modules/cjs/loader:_:_)
at require (node:internal/modules/cjs/helpers:_:_)
at require (... internal node frames ...)
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)"
`);
});

Expand All @@ -90,12 +93,7 @@ describe("@babel/core errors", function () {
at f (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at g (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at Object.<anonymous> (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at Module._compile (node:internal/modules/cjs/loader:_:_)
at Module._extensions..js (node:internal/modules/cjs/loader:_:_)
at Module.load (node:internal/modules/cjs/loader:_:_)
at Module._load (node:internal/modules/cjs/loader:_:_)
at Module.require (node:internal/modules/cjs/loader:_:_)
at require (node:internal/modules/cjs/helpers:_:_)
at require (... internal node frames ...)
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)"
`);
});
Expand All @@ -113,15 +111,12 @@ describe("@babel/core errors", function () {
at f (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at g (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at Object.<anonymous> (<CWD>/packages/babel-core/test/fixtures/errors/error-config-file-more-frames/babel.config.js:_:_)
at Module._compile (node:internal/modules/cjs/loader:_:_)
at Module._extensions..js (node:internal/modules/cjs/loader:_:_)
at Module.load (node:internal/modules/cjs/loader:_:_)
at Module._load (node:internal/modules/cjs/loader:_:_)
at Module.require (node:internal/modules/cjs/loader:_:_)
at require (node:internal/modules/cjs/helpers:_:_)
at require (... internal node frames ...)
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
} finally {
Error.stackTraceLimit -= INC;
Expand All @@ -137,8 +132,10 @@ describe("@babel/core errors", function () {
"Error: Error while parsing config - JSON5: invalid character '}' at 3:1
at <CWD>/packages/babel-core/test/fixtures/errors/invalid-json/babel.config.json
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -151,8 +148,10 @@ describe("@babel/core errors", function () {
"Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel
at <CWD>/packages/babel-core/test/fixtures/errors/use-exclude/babel.config.js
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -165,8 +164,10 @@ describe("@babel/core errors", function () {
}).toMatchInlineSnapshot(`
"Error: Configuration contains string/RegExp pattern, but no filename was passed to Babel
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -182,8 +183,10 @@ describe("@babel/core errors", function () {
\`\`\`
See https://babeljs.io/docs/en/options#filename for more information.
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -196,8 +199,10 @@ describe("@babel/core errors", function () {
"Error: .sourceType must be \\"module\\", \\"script\\", \\"unambiguous\\", or undefined
at <CWD>/packages/babel-core/test/fixtures/errors/invalid-option/babel.config.json
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -210,8 +215,10 @@ describe("@babel/core errors", function () {
).toMatchInlineSnapshot(`
"Error: .sourceType must be \\"module\\", \\"script\\", \\"unambiguous\\", or undefined
at Module.parseSync (<CWD>/packages/babel-core/lib/parse.js:_:_)
... frames from this test file ...
... internal jest frames ..."
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at expectError (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at <CWD>/packages/babel-core/test/errors-stacks.js?:_:_
at async (... internal jest frames ...)"
`);
});

Expand All @@ -230,7 +237,7 @@ describe("@babel/core errors", function () {
}
}).toMatchInlineSnapshot(`
"Error: Internal error! This is a fake bug :)
... frames from this test file ...
at Array.map (<CWD>/packages/babel-core/test/errors-stacks.js?:_:_)
at loadOneConfig (<CWD>/packages/babel-core/lib/config/files/configuration.js:_:_)
at loadOneConfig.next (<anonymous>)
at buildRootChain (<CWD>/packages/babel-core/lib/config/config-chain.js:_:_)
Expand Down

0 comments on commit 2fb805c

Please sign in to comment.