launch.json 中的基本配置在 vs 代碼(windows)中運行所有 mocha 測驗。
嘗試添加 --grep 選項時,無法獲得預期的模式匹配行為(即僅運行匹配測驗)。嘗試了各種組合后,我沒有發現任何測驗錯誤,或者運行所有測驗。
注意 - 我可以讓 grep 選項與命令列一起使用(測驗:grep 腳本 - 盡管模式文本是手動輸入的)。
期望 --grep 'CURRENTTEST' 僅在描述中使用此字串運行測驗(即示例中的 1-通過測驗)。這是我從使用 grep 選項運行命令列得到的行為,如下所示;
mocha -r ts-node/register -r tsconfig-paths/register "spec/**/*.ts" --grep CURRENTTEST
launch.json 的實際行為如圖所示:
Error: No test files found: "C:\\temp\\Min code grep test/spec/**/*.spec.ts --grep 'CURRENTTEST'"
其他一些組合嘗試運行所有測驗(而不是模式匹配測驗)。
嘗試了其他引陣列合;
- 在與測驗位置相同的行上具有 grep 選項,并在下面作為單獨的行。
- 帶有單引號、雙引號(帶有轉義斜杠)的環繞模式,什么都沒有。
以前相關(但不重復)的問題; https://stackoverflow.com/a/39012417/20429097 使用 Mocha 選擇性地運行測驗用例 https://mochajs.org/#-grep-regexp-g-regexp
代碼;
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);
});
});
啟動.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",
}
]
}
包.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"
}
uj5u.com熱心網友回復:
每個引數都應該是陣列中的一個新元素,例如:
{
"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://www.uj5u.com/qukuanlian/532524.html
