[Pkg-javascript-devel] Workarounds for node-ava
Xavier
yadd at debian.org
Tue Dec 1 17:11:29 GMT 2020
Hi,
packaging node-ava needs a (too big) lot of components/packages (I
stopped counting at 48).
Workarounds:
* for simple test files, replace it by node-tape:
## ORIGINAL TEST ### TAPE TEST ##
#
import test from 'ava' # const test = require('tape')
import foo from '.' # const foo = require('.')
#
test('bar', t => { # test('bar', t=> {
t.is( foo(0), 0) # t.is( foo(0), 0)
} # t.end()
# }
Just to transform in commonjs and add "t.end()" at each test; and
adapt some functions name. For example, t.notThrows becomes
t.doesNotThrow.
See /usr/share/doc/node-tape/readme.markdown.gz to find
them.
* more complex test files, use jest (via jest-codemods)
$ npx jest-codemods
? Which parser do you want to use? Babel
? Which test library would you like to migrate from? AVA
? Are you using the global object for assertions? No
? Will you be using Jest on Node.js as your test runner? Yes
? On which files or directory should the codemods be applied?
test.js
Executing command: jscodeshift -t [...] test.js \
--ignore-pattern node_modules --parser babel
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
All done.
Results:
0 errors
0 unmodified
0 skipped
1 ok
# Test it
$ jest --ci --testRegex test.js
It may need a babel file. If so, add a babel.config.json:
{
"presets": [ "@babel/preset-env" ],
"plugins": [ "@babel/plugin-transform-runtime" ]
}
Anyway, jest has not exactly the same features than ava. Especially some
throwsAsync / notThrowsAsync test should be removed or modified.
I'll add this to https://wiki.debian.org/Javascript/Tutorial when
wiki.debian.org will be available (403 for now...)
Cheers,
Xavier
More information about the Pkg-javascript-devel
mailing list