Skip to content

Commit

Permalink
test: divide cli,node tests into 8 slices (#16196)
Browse files Browse the repository at this point in the history
Co-Authored-By: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
  • Loading branch information
2 people authored and nicolo-ribaudo committed Jan 18, 2024
1 parent 1d33afd commit dde84f0
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 61 deletions.
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-cli/test/batch-test-runner/7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { buildProcessTests } from "@babel/helper-transform-fixture-test-runner";
import {
buildProcessTests,
buildParallelProcessTests,
} from "@babel/helper-transform-fixture-test-runner";
import path from "path";
import { commonJS } from "$repo-utils";

const { __dirname } = commonJS(import.meta.url);

const fixtureLoc = path.join(__dirname, "fixtures");
const rootDir = path.resolve(__dirname, "../../..");
const fixtureLoc = path.join(__dirname, "../fixtures");
const rootDir = path.resolve(__dirname, "../../../..");

const getPath = name => path.join(rootDir, "packages", name, "lib/index.js");

Expand Down Expand Up @@ -41,27 +44,24 @@ const normalizeOutput = function (str, cwd) {
return result;
};

const tests = buildProcessTests(
fixtureLoc,
function (test) {
test.binLoc = path.join(__dirname, "../lib", test.suiteName);
if (
test.suiteName !== "babel-external-helpers" &&
!test.opts.noDefaultPlugins
) {
test.opts.args.push("--presets", presetLocs, "--plugins", pluginLocs);
}
},
function (_, tmpDir, stdout, stderr) {
return {
stdout: normalizeOutput(stdout, tmpDir),
stderr: normalizeOutput(stderr, tmpDir),
};
},
export const runParallel = buildParallelProcessTests(
"babel-cli",
buildProcessTests(
fixtureLoc,
function (test) {
test.binLoc = path.join(__dirname, "../../lib", test.suiteName);
if (
test.suiteName !== "babel-external-helpers" &&
!test.opts.noDefaultPlugins
) {
test.opts.args.push("--presets", presetLocs, "--plugins", pluginLocs);
}
},
function (test, tmpDir, stdout, stderr) {
return {
stdout: normalizeOutput(stdout, tmpDir),
stderr: normalizeOutput(stderr, tmpDir),
};
},
),
);

describe("bin/babel", function () {
for (const test of tests) {
(test.skip ? it.skip : it)(test.suiteName + " " + test.testName, test.fn);
}
});
19 changes: 19 additions & 0 deletions packages/babel-helper-transform-fixture-test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,25 @@ const assertTest = function (
}
};

export function buildParallelProcessTests(name: string, tests: ProcessTest[]) {
return function (curr: number, total: number) {
const sliceLength = Math.ceil(tests.length / total);
const sliceStart = curr * sliceLength;
const sliceEnd = sliceStart + sliceLength;
const testsSlice = tests.slice(sliceStart, sliceEnd);

describe(`${name} [${curr}/${total}]`, function () {
it("dummy", () => {});
for (const test of testsSlice) {
(test.skip ? it.skip : it)(
test.suiteName + " " + test.testName,
test.fn as any,
);
}
});
};
}

export function buildProcessTests(
dir: string,
beforeHook: ProcessTestBeforeHook,
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
3 changes: 3 additions & 0 deletions packages/babel-node/test/batch-test-runner/7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runParallel } from "../helpers/runner.js";

runParallel(parseInt(import.meta.url.split("/").pop().split(".")[0]), 8);
38 changes: 38 additions & 0 deletions packages/babel-node/test/helpers/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from "path";
import { writeFileSync } from "fs";
import { commonJS } from "$repo-utils";
import {
buildProcessTests,
buildParallelProcessTests,
} from "@babel/helper-transform-fixture-test-runner";

const { require, __dirname } = commonJS(import.meta.url);

const fixtureLoc = path.join(__dirname, "../fixtures");
const binLoc = path.join(__dirname, "../../lib/babel-node");

export const runParallel = buildParallelProcessTests(
"babel-node",
buildProcessTests(fixtureLoc, function (test, tmpDir) {
test.binLoc = binLoc;
test.opts.env = { ...test.opts.env, BABEL_DISABLE_CACHE: true };
if (test.testName === "require") {
writeFileSync(
path.join(tmpDir, ".babelrc"),
JSON.stringify({
presets: [
require.resolve("@babel/preset-env"),
[require.resolve("@babel/preset-react"), { runtime: "classic" }],
],
}),
);
}
if (!test.opts.inFiles["package.json"]) {
test.opts.inFiles["package.json"] = `{ "type": "commonjs" }`;
writeFileSync(
path.join(tmpDir, "package.json"),
`{ "type": "commonjs" }`,
);
}
}),
);
35 changes: 0 additions & 35 deletions packages/babel-node/test/index.js

This file was deleted.

0 comments on commit dde84f0

Please sign in to comment.