mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
tests: cleanup "node_compat_tests" (#18594)
A few drive-by cleanup while I'm working on the "crypto" module. It makes it easier and faster to debug the failing test case.
This commit is contained in:
parent
e222c368c0
commit
aec781cf8f
4 changed files with 36 additions and 55 deletions
|
@ -8,12 +8,6 @@ fn node_compat_tests() {
|
|||
.current_dir(util::root_path())
|
||||
.arg("test")
|
||||
.arg("--unstable")
|
||||
.arg("--import-map")
|
||||
.arg(
|
||||
util::tests_path()
|
||||
.join("node_compat")
|
||||
.join("import_map.json"),
|
||||
)
|
||||
.arg("-A")
|
||||
.arg(util::tests_path().join("node_compat"))
|
||||
.spawn()
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"imports": {
|
||||
"std/": "../../../test_util/std/"
|
||||
}
|
||||
}
|
|
@ -1,8 +1,22 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
import { magenta } from "std/fmt/colors.ts";
|
||||
import { pooledMap } from "std/async/pool.ts";
|
||||
import { dirname, fromFileUrl, join } from "std/path/mod.ts";
|
||||
import { fail } from "std/testing/asserts.ts";
|
||||
|
||||
/**
|
||||
* This script will run the test files specified in the configuration file.
|
||||
*
|
||||
* Each test file will be run independently (in a separate process as this is
|
||||
* what Node.js is doing) and we wait until it completes. If the process reports
|
||||
* an abnormal code, the test is reported and the test suite will fail
|
||||
* immediately.
|
||||
*
|
||||
* Some tests check for presence of certain `process.exitCode`.
|
||||
* Some tests depends on directories/files created by other tests - they must
|
||||
* all share the same working directory.
|
||||
*/
|
||||
|
||||
import { magenta } from "../../../test_util/std/fmt/colors.ts";
|
||||
import { pooledMap } from "../../../test_util/std/async/pool.ts";
|
||||
import { dirname, fromFileUrl, join } from "../../../test_util/std/path/mod.ts";
|
||||
import { fail } from "../../../test_util/std/testing/asserts.ts";
|
||||
import {
|
||||
config,
|
||||
getPathsFromTestSuites,
|
||||
|
@ -11,24 +25,14 @@ import {
|
|||
|
||||
// If the test case is invoked like
|
||||
// deno test -A cli/tests/node_compat/test.ts -- <test-names>
|
||||
// Use the test-names as filters
|
||||
// Use the <test-names> as filters
|
||||
const filters = Deno.args;
|
||||
const hasFilters = filters.length > 0;
|
||||
|
||||
/**
|
||||
* This script will run the test files specified in the configuration file
|
||||
*
|
||||
* Each test file will be run independently and wait until completion, if an abnormal
|
||||
* code for the test is reported, the test suite will fail immediately
|
||||
*/
|
||||
|
||||
const toolsPath = dirname(fromFileUrl(import.meta.url));
|
||||
const stdRootUrl = new URL("../../", import.meta.url).href;
|
||||
const testPaths = partitionParallelTestPaths(
|
||||
getPathsFromTestSuites(config.tests),
|
||||
);
|
||||
const cwd = new URL(".", import.meta.url);
|
||||
const importMap = "import_map.json";
|
||||
const windowsIgnorePaths = new Set(
|
||||
getPathsFromTestSuites(config.windowsIgnore),
|
||||
);
|
||||
|
@ -74,7 +78,7 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
|
|||
"--unstable",
|
||||
//"--unsafely-ignore-certificate-errors",
|
||||
"--v8-flags=" + v8Flags.join(),
|
||||
testCase.endsWith(".mjs") ? "--import-map=" + importMap : "runner.ts",
|
||||
"runner.ts",
|
||||
testCase,
|
||||
];
|
||||
|
||||
|
@ -83,7 +87,6 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
|
|||
const command = new Deno.Command(Deno.execPath(), {
|
||||
args,
|
||||
env: {
|
||||
DENO_NODE_COMPAT_URL: stdRootUrl,
|
||||
TEST_SERIAL_ID: String(testSerialId++),
|
||||
},
|
||||
cwd,
|
||||
|
@ -93,15 +96,23 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
|
|||
if (code !== 0) {
|
||||
// If the test case failed, show the stdout, stderr, and instruction
|
||||
// for repeating the single test case.
|
||||
if (stdout.length) console.log(decoder.decode(stdout));
|
||||
console.log(`Error: "${path}" failed`);
|
||||
console.log(
|
||||
"You can repeat only this test with the command:",
|
||||
magenta(
|
||||
`./target/debug/deno test -A --import-map cli/tests/node_compat/import_map.json cli/tests/node_compat/test.ts -- ${path}`,
|
||||
),
|
||||
if (stdout.length) {
|
||||
console.log(decoder.decode(stdout));
|
||||
}
|
||||
const stderrOutput = decoder.decode(stderr);
|
||||
const repeatCmd = magenta(
|
||||
`./target/debug/deno test -A cli/tests/node_compat/test.ts -- ${path}`,
|
||||
);
|
||||
fail(decoder.decode(stderr));
|
||||
const msg = `"${magenta(path)}" failed:
|
||||
|
||||
${stderrOutput}
|
||||
|
||||
You can repeat only this test with the command:
|
||||
|
||||
${repeatCmd}
|
||||
`;
|
||||
console.log(msg);
|
||||
fail(msg);
|
||||
} else if (hasFilters) {
|
||||
// Even if the test case is successful, shows the stdout and stderr
|
||||
// when test case filtering is specified.
|
||||
|
|
|
@ -169,25 +169,6 @@ to pass certain tests. However, avoid doing such manual changes to the test
|
|||
files, since that may cover up inconsistencies between the node library and
|
||||
actual node behavior.
|
||||
|
||||
### Working with child processes ? Use `DENO_NODE_COMPAT_URL`
|
||||
|
||||
When working with `child_process` modules, you will have to run tests pulled
|
||||
from Node.js. These tests usually spawn deno child processes via the use of
|
||||
`process.execPath`. The `deno` executable will use its own embedded version of
|
||||
std modules, then you may get the impression your code is not really working as
|
||||
it should.
|
||||
|
||||
To prevent this, set `DENO_NODE_COMPAT_URL` with the absolute path to your
|
||||
`deno_std` repo, ending with a trailing slash:
|
||||
|
||||
```
|
||||
export DENO_NODE_COMPAT_URL=$PWD/
|
||||
# or
|
||||
export DENO_NODE_COMPAT_URL=file:///path/to/deno_std/dir/
|
||||
```
|
||||
|
||||
Then, `deno` will use your local copy of `deno_std` instead of latest version.
|
||||
|
||||
### Best practices
|
||||
|
||||
When converting from promise-based to callback-based APIs, the most obvious way
|
||||
|
|
Loading…
Reference in a new issue