tape: Unable to Use NPM Variable with -r Flag and ESM
This command works:
"test": "npx tape '__test__/*.test.js' | tap-spec -r __test__/index.js"
But when I try to insert a variable for npm, I have to remove the single quotes around path to get it to be recognized, and then the indexjs file never runs.
"test:specific": "npx tape __test__/$npm_config_testname.test.js | tap-spec -r __test__/index.js"
If I place the call to the index file on the other side of the pipe it looks for the file under CJS in modules, but since the tests are using ESM, I get a not found module error.
Node: 20.2.0 npm: 9.6.6
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 28
Works perfectly, and now I have my command for running a single test!
I’ll leave this open to add an
--importoption, and onceresolvesupports ESM, tape automatically will support it on--require.I suspected when I saw the stacktrace on the
require, always seemed to be looking down a CJS path. Ok, so what I’ve done is the only supported option for ESM. The whole project the tests are embedded in leans pretty hard towards ESM, so was just easier to use tape that way.So when I remove all flags for the
index.jsfile, and place it first in the command it seems to consistently work for all and individual tests. Why, I have no idea:"test:specific": "npx tape integration-tests/index.js integration-tests/$npm_config_testname.test.js | tap-spec"It contains two functions(login, sdk initialization) needed before running almost any test. It also exports a function to generate a password. For login and initialize I was creating and calling the functions inside
index.js.Functions are async.
symstory.datais the only one I’ve tried. If I import the dependencies directly into the file, it actually runs the import twice before running the test file.Update: Just debugged, and it’s hitting the
--importfrom the npm command first, not the import statement in the test file.npx tape --import=__test__/index.js '__test__/*.test.js'should certainly work assuming the file exists and is ESM (-rfor ESM will only work with require(esm), which requires node 20.19)