[Pkg-javascript-devel] Using ava

Yadd yadd at debian.org
Mon May 9 17:31:27 BST 2022


Hi all,

ftpmasters accepted ava and I just added this README.Debian (not yet 
published). It explains a known issue I'd like to share here.

Fixes/improvements are welcome:
  git at salsa.debian.org:js-team/node-ava.git


# Notes on ava 4

ava 4 is usable only with ES modules. If you want to run test of a 
commonjs module, you can use tape (preferred) or jest.

## Using tape

To use tape instead of ava, you have to patch test. Some tips:
  * replace `import test from 'ava'` by `import test from 'tape'`
    (or by `const test = require('tape')` if your module isn't ES)
  * add a `t.end()` at the end of each test
  * translate each test files into commonjs if module isn't `type:module`
  * replace all:
    * `t.truthy` by `t.ok`
    * `t.falsy` by `t.nok`
    * `t.notThrows` by `t.doesNotThrow`
    * `t.regex(string, /regex/)` by `t.ok(string.match(/regex/))`
  * drop tests that uses `t.notThrowsAsync` or `t.throwsAsync`

If your module is a ES module, you may have to link tape for test:

```shell
$ cat >> debian/nodejs/extlinks << EOF
tape    test
EOF
```

## Using jest

You can transform ava test files into jest ones using `npx jest-codemods`.
Then you have to answer to some questions:
  * **Which parser do you want to use?**                   : choose babel
  * **Which test library would you like to migrate from?** : choose ava
  * **Are you using the global object for assertions**     : choose no
  * **Will you be using Jest on Node.js as your test runner?**: choose yes

Then you may have to add a `babel.config.json` file if you encounter 
errors like `Jest encountered an unexpected token`:

```shell
$ cat > babel.config.json << EOF
{"presets":["@babel/preset-env"],"plugins":["@babel/plugin-transform-runtime"]}
EOF
```

Then you'll probably have things to fix...



More information about the Pkg-javascript-devel mailing list