mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
chore(node_compat): add deno task for setting up and running tests (#19293)
This commit is contained in:
parent
6836e5a6eb
commit
ba7cffc896
3 changed files with 20 additions and 72 deletions
|
@ -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 -- <pattern-to-match>
|
||||
```
|
||||
|
||||
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).
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
6
tools/node_compat/deno.json
Normal file
6
tools/node_compat/deno.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"tasks": {
|
||||
"setup": "deno run --allow-read --allow-write ./setup.ts",
|
||||
"test": "deno test -A ../../cli/tests/node_compat/test.ts --"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue