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:
parent
9d0161356b
commit
fd39443f8f
2 changed files with 39 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// 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";
|
import { join } from "std/path/mod.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,3 +53,14 @@ export function getPathsFromTestSuites(suites: TestSuites): string[] {
|
||||||
}
|
}
|
||||||
return testPaths;
|
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] };
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
import { magenta } from "std/fmt/colors.ts";
|
import { magenta } from "std/fmt/colors.ts";
|
||||||
import { dirname, fromFileUrl, join } from "std/path/mod.ts";
|
import { dirname, fromFileUrl, join } from "std/path/mod.ts";
|
||||||
import { fail } from "std/testing/asserts.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
|
// If the test case is invoked like
|
||||||
// deno test -A cli/tests/node_compat/test.ts -- <test-names>
|
// 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 toolsPath = dirname(fromFileUrl(import.meta.url));
|
||||||
const stdRootUrl = new URL("../../", import.meta.url).href;
|
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 cwd = new URL(".", import.meta.url);
|
||||||
const importMap = "import_map.json";
|
const importMap = "import_map.json";
|
||||||
const windowsIgnorePaths = new Set(
|
const windowsIgnorePaths = new Set(
|
||||||
|
@ -30,23 +36,27 @@ const darwinIgnorePaths = new Set(
|
||||||
);
|
);
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
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
|
// If filter patterns are given and any pattern doesn't match
|
||||||
// to the file path, then skip the case
|
// to the file path, then skip the case
|
||||||
if (
|
if (
|
||||||
filters.length > 0 &&
|
filters.length > 0 &&
|
||||||
filters.every((pattern) => !path.includes(pattern))
|
filters.every((pattern) => !path.includes(pattern))
|
||||||
) {
|
) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
const isTodo = path.includes("TODO");
|
const isTodo = path.includes("TODO");
|
||||||
const ignore =
|
const ignore =
|
||||||
(Deno.build.os === "windows" && windowsIgnorePaths.has(path)) ||
|
(Deno.build.os === "windows" && windowsIgnorePaths.has(path)) ||
|
||||||
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo;
|
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo;
|
||||||
Deno.test({
|
await t.step({
|
||||||
name: `Node.js compatibility "${path}"`,
|
name: `Node.js compatibility "${path}"`,
|
||||||
ignore,
|
ignore,
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeExit: false,
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
const testCase = join(toolsPath, "test", path);
|
const testCase = join(toolsPath, "test", path);
|
||||||
|
|
||||||
|
@ -74,6 +84,7 @@ for await (const path of testPaths) {
|
||||||
args,
|
args,
|
||||||
env: {
|
env: {
|
||||||
DENO_NODE_COMPAT_URL: stdRootUrl,
|
DENO_NODE_COMPAT_URL: stdRootUrl,
|
||||||
|
TEST_SERIAL_ID: String(testSerialId++),
|
||||||
},
|
},
|
||||||
cwd,
|
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[]>) {
|
function checkConfigTestFilesOrder(testFileLists: Array<string[]>) {
|
||||||
for (let testFileList of testFileLists) {
|
for (let testFileList of testFileLists) {
|
||||||
testFileList = testFileList.filter((name) => !name.startsWith("TODO:"));
|
testFileList = testFileList.filter((name) => !name.startsWith("TODO:"));
|
||||||
|
|
Loading…
Reference in a new issue