From ba7cffc896f4c7cb717773cbceda54fc15dd1adb Mon Sep 17 00:00:00 2001 From: Hirotaka Tagawa / wafuwafu13 Date: Thu, 1 Jun 2023 09:31:06 +0100 Subject: [PATCH] chore(node_compat): add deno task for setting up and running tests (#19293) --- ext/node/polyfills/README.md | 72 ++---------------------------------- tools/node_compat/README.md | 14 +++++-- tools/node_compat/deno.json | 6 +++ 3 files changed, 20 insertions(+), 72 deletions(-) create mode 100644 tools/node_compat/deno.json diff --git a/ext/node/polyfills/README.md b/ext/node/polyfills/README.md index 748c53daa6..671d78bc4f 100644 --- a/ext/node/polyfills/README.md +++ b/ext/node/polyfills/README.md @@ -99,75 +99,9 @@ const leftPad = require("left-pad"); ## Contributing -### Setting up the test runner +### Setting up the test runner and running tests -This library contains automated tests pulled directly from the Node.js repo in -order ensure compatibility. - -Setting up the test runner is as simple as running the `node/_tools/setup.ts` -file, this will pull the configured tests in and then add them to the test -workflow. - -```zsh -$ deno task node:setup -``` - -You can additionally pass the `-y`/`-n` flag to use test cache or generating -tests from scratch instead of being prompted at the moment of running it. - -```zsh -# Will use downloaded tests instead of prompting user -$ deno run --allow-read --allow-net --allow-write node/_tools/setup.ts -y -# Will not prompt but will download and extract the tests directly -$ deno run --allow-read --allow-net --allow-write node/_tools/setup.ts -n -``` - -To run the tests you have set up, do the following: - -```zsh -$ deno test --allow-read --allow-run node/_tools/test.ts -``` - -If you want to run specific Node.js test files, you can use the following -command - -```shellsession -$ deno test -A node/_tools/test.ts -- -``` - -For example, if you want to run only -`node/_tools/test/parallel/test-event-emitter-check-listener-leaks.js`, you can -use: - -```shellsession -$ deno test -A node/_tools/test.ts -- test-event-emitter-check-listener-leaks.js -``` - -If you want to run all test files which contains `event-emitter` in filename, -then you can use: - -```shellsession -$ deno test -A node/_tools/test.ts -- event-emitter -``` - -The test should be passing with the latest deno, so if the test fails, try the -following: - -- `$ deno upgrade` -- `$ git submodule update --init` -- Use - [`--unstable` flag](https://deno.land/manual@v1.15.3/runtime/stability#standard-modules) - -To enable new tests, simply add a new entry inside `node/_tools/config.json` -under the `tests` property. The structure this entries must have has to resemble -a path inside `https://github.com/nodejs/node/tree/main/test`. - -Adding a new entry under the `ignore` option will indicate the test runner that -it should not regenerate that file from scratch the next time the setup is run, -this is specially useful to keep track of files that have been manually edited -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. +See [tools/node_compat/README.md](../../../tools/node_compat/README.md). ### Best practices @@ -226,4 +160,4 @@ It's not as clean, but prevents the callback being called twice. Node compatibility can be measured by how many native Node tests pass. If you'd like to know what you can work on, check out the list of Node tests remaining -[here](_tools/node_compat/TODO.md). +[here](../../../tools/node_compat/TODO.md). diff --git a/tools/node_compat/README.md b/tools/node_compat/README.md index c422a1d0e3..29a7ef7399 100644 --- a/tools/node_compat/README.md +++ b/tools/node_compat/README.md @@ -20,10 +20,10 @@ Node.js compat testing in Deno repository. ## Steps to add new test cases from Node.js test cases 1. Update `tests` property of `//cli/tests/node_compat/config.jsonc`. For - example, if you want to add `test/paralles/test-foo.js` from Node.js test + example, if you want to add `test/parallel/test-foo.js` from Node.js test cases, then add `test-foo.js` entry in `tests.parallel` array property in `config.jsonc` -1. Run `./tools/node_compat/setup.ts` +1. Run `deno task setup` in `tools/node_compat` dir. The above command copies the updated items from Node.js tarball to the Deno source tree. @@ -40,4 +40,12 @@ If the test needs to be ignored in particular platform, then add them in Node.js compat tests are run as part of `cargo test` command. If you want to run only the Node.js compat test cases you can use the command -`cargo test node_compat`. +`cargo test node_compat`. If you want to run specific tests you can use the +command `deno task test` (in `tools/node_comapt` dir). For example, if you want +to run all test files which contains `buffer` in filename you can use the +command: + +```shellsession +/path/to/deno/tools/node_compat +$ deno task test buffer +``` diff --git a/tools/node_compat/deno.json b/tools/node_compat/deno.json new file mode 100644 index 0000000000..6e9c891a03 --- /dev/null +++ b/tools/node_compat/deno.json @@ -0,0 +1,6 @@ +{ + "tasks": { + "setup": "deno run --allow-read --allow-write ./setup.ts", + "test": "deno test -A ../../cli/tests/node_compat/test.ts --" + } +}