deno/tools/node_compat
Nathan Whitaker a77b2987bc
fix(ext/node): Match punycode module behavior to node (#22847)
Fixes #19214.

We were using the `idna` crate to implement our polyfill for
`punycode.toASCII` and `punycode.toUnicode`. The `idna` crate is
correct, and adheres to the IDNA2003/2008 spec, but it turns out
`node`'s implementations don't really follow any spec! Instead, node
splits the domain by `'.'` and punycode encodes/decodes each part. This
means that node's implementations will happily work on codepoints that
are disallowed by the IDNA specs, causing the error in #19214.

While fixing this, I went ahead and matched the node behavior on all of
the punycode functions and enabled node's punycode test in our
`node_compat` suite.
2024-03-11 15:49:43 -07:00
..
node@b114fad0ec chore: update node_compat test suites to v18.18.2 (#21328) 2023-11-25 11:35:36 +09:00
.gitignore chore(tools): restore node compat test setup script (#18290) 2023-03-21 22:38:07 +09:00
deno.json chore(tests): Remove vestiges of cli/tests folder (#22712) 2024-03-05 13:49:21 -07:00
README.md chore(tests): Remove vestiges of cli/tests folder (#22712) 2024-03-05 13:49:21 -07:00
setup.ts chore: use @std import instead of @test_util/std (#22398) 2024-02-13 02:05:10 +00:00
TODO.md fix(ext/node): Match punycode module behavior to node (#22847) 2024-03-11 15:49:43 -07:00

Tools for Node.js compatibility work

We run native Node.js test cases against our Node.js compatibility feature.

This directory includes the tools for downloading, setting up, and updating the Node.js compat testing in Deno repository.

  • //tools/node_compat/setup.ts
    • This script sets up the Node.js compat tests.
  • //tools/node_compat/versions/
    • Node.js source tarballs and extracted test cases are stored here.
  • //tests/node_compat/config.jsonc
    • This json file stores the settings about which Node.js compat test to run with Deno.
  • //tests/node_compat/test
    • The actual test cases are stored here.

Steps to add new test cases from Node.js test cases

  1. Update tests property of //tests/node_compat/config.jsonc. For 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
  2. 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.

Ideally Deno should pass the Node.js compat tests without modification, but if you need to modify it, then add that item in ignore property of config.jsonc. Then setup.ts doesn't overwrite the modified Node.js test cases anymore.

If the test needs to be ignored in particular platform, then add them in ${platform}Ignore property of config.jsonc

Run Node.js test cases

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. If you want to run specific tests you can use the command deno task test (in tools/node_compat dir). For example, if you want to run all test files which contains buffer in filename you can use the command:

/path/to/deno/tools/node_compat
$ deno task test buffer