Typescript 尝试在Jest中使用-t或--testNamePattern将运行所有测试
我正在使用Typescript 尝试在Jest中使用-t或--testNamePattern将运行所有测试,typescript,unit-testing,testing,jestjs,ts-jest,Typescript,Unit Testing,Testing,Jestjs,Ts Jest,我正在使用jest和ts jest按照ts jest在其文档中描述的方式进行配置 如果我运行纱线测试--listTests我可以看到我想要运行的测试文件:processNewUser.ts包含在我的项目的\uuuuuuuuu测试文件夹的输出中 我只能使用纱线测试--testPathPattern='processNewUser' 但如果我尝试使用纱线测试--testNamePattern=”处理新用户。Auth'这是测试的名称,然后每个测试都会运行,包括所有没有指定名称字符串的测试 同: 纱线测
jest
和ts jest
按照ts jest
在其文档中描述的方式进行配置
如果我运行纱线测试--listTests
我可以看到我想要运行的测试文件:processNewUser.ts
包含在我的项目的\uuuuuuuuu测试
文件夹的输出中
我只能使用纱线测试--testPathPattern='processNewUser'
但如果我尝试使用纱线测试--testNamePattern=”处理新用户。Auth'
这是测试的名称,然后每个测试都会运行,包括所有没有指定名称字符串的测试
同:
纱线测试-t=“Auth”
纱线测试-t认证
纱线测试--testNamePattern“Auth”
jest Auth
jest-t=“进程”
等等。
每一种语法组合都是如此。还尝试了命名descriple
函数包装器而不是测试。不走运
我的tsconfig.json
是:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"removeComments": false,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"lib": [
"ES2020.Promise",
"ES2015.Iterable",
"ES2015.Symbol.WellKnown"
],
},
"include": ["src/**/*"],
}
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
clearMocks: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
preset: 'ts-jest',
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/', '\\.pnp\\.[^\\/]+$'],
}
export default config;
我的jest.config.ts
是:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true,
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"removeComments": false,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"lib": [
"ES2020.Promise",
"ES2015.Iterable",
"ES2015.Symbol.WellKnown"
],
},
"include": ["src/**/*"],
}
import type {Config} from '@jest/types';
const config: Config.InitialOptions = {
clearMocks: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
preset: 'ts-jest',
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/', '\\.pnp\\.[^\\/]+$'],
}
export default config;
纱线脚本只是:“test”:“jest”,
我希望它能够用auth
标记一个测试,例如运行所有的auth测试
是否有帮助?定义了按名称筛选测试的谓词:
if(globalConfig.testNamePattern){
const testNameRegex=newregexp(globalConfig.testNamePattern'i');
env.specFilter=(spec:spec)=>testNameRegex.test(spec.getFullName());
}
注意,它根据每个规范的全名检查创建的regexp,即测试套件本身的名称加上所有周围描述块的名称