How can I end passing Jest test on Circle CI? - npm

My app passes all the tests in Circle CI. However, after it passes it just hangs there until it times out at 10 minutes, and is eventually deemed failed.
Tests do pass locally. I get:
Test Suites: 1 failed, 11 passed, 12 total
Tests: 1 failed, 55 passed, 56 total
Snapshots: 2 obsolete, 10 passed, 10 total
Time: 11.196 s
Ran all test suites matching /a|q/i.
Active Filters: filename /a|q/
› Press c to clear filters.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press o to only run tests related to changed files.
› Press u to update failing snapshots.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
at the end in my local terminal. Then I would press Ctrl-C. I get the same thing in Circle CI:
Test Suites: 1 failed, 10 passed, 11 total
Tests: 1 failed, 49 passed, 50 total
Snapshots: 2 obsolete, 9 passed, 9 total
Time: 10.752 s
Ran all test suites matching /a/i.
Active Filters: filename /a/
› Press c to clear filters.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press o to only run tests related to changed files.
› Press u to update failing snapshots.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
Too long with no output (exceeded 10m0s): context deadline exceeded
except for the last line.
This is my .circleci/config.yml:
version: 2.1
orbs:
node: circleci/node#4.7.0
# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
docker:
- image: 'circleci/node:latest'
steps:
- checkout
- run:
name: "npm install"
command: sudo npm install
- run:
name: "npm build"
command: sudo npm run build
test:
docker:
- image: 'circleci/node:latest'
steps:
- checkout
- run:
name: "npm install"
command: sudo npm install
- run:
name: "npm test"
command: sudo npm test a
workflows:
build_and_test:
jobs:
- build
- test:
requires:
- build
build works fine. All spacing/linting is correct.
These are the commands in package.json:
"scripts": {
"begin": "react-scripts start && node server/server.js",
"start": "node server/server.js",
"build": "react-scripts --openssl-legacy-provider build",
"eject": "react-scripts eject",
"test": "react-scripts test",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install && npm run build"
},
I have also tried adding
- run: q
after the test line in .yml file, but it won't even get to the run q because sudo npm test a does not end as mentioned above.

Use
"test": "react-scripts test --watchAll=false",
Adding
--watchAll=false
at the end of
"test": "react-scripts test",
solved the issue.
Test in Circle CI was hanging because it was in watch mode.
Had to explicitly disable watch mode.
CRA's Jest comes with configured watch mode by default.
Also check if any snapshot is obsolete; this will prevent tests from passing in the CI.

Related

What should be NPM command for solving this question?

I tried various solutions for this question but not able to pass 2 test cases amongst 4. Please help me crackdown this problem
Perform the below mentioned steps by creating package.json file named npm_commands in the maxbot directory
Create a file named index.js.
Write a js code in index.js file to create a string named myVar and value as node package manager
and convert it into uppercase.
NOTE: Please use console.log to display the output of myVar in index.js file
Configure scripts in package.json
(a) to check the versions of npm and node by using npm run release | tee output1.txt
(b) to execute index.js by using npm run build | tee output.txt
npm init - to initialize new package
give npm_commands as package name
give index.js as start file
Create new file named as index.js
declare : let myVar = "node package manager"
print var in uppercase: console.log(myVar.toUpperCase());
Add these scripts in package.json
to check npm and node version: "release": "npm -v && node -v",
to execute index.js file: "build": "node index.js"
Save and then run these commands to get the results:
npm run release | tee output1.txt
npm run build | tee output.txt
Step 1: run the command to initialize new package
npm init
Step 2: Command will start package initialization process
Set the package name:
package name: (challange) npm_commands
Step3: Press enter till time it ask for "entry point", by default it set to index.js verify and press enter key. Until the initialization process ends.
Step 4: Go to editor project explorer add create new file index.js, and add following code in it.
let myVar = 'node package manager';
console.log(myVar.toUpperCase());
Step 5: Add following lines into script block of package.json file
"release" : "npm -v && node -v",
"build" : "node index.js",
Script block looks like as below after adding above lines
"scripts": {
"release" : "npm -v && node -v",
"build" : "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
Step 6: Now open the command prompt and run the following commands
npm run release | tee output1.txt
npm run build | tee output.txt
Above commands create the output1.txt, and output.txt files in project explorer containing respective commands output.
Step 7: That's it! now run the test and check your FS_SCORE for 100% and submit the test.

Grouping parallel runs in one entry on Cypress.io using Gitlab CI

I have an Nx project with Gitlab CI configured. My project has 2 kinds of E2E testing included - main project's and Storybook's ones. The tests themselves work fine, but I use cypress.io dashboard for E2E results gathering.
I configured the project to record them and it works, but I want them to be saved as one run, but with 2 groups x 2 browsers (Main/Storybook x Chrome/Firefox). Recording also works fine, cypress.io dashboard recognizes 2 browsers and groups correctly, but I only get results for one browser (there is one result for Chrome for Main and one for Firefox for Storybook - the second browsers are visible in filters, but results for them are empty - please, see the screenshots).
I tried some flags and configurations from https://docs.cypress.io/guides/guides/parallelization.html
Unfortunately, no matter what I try, there is always some kind of error like:
You passed the --parallel flag, but we do not parallelize tests across
different environments. This machine is sending different environment
parameters than the first machine that started this parallel run. The
existing run is: https://dashboard.cypress.io/projects/qwerty/runs/44
In order to run in parallel mode each machine must send identical
environment parameters such as:
specs
osName
osVersion
browserName
browserVersion (major) This machine sent the following parameters: { "osName": "linux", "osVersion": "Ubuntu - 20.04", "browserName":
"Firefox", "browserVersion": "80.0.1", "specs": [
"src/integration/app/app.spec.ts" ] } https://on.cypress.io/parallel-group-params-mismatch
Only one browser per group passes and the 2nd one gets the following error.
These are my scripts in package.json:
# 1st --parallel flag for nx and 2nd after -- for Cypress directly
# $CYPRESS_RECORD_KEY - key provided by cypress.io
# $CI_ID - <branch-name>-<commit-hash> - e.g. my-new-branch-qweqtwerwtreyzsxfc4123dxfv
"e2e:ci": "nx e2e main-e2e --prod --headless --parallel --record --key $CYPRESS_RECORD_KEY --ci-build-id $CI_ID --group MainWeb -- --parallel",
"e2e:ci:chrome": "yarn e2e:ci --browser=chrome",
"e2e:ci:firefox": "yarn e2e:ci --browser=firefox",
"e2e:storybook:ci": "nx e2e storybook-e2e --prod --headless --parallel --record --key $CYPRESS_RECORD_KEY --ci-build-id $CI_ID --group Storybook -- --parallel",
"e2e:storybook:ci:chrome": "yarn e2e:storybook:ci --browser=chrome",
"e2e:storybook:ci:firefox": "yarn e2e:storybook:ci --browser=firefox"
And here is my .gitlab-ci.yml (e2e stage part only):
E2E Main-Web - Chrome:
stage: e2e
script:
- yarn e2e:ci:chrome
E2E Main-Web - Firefox:
stage: e2e
script:
- yarn e2e:ci:firefox
E2E Storybook - Chrome:
stage: e2e
script:
- yarn e2e:storybook:ci:chrome
E2E Storybook - Firefox:
stage: e2e
script:
- yarn e2e:storybook:ci:firefox
I'm not sure what is wrong here. I tried so many configurations, flags, solutions (even parallelization on Gitlab), but always there is something wrong...
Of course I set cypress.io > Project Settings > Parallelization > Run Completion Delay for 60s.
I think the answer lies in the Cypress error you shared:
You passed the --parallel flag, but we do not parallelize tests across
different environments.
You are triggering two parallel runs, with each parallel run setting up two browsers. As the error says, this is not expected - each parallel run should have only one browser.
The solution in this case is easy: just configure four groups, one for each test and browser type.
This is how this could look:
"e2e:ci": "nx e2e main-e2e --prod --headless --parallel --record --key $CYPRESS_RECORD_KEY --ci-build-id $CI_ID -- --parallel",
"e2e:ci:chrome": "yarn e2e:ci --browser=chrome --group 'MainWeb Chrome' ",
"e2e:ci:firefox": "yarn e2e:ci --browser=firefox --group 'MainWeb Firefox' ",
"e2e:storybook:ci": "nx e2e storybook-e2e --prod --headless --parallel --record --key $CYPRESS_RECORD_KEY --ci-build-id $CI_ID -- --parallel",
"e2e:storybook:ci:chrome": "yarn e2e:storybook:ci --browser=chrome --group 'Storybook Chrome'",
"e2e:storybook:ci:firefox": "yarn e2e:storybook:ci --browser=firefox --group 'Storybook Firefox'"

How to use commander.js command through npm command

I'm using commander.js command like this ./index.js --project mono --type item --title newInvoice --comments 'Creates an invoice' --write, Now I'm using the command through npm run item newInvoice by setting some options in package.json file like this
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"snapshot": "node --max-old-space-size=10240 ./scripts/snapshot.js",
"item": "./index.js --project mono --type item --title",
"config": "./index.js --project mono --type config --title"
}
But whenever I'm trying to get the --write option with npm using npm run item newInvoice --write it's showing undefined for --write
Source Code:
#!/usr/bin/env node
const fs = require('fs');
const program = require('commander');
require('colors');
program
.version('0.1.0')
.option('--project [project]', 'Specifies the project name', 'mono')
.option('--type [type]', 'Type of code to generate, either "item" or "config"', /^(config|item)$/, 'config')
.option('--title [title]', 'Title of the item or config', 'untitled')
.option('--comments [comments]', 'Configs: describe the config', '#todo description/comments')
.option('--write', 'Write the source code to a new file in the expected path')
.option('--read', 'To see what would be written the source code to a new file in the expected path')
.parse(process.argv);
console.log(program.write, program.read); //=> undefined undefined
Can anyone help me how to use commander js command with npm?
When you run your npm run command you need to utilize the special -- option to demarcate the end of any option(s) that may belong to the npm run command itself (e.g. --silent), and the beginning of the argument(s) that are to be passed to the end of the npm script.
Run the following command instead:
npm run item -- newInvoice --write
Given the aforementioned command and the command currently defined your npm script named item they essentially form the following compound command prior to execution:
./index.js --project mono --type item --title newInvoice --write
^ ^
The npm run documentation states the following:
As of npm#2.0.0, you can use custom arguments when executing scripts. The special option -- is used by getopt to delimit the end of the options. npm will pass all the arguments after the -- directly to your script.
and it's usage syntax is defined in the Synopsis section as:
npm run-script <command> [--silent] [-- <args>...]
^^
Note: It's not possible to add the -- option to the npm script itself.

npm tslint don't give error

Hey all got a issue with npm and tslint I was hoping you could help me with.
Ok here comes my situation and code:
package.json
"scripts": {
"lint": "tslint -c tslint.json 'src/app/**/*.ts'",
"pretest": "npm run lint ",
"test": "echo 'No test are made'",
...
},
When I run command npm test this is the output:
input terminal
$ npm test
output terminal
> keoom#1.0.0 pretest c:\Users\Hjorth\Documents\github\keoom-angular
> npm run lint
> keoom#1.0.0 lint c:\Users\Hjorth\Documents\github\keoom-angular
> tslint -c tslint.json 'src/app/**/*.ts'
> keoom#1.0.0 test c:\Users\Hjorth\Documents\github\keoom-angular
> echo 'No test are made'
'No test are made'
If I only run command tslint -c tslint.json 'src/app/**/*.ts' I on the other hand see the linting error.
input terminal
$ tslint -c tslint.json 'src/app/**/*.ts'
output terminal
src/app/app.component.ts[1, 27]: " should be '
So as you can see there is a linting error in my code, but if I am not running the script directly It will not show. What I am expecting is this:
When I run npm test the script pretest will run, and that script will run the script lint, it will then exit with exit 0 before test script is run as it will find the linting error.
Anyone that can be of assistance.
It's the quotes around the file spec in the tslint command that are the problem:
"lint": "tslint -c tslint.json 'src/app/**/*.ts'"
^ ^
If you remove those, you should see the expected error reported by tslint.

How to run ember-cli test in jenkins

How can i run Ember-cli test in jenkins?
Currently to run the tests i added a build step "Execute shell" with the following in it:
ember test --silent --config-file ${WORKSPACE}/testem.json > ${WORKSPACE}/xunit-ember-dev.xml;
But it doesn't work, this is the output
<testsuite name="Testem Tests" tests="0" failures="0" timestamp="Thu Feb 12 2015 14:20:24 GMT+0100 (CET)" time="0">
</testsuite>
If I do the same manually in the workspace as jenkins user I got the expected results.
<testsuite name="Testem Tests" tests="70" failures="0" timestamp="Thu Feb 12 2015 15:06:40 GMT+0100 (CET)" time="15">
<testcase name="PhantomJS 1.9 Integration - Homepage: Should display the homepage"/>
<testcase name="PhantomJS 1.9 Integration - Profile: Should display the profile sections"/>
...
Every time I make Jenkins run the tests, he find no tests.
Thanks
Just add an Execute Shell step that runs:
npm run test > results.tap
This command tells npm to run a script called test and redirect the output to a file called results.tap. (The purpose of redirecting to results.tap is so you can take this file and hand it to Publish TAP Results post-build step and get pretty charts of test runs.)
In your package.json, you should have a block that looks like this:
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
},
(This is the default from ember-cli 1.13.8 and likely a few versions earlier than that.)
Using this approach, you don't need to have ember-cli globally installed on your build system: it will simply pick it up from the project's node_modules folder.
Caveat emptor: you'll likely find some blogs/forum posts that tell you to run npm run test | tee results.tap. This will run the tests, however, it will eat the return code. (If the test run fails, the npm process exits with a return value of 1, but since you're piping output to a second command (tee), the return code of that command is what jenkins sees. The net result is that jenkins will interpret test failures as success and keep on running build steps.)