Files
Huáng JùnliàngandGitHub 16f37b5473 Add file URL support for test runners (#18002)
* test: accept URL in fixture test runner

* test: use URL for fixture calls

* test: extract systemjs-exec test into single file
2026-05-15 21:24:49 -04:00

49 lines
1.4 KiB
JavaScript

import {
buildProcessTests,
buildParallelProcessTests,
} from "@babel/helper-transform-fixture-test-runner";
import path from "node:path";
import { commonJS } from "$repo-utils";
const { __dirname } = commonJS(import.meta.url);
const rootDir = path.resolve(__dirname, "../../../..");
function escapeRegExp(string) {
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}
const normalizeOutput = function (str, cwd) {
let result = str
.replace(/\(\d+ms\)/g, "(123ms)")
.replace(new RegExp(escapeRegExp(cwd), "g"), "<CWD>")
// (non-win32) /foo/babel/packages -> <CWD>/packages
// (win32) C:\foo\babel\packages -> <CWD>\packages
.replace(new RegExp(escapeRegExp(rootDir), "g"), "<ROOTDIR>");
if (process.platform === "win32") {
result = result
// C:\\foo\\babel\\packages -> <CWD>\\packages (in js string literal)
.replace(
new RegExp(escapeRegExp(rootDir.replace(/\\/g, "\\\\")), "g"),
"<ROOTDIR>",
);
}
return result;
};
export const runParallel = buildParallelProcessTests(
"babel-build-external-helpers",
buildProcessTests(
new URL("../fixtures", import.meta.url),
function (test) {
test.binLoc = path.join(__dirname, "../../lib", test.suiteName);
},
function (test, tmpDir, stdout, stderr) {
return {
stdout: normalizeOutput(stdout, tmpDir),
stderr: normalizeOutput(stderr, tmpDir),
};
},
),
);