笑话脚本失败并退出状态 1

问题描述 投票:0回答:1

我有几个测试脚本在测试全部成功通过后失败,但不确定原因。我在网上搜索过没有解决的解决方案 问题。

这是脚本执行后日志的输出(

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 ]

所有测试均成功

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

这是配置文件(

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;

我尝试了来自 GitHub

的一些建议

任何人都可以提供解决方案来解决这些错误吗?

注意:<...>是公司认为一些潜在受限信息的占位符。

更新

我创建了一个简单的测试,如下所示,运行后我仍然遇到相同的错误

patch-coverage
。难道是补丁覆盖配置的问题?

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

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

更新(2月6日/24日)

将 npm 升级到 8.19.4,将节点升级到 16.20.2 - 错误不再出现。这是不是说明版本有问题?

javascript node.js jestjs automated-tests code-coverage
1个回答
0
投票

所以问题在于覆盖率是一行永远不会被命中的冗余代码,因此删除了该代码块并重新运行覆盖率脚本。覆盖率达到 100%。

检查了 lcov 报告,确定未覆盖的线路。

© www.soinside.com 2019 - 2024. All rights reserved.