Skip to content

Commit

Permalink
Move path normalization from preset-env to the test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 7, 2021
1 parent 241508d commit ac7553f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 16 additions & 3 deletions packages/babel-helper-transform-fixture-test-runner/src/index.js
Expand Up @@ -280,8 +280,16 @@ function run(task) {
}

if (validateLogs) {
validateFile(normalizeOutput(actualLogs.stdout), stdout.loc, stdout.code);
validateFile(normalizeOutput(actualLogs.stderr), stderr.loc, stderr.code);
validateFile(
normalizeOutput(actualLogs.stdout, /* normalizePathSeparator */ true),
stdout.loc,
stdout.code,
);
validateFile(
normalizeOutput(actualLogs.stderr, /* normalizePathSeparator */ true),
stderr.loc,
stderr.code,
);
}
}

Expand Down Expand Up @@ -319,7 +327,7 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
}
}

function normalizeOutput(code) {
function normalizeOutput(code, normalizePathSeparator) {
const projectRoot = path.resolve(__dirname, "../../../");
const cwdSymbol = "<CWD>";
let result = code
Expand All @@ -339,6 +347,11 @@ function normalizeOutput(code) {
new RegExp(escapeRegExp(projectRoot.replace(/\\/g, "\\\\")), "g"),
cwdSymbol,
);
if (normalizePathSeparator) {
result = result.replace(/<CWD>[\w\\/.-]+/g, path =>
path.replace(/\\\\?/g, "/"),
);
}
}
return result;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/babel-preset-env/src/debug.js
Expand Up @@ -34,10 +34,6 @@ export const logEntryPolyfills = (
polyfillTargets: Targets,
allBuiltInsList: { [key: string]: Targets },
) => {
// normalize filename to generate consistent preset-env test fixtures
if (process.env.BABEL_ENV === "test") {
filename = filename.replace(/\\/g, "/");
}
if (!importPolyfillIncluded) {
console.log(`\n[${filename}] Import of ${polyfillName} was not found.`);
return;
Expand Down

0 comments on commit ac7553f

Please sign in to comment.