I've just installed mocha and am using fairly basic settings to run 2 tests, but it won't output all the results.
I am expecting to see:
foo
bar
√ does thing
baz
√ does other thing
but I am only seeing the first 2-4 lines (varies with no discernible pattern). It seems there's some sort of time-dependent element here, but I have no idea how to approach fixing it.
The environment is cygwin under Windows 8.
I am running mocha by running npm test.
My test command in package.json is mocha test/*.js -R spec.
Any luck finding an answer?
I'm on a different OS and your config looks good.
Works in my package.json:
"scripts": {
"test": "mocha -R spec"
}
Related
It seems that vite build command doesn't run tests (unit tests written with vitest, for example) before building the application for production. This is quite unsafe.
Is there a way to configure vite build to run tests before trying to build ?
I couldn't find anything in Build Options.
What do you have in your package.json, scripts section? Don't you have some test or alike?
build is used to bundle your app and ship it to production. It's not supposed to run any tests by default.
You could achieve this by doing something like
"scripts": {
"build": "vite build && npm run test:unit && npm run test:e2e",
"test:unit": "vitest --environment jsdom",
"test:e2e": "start-server-and-test preview http://localhost:4173/ 'cypress open --e2e'",
},
If you generate a new project via the CLI, you will have most of them already written for you, then it's a matter of properly chaining them with && to assure that they are all succeeding before proceeding further.
You can also add some Git hooks with something like husky + lintstaged so that your flow is using something by default before even pushing it to a remote repo.
Otherwise, it's part of your CI. Either it be a Docker compose file, some Github actions, Gitlab pipelines or anything your devops team could have setup for your deploy environments.
I have run the command
yarn add -D jest to install jest to my project.
This does successfully add jest to my node_modules
> find . -name jest
./node_modules/.bin/jest
./node_modules/jest
When I use iterm2 to run jest however I get the following output
> jest
zsh: command not found: jest
FWIW When I use the IntelliJ terminal it does work
> jest
Determining test suites to run...^C
What am I missing in the iterm environment to be able to have node_modules bin in my classpath depending on the current repo?
An OS shell doesn't know about your locally installed node_modules, but IntelliJ terminal does. So if you want to run jest from outside of an IDE you should perform several additional steps.
The most common way to run locally installed packages is to define a separate script in the "scripts" section of your package.json file. Then you will be able to run it using the yarn/npm itself from any terminal. You can find an exact example in the Yarn docs.
{
"name": "my-package",
"scripts": {
"test": "jest"
}
}
yarn run test
Or you could install jest globally so it will be accessible from anywhere, but it's not a best practice.
I have a Vue app built that requires me to build the assets from my machine each time updates are made. Another developer asked me let them know the dependencies so that they set up a build engine on Circle CI. Does that mean the dependencies and devDependencies listed in package.json? Some of those I don't remember manually installing.
It's hard to know what your colleague is asking for without talking to them directly, but for cloud-based continuous integration systems, you usually need to know what the system prerequisites are in order to build. The stuff that's in package.json is the easy bit, as long as you have a "build" command in your package.json "scripts" section.
As an example, I have a package.json that looks roughly like this:
"build": "yarn build:umd & yarn build:es & yarn build:unpkg",
"build:umd": "rollup --config build/rollup.config.js --format umd --file dist/honeybadger-vue.umd.js",
"build:es": "rollup --config build/rollup.config.js --format es --file dist/honeybadger-vue.esm.js",
"build:unpkg": "rollup --config build/rollup.config.js --format iife --file dist/honeybadger-vue.js",
"build:unpkg-minify": "rollup MINIFY=true --config build/rollup.config.js --format iife --file dist/honeybadger-vue.min.js",
However, for the continuous integration setup, I need to tell the CI system what I need in order to run those commands. Those are likely the dependencies your colleague is asking about.
For example, I use Travis rather than Circle CI, but I need to specify which versions of Node I need to run tests on, which external dependencies I might need in order to build the library and to run tests. That could be libraries like ImageMagick, headless Chrome, maybe a database client for some use cases. I also need to know what commands need to be run to run the build (travis makes a reasonable assumption once you tell it that the language is node_js; I would expect Circle CI to be similar).
In my particular Travis setup, I have a config file in the project called .travis.yml that tells Travis everything it needs to know, like this:
dist: trusty
language: node_js
node_js:
- 8
- 10
- 11
sudo: false
addons:
chrome: stable
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
before_install:
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
This lists the versions of Node I want to test with, a list of pre-build commands, and some addons I need. I could just as easily add things with the OS package manager if I needed to.
Basically, I presume your developer counterpart is looking for enough information to make sure it's possible to build the library on someone else's machine. That's almost certainly what they mean by "dependencies", as your package file will contain sufficient information to reference any of the dependencies that Node can handle itself.
Running npm 3.10.3 and node 6.7.0 on Ubuntu, I was using the "npm-run" package to allow using executable node scripts locally in a cross-platform way. So, for example, for some simple ava tests I ran with the following in package.json.
"scripts": {
"test": "npm-run ava --serial "
}
However, I noticed that the following worked just fine as well, after verifying that ava was not installed globally:
"scripts": {
"test": "ava --serial "
}
I haven't tested on Windows yet, so the jury's still out, but does anyone know if this behavior is now supported directly in npm as it appears? If so, is npm-run still recommended for backward compatibility?
Thanks,
John
When running npm test, which is defined by:
"test": "mocha test/**/*.spec.js"
The path expansion fails to match scripts at a depth of more than one. Therefore everything in test/lib/*.spec.js gets matched, but a test at test/lib/subdir/*.spec.js does not.
When I run mocha test/**/*.spec.js, however, all the tests are matched and run. I'm at something of a loss as to how to debug this.
EDIT
I'm pretty sure this is due to npm running scripts in sh instead of my shell (zsh). I don't know how to fix this.