Search code examples
javascriptnode.jsjestjsautomated-testscode-coverage

jest scripts failing with exit status 1


I have a couple of test scripts that are failing after the tests are all passing successfully and not sure the reason. I've searched the web with no solution that resolves the issue.

Here is the output from the log after the execution of the script (npm run patch-coverage)

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'patch-coverage'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prepatch-coverage', 'patch-coverage', 'postpatch-coverage' ]
5 info lifecycle [email protected]~prepatch-coverage: [email protected]
6 info lifecycle [email protected]~patch-coverage: [email protected]
7 verbose lifecycle [email protected]~patch-coverage: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~patch-coverage: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\<...>\node_modules\.bin;C:\Python312\Scripts\;C:\Python312\;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files\RSA SecurID Token Common;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Amazon\AWSSAMCLI\bin\;C:\Program Files\MongoDB\Tools\100\bin;C:\MongoSH\mongosh-1.10.6-win32-x64\bin\mongosh_crypt_v1.dll;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Amazon\AWSCLIV2\;C:\Users\gnorkett\AppData\Local\Microsoft\WindowsApps;C:\Users\gnorkett\.dotnet\tools;C:\Program Files\Azure Data Studio\bin;C:\Users\gnorkett\AppData\Local\Programs\Fiddler;C:\DevUtils;C:\Users\gnorkett\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Amazon\AWSSAMCLI;c:\terraform;c:\terragrunt;C:\Users\gnorkett\AppData\Local\GitHubDesktop\bin;C:\Users\gnorkett\.dotnet\tools;C:\Users\gnorkett\AppData\Roaming\npm
9 verbose lifecycle [email protected]~patch-coverage: CWD: <...>
10 silly lifecycle [email protected]~patch-coverage: Args: [ '-c', 'npm run patch-tests -- --coverage' ]
11 silly lifecycle [email protected]~patch-coverage: Returned: code: 1  signal: null
12 info lifecycle [email protected]~patch-coverage: Failed to exec patch-coverage script
13 verbose stack Error: [email protected] patch-coverage: `npm run patch-tests -- --coverage`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:400:28)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:400:28)
13 verbose stack     at maybeClose (internal/child_process.js:1088:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
14 verbose pkgid [email protected]
15 verbose cwd <...>
16 verbose Windows_NT 10.0.19045
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "patch-coverage"
18 verbose node v14.21.3
19 verbose npm  v6.14.18
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] patch-coverage: `npm run patch-tests -- --coverage`
22 error Exit status 1
23 error Failed at the [email protected] patch-coverage script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

All the tests are successful

Test Suites: 18 passed, 18 total
Tests:       74 passed, 74 total
Snapshots:   126 passed, 126 total
Time:        220.454 s, estimated 340 s
Ran all test suites.
Waiting for the debugger to disconnect...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] patch-tests: `jest --config="./jest.config.patch.js" --runInBand --passWithNoTests "--coverage"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] patch-tests script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ...\npm-cache\_logs\2024-01-31T20_58_41_359Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] patch-coverage: `npm run patch-tests -- --coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] patch-coverage script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ...\npm-cache\_logs\2024-01-31T20_58_41_398Z-debug.log

This is the config file (jest.config.patch.js)

// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

const _ = require('lodash');

const config = _.cloneDeep(require('./jest.config.e2e'));

// The directory where Jest should output its coverage files
config.coverageDirectory = 'test_out/patch';

// reset collectCoverageFrom param to default value
config.collectCoverageFrom = ['resources/patch/patches/**/*.[jt]s'];

config.coveragePathIgnorePatterns = [];

// The glob patterns Jest uses to detect test files
config.testMatch = [
    '<rootDir>/resources/patch/**/__tests__/**/*.e2e.[jt]s',
    '<rootDir>/resources/patch/**/__tests__/**/*.spec.[jt]s',
];

// reset testPathIgnorePatterns param to default value
config.testPathIgnorePatterns = ['<rootDir>/node_modules/', '.tmp'];

config.moduleNameMapper['^resources(.*)$'] = '<rootDir>/resources$1';

config.coverageThreshold = {
    global: {
        branches: 100,
        functions: 100,
        lines: 100,
    },
};

module.exports = config;

I've tried a few suggestions from GitHub

Can anyone provide a solution to resolve the errors?

Note: <...> is a place holder for some potential restricted information as deemed by the company.

Update

I created a simple test as follows and I still get the same error after running the patch-coverage. Could it be the patch-coverage configuration?

describe('186-add-new-locales', () => {
    test('Empty test', async () => {
        const x = 9;
        const y = 5;
        const z = x * y;

        expect(z).toEqual(45);
    });
});

Update (Feb. 6/24)

Upgraded npm to 8.19.4 and node to 16.20.2 - error no longer appears. Does this mean there is a version problem?


Solution

  • So the problem was the coverage as one line of redundant code that would never be hit so removed that code block and reran the coverage script. Got 100% coverage.

    Checked the lcov report that identified the line(s) not being covered.