tap command not found
Is there an existing issue for this?
- [X] I have searched the existing issues
Have you read the CONTRIBUTING guide on posting bugs, and CODE_OF_CONDUCT?
- [X] yes I read the things
This issue exists in the latest tap version
- [X] I am using the latest tap
Description
this issue was reported in 2021 https://github.com/tapjs/tapjs/issues/774
however, I still face this problem today. I followed the directions exactly as published on the website:
- Installed TAP
npm install tap --save-dev
- wrote a test file
- ran tap from the commandline
→ tap lib/zql/queryMaker/where/index.test.js
tap
zsh: command not found: tap
The solution, as suggested in the linked issue #774 is to install TAP globally with npm install -g tap. If that is true, why is that not on the website? In any case, I'd prefer not to install TAP globally.
Much appreciation in advance for any guidance.
Reproduction
see above
Environment
which tap -→ cannot run this
npm ls tap -→ see below
tap versions -→ cannot run this
tap config list -→ cannot run this
tap plugin list -→ cannot run this
# if using typescript:
npm ls @isaacs/ts-node-temp-fork-for-pr-2009
npm ls typescript
# posix:
uname -a
# windows (in powershell)
"$([Environment]::OSVersion.VersionString) $(('x86', 'x64')[[Environment]::Is64BitOperatingSystem])"
→ npm ls tap
[email protected] /Users/punkish/Projects/zenodeo3
└── [email protected]
→ node --version
v20.12.2
I want to add that I am using node with nvm. I don't know if that matters. Since I installed tap as a local dev-dependency, it is in my project's node_modules directory.
→ which node
/Users/punkish/.nvm/versions/node/v20.12.2/bin/node
I am able to run the test using node directly as well as via npx tap successfully, but when I do the following
# the following works
→ node lib/zql/queryMaker/where/index.test.js
# the following works
→ npx tap lib/zql/queryMaker/where/index.test.js
# the following does not work
→ tap lib/zql/queryMaker/where/index.test.js
Also, running the test with npx tap causes all the tests in the entire project directory structure to be run. I want to run only the test specified on the command line (just to reduce the noise in the terminal)
seems like npx tap path/to/test.js is the best option available to me so I don't have to install tap globally
I got tired of typing npx so I gave up and installed tap globally. But, faced a similar problem as above -- when running tap path/to/index.test.js, it works fine. But nothing happens when running tap "**/*.test.js". Actually, something does happen but it just takes a long time. And, again contrary to what the documentation says, tapwants to run the tests in all thenode_modules`
$ tap "**/*.test.js"
FAIL bin/truebug/index.test.js 0 200ms
✖ SIGINT
FAIL data-dictionary/dd-utils.test.js 0 195ms
✖ SIGINT
…
FAIL node_modules/@fastify/ajv-compiler/test/duplicated-id-compile.test.js 0 36ms
✖ SIGINT
FAIL node_modules/@fastify/ajv-compiler/test/plugins.test.js 0 34ms
✖ SIGINT
FAIL node_modules/@fastify/ajv-compiler/test/standalone.test.js 0 36ms
✖ SIGINT
FAIL node_modules/@fastify/ajv-compiler/test/serialization.test.js 0 23ms
✖ SIGINT
FAIL node_modules/@fastify/cors/test/cors.test.js 0 38ms
✖ SIGINT
FAIL node_modules/@fastify/cors/test/hooks.test.js 0 36ms
✖ SIGINT
FAIL node_modules/@fastify/ajv-compiler/test/index.test.js 0 35ms
✖ SIGINT
FAIL node_modules/@fastify/cors/test/preflight.test.js 0 35ms
…
When I try to edit the config file using tap config edit, I get a YAML error even though strangely I didn't even touch that line 14. I only wanted to change the exclude pattern.
YAMLParseError: A block sequence may not be used as an implicit map key at line 14, column 1:
coverage-map: map.mjs
In any case, tap should not be running tests in the node_modules directory as stated
--exclude=[#](https://node-tap.org/cli/#--exclude%3D%3Cpattern%3E) A glob pattern indicating which filenames should NEVER be run as tests. This overrides the include option.
Defaults to excluding any folders named dist, fixture, or fixtures.
Note: folders named tap-snapshots, node_modules, or .git are ALWAYS excluded from the default test file set. If you wish to run tests in these folders, then name the test files on the command line as positional arguments.
What am I doing wrong that my experience doesn't match what the docs say?
Put { "scripts": { "test": "tap" }} in your package.json and then you can run npm test and it'll Just Work. You can also provide additional arguments like npm test test/some/specific/file.ts, because npm will pass those along, but be advised that any arg starting with a - will need to be separated with --, like npm test -- --bail so that npm doesn't try to consume the option. (This also works with pnpm test, yarn test, etc.)
If the "scripts" name is "snap" or "snapshot", then running npm run snap will run your tests in snapshot-creation mode.