1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00

test: parallelize applicable node compat tests (#18161)

This commit is contained in:
Nayeem Rahman 2023-03-14 07:56:06 +00:00 committed by Yoshiya Hinosawa
parent 9d0161356b
commit fd39443f8f
2 changed files with 39 additions and 5 deletions

View file

@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { partition } from "std/collections/mod.ts";
import { join } from "std/path/mod.ts";
/**
@ -52,3 +53,14 @@ export function getPathsFromTestSuites(suites: TestSuites): string[] {
}
return testPaths;
}
const PARALLEL_PATTERN = Deno.build.os == "windows"
? /^parallel[/\/]/
: /^parallel\//;
export function partitionParallelTestPaths(
testPaths: string[],
): { parallel: string[]; sequential: string[] } {
const partitions = partition(testPaths, (p) => !!p.match(PARALLEL_PATTERN));
return { parallel: partitions[0], sequential: partitions[1] };
}

View file

@ -2,7 +2,11 @@
import { magenta } from "std/fmt/colors.ts";
import { dirname, fromFileUrl, join } from "std/path/mod.ts";
import { fail } from "std/testing/asserts.ts";
import { config, getPathsFromTestSuites } from "./common.ts";
import {
config,
getPathsFromTestSuites,
partitionParallelTestPaths,
} from "./common.ts";
// If the test case is invoked like
// deno test -A cli/tests/node_compat/test.ts -- <test-names>
@ -19,7 +23,9 @@ const hasFilters = filters.length > 0;
const toolsPath = dirname(fromFileUrl(import.meta.url));
const stdRootUrl = new URL("../../", import.meta.url).href;
const testPaths = getPathsFromTestSuites(config.tests);
const testPaths = partitionParallelTestPaths(
getPathsFromTestSuites(config.tests),
);
const cwd = new URL(".", import.meta.url);
const importMap = "import_map.json";
const windowsIgnorePaths = new Set(
@ -30,23 +36,27 @@ const darwinIgnorePaths = new Set(
);
const decoder = new TextDecoder();
let testSerialId = 0;
for await (const path of testPaths) {
async function runTest(t: Deno.TestContext, path: string): Promise<void> {
// If filter patterns are given and any pattern doesn't match
// to the file path, then skip the case
if (
filters.length > 0 &&
filters.every((pattern) => !path.includes(pattern))
) {
continue;
return;
}
const isTodo = path.includes("TODO");
const ignore =
(Deno.build.os === "windows" && windowsIgnorePaths.has(path)) ||
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo;
Deno.test({
await t.step({
name: `Node.js compatibility "${path}"`,
ignore,
sanitizeOps: false,
sanitizeResources: false,
sanitizeExit: false,
fn: async () => {
const testCase = join(toolsPath, "test", path);
@ -74,6 +84,7 @@ for await (const path of testPaths) {
args,
env: {
DENO_NODE_COMPAT_URL: stdRootUrl,
TEST_SERIAL_ID: String(testSerialId++),
},
cwd,
});
@ -101,6 +112,17 @@ for await (const path of testPaths) {
});
}
Deno.test("Node.js compatibility", async (t) => {
for (const path of testPaths.sequential) {
await runTest(t, path);
}
const pending = [];
for (const path of testPaths.parallel) {
pending.push(runTest(t, path));
}
await Promise.all(pending);
});
function checkConfigTestFilesOrder(testFileLists: Array<string[]>) {
for (let testFileList of testFileLists) {
testFileList = testFileList.filter((name) => !name.startsWith("TODO:"));