launch.json中的基本配置是运行vs代码(windows)中的所有mocha测试。
当尝试添加--grep选项时,无法获得预期的模式匹配行为(即只运行匹配测试)。通过尝试不同的组合,我没有发现错误的测试,也没有运行所有的测试。
注意-我可以让grep选项使用命令行(test:grep脚本-尽管模式文本是手动输入的)。
Expect --grep 'CURRENTTEST‘只使用描述中的这个字符串运行测试(例如,1通过测试)。这是我在使用grep选项运行命令行时获得的行为,如下所示:mocha -r ts-node/register -r tsconfig-paths/register "spec/**/*.ts" --grep CURRENTTEST
launch.json的实际行为如下所示:一些其他组合尝试运行所有测试(而不是模式匹配测试)。
其他args组合尝试;
的单独行
以前的相关问题(但不是重复问题);https://stackoverflow.com/a/39012417/20429097 Running test cases selectively with Mocha https://mochajs.org/#-grep-regexp-g-regexp
(B)编码;
export function testFn(): number { return 1; }
测试;
describe('CURRENTTEST test pass', () => {
it('should pass', () => {
expect(testFn()).to.equal(1);
});
});
describe('test fail', () => {
it('should fail', () => {
expect(testFn()).to.equal(2);
});
});
launch.json
{
"version": "0.2.0",
"configurations": [
////////////////////////////// basic config to run all tests - works //////////////////////////////////////
{
"name": "mocha tests",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": [
"-r",
"ts-node/register",
"${workspaceRoot}/spec/**/*.spec.ts",
"--no-timeouts",
"--colors",
"--recursive",
],
"cwd": "${workspaceRoot}",
// "internalConsoleOptions": "openOnSessionStart",
// "console": "integratedTerminal",
},
/////////////////////// grep config to run CURRENTTEST only - doesn't work ////////////////////////////
{
"name": "mocha CURRENTTEST",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": [
"-r",
"ts-node/register",
"${workspaceRoot}/spec/**/*.spec.ts --grep 'CURRENTTEST'",
"--no-timeouts",
"--colors",
"--recursive",
],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
// "console": "integratedTerminal",
}
]
}
package.json
{
"name": "min code grep test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@types/chai": "latest",
"@types/mocha": "latest",
"@types/node": "latest",
"chai": "latest",
"eslint-import-resolver-typescript": "latest",
"eslint-plugin-jsx-a11y": "latest",
"eslint-plugin-react": "latest",
"eslint-plugin-react-hooks": "latest",
"ts-node": "latest",
"typescript": "latest"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"eslint": "latest",
"eslint-config-airbnb-base": "latest",
"eslint-config-airbnb-typescript": "latest",
"eslint-config-google": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest",
"mocha": "latest"
},
"scripts": {
"test": "mocha -r ts-node/register -r tsconfig-paths/register './spec/**/*.spec.ts'",
"test:grep": "mocha -r ts-node/register -r tsconfig-paths/register \"spec/**/*.ts\" --grep"
},
"author": "",
"license": "ISC"
}
发布于 2022-11-11 03:50:55
每个参数都应该是数组中的一个新元素,例如:
{
"name": "mocha CURRENTTEST",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": [
"-r",
"ts-node/register",
"${workspaceRoot}/spec/**/*.spec.ts",
"--grep",
"CURRENTTEST",
"--no-timeouts",
"--colors",
"--recursive",
],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
// "console": "integratedTerminal",
}
https://stackoverflow.com/questions/74333733
复制相似问题