Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"npm test" fails although tests are successful (reactjs app created with create-react-app)

I created a reactjs app using create-react-app.

Running the app works. Running the tests works. Very nice and easy.

Then created a pipeline for gitlab to run the build and tests.

Builds successfully on gitlab but when it comes to tests it fails.

> react-scripts test

PASS src/App.test.js
  ✓ renders without crashing (25ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.955s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

I cannot find anyway to get more details about the reason for failure and have no idea how to fix it.

After running npm test --verbose here is the new output:

$npm test --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'test',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'pretest', 'test', 'posttest' ]
npm info lifecycle [email protected]~pretest: [email protected]
npm info lifecycle [email protected]~test: [email protected]

> [email protected] test /builds/easyauto123/website
> react-scripts test

PASS src/App.test.js
  ✓ renders without crashing (30ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.13s
Ran all test suites.
npm verb lifecycle [email protected]~test: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/builds/easyauto123/website/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle [email protected]~test: CWD: /builds/easyauto123/website
npm info lifecycle [email protected]~test: Failed to exec test script
npm ERR! Test failed.  See above for more details.
npm verb exit [ 1, true ]
npm timing npm Completed in 3576ms
npm verb code 1
ERROR: Job failed: exit code 1
like image 555
Calin Pirtea Avatar asked Oct 26 '25 11:10

Calin Pirtea


1 Answers

You can verify if you have any threshold configured in your project.

According to jest documentation, https://jestjs.io/docs/configuration, if you set a coverageThreshold on your jest.config.js the test will fail if there is less than 80% branch, line, and function coverage, according to the configuration below.

"coverageThreshold": {
  "global": {
    "branches": 80,
    "functions": 80,
    "lines": 80,
    "statements": -10
  }
}

You can pass all tests but jest will fail if you do not accomplish the threshold specified. Moreover, it does not give you any tips about this on the error log.

I had the same issue with an angular project and it was due to this configuration.

like image 151
Kaleb Dalla Pria Avatar answered Oct 28 '25 23:10

Kaleb Dalla Pria