Currently, I have set up my testing framework using jest
and ts-jest
based on the guidelines provided by the ts-jest
documentation.
When I execute the command yarn test --listTests
, I can identify the specific test file I intend to run: processNewUser.ts
located within a __test__
folder in my project.
I have successfully executed this test individually using the command
yarn test --testPathPattern='processNewUser'
.
However, when I attempt to specify a particular test by its name using commands like
yarn test --testNamePattern='Processes new user. Auth'
, all tests are triggered, including those not matching the specified name.
I have tried various combinations of syntax such as:
yarn test -t="Auth"
,
yarn test -t Auth
,
yarn test --testNamePattern "Auth"
,
jest Auth
,
jest -t="Processes"
,
and numerous other permutations, but none have been successful. I also attempted naming a describe
function wrapper instead of a test, but with no success either.
The contents of my tsconfig.json
file are as follows:
{
"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/**/*"],
}
Additionally, here is the content of my jest.config.ts
file:
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;
My Yarn script only consists of:
"test": "jest",
One of my objectives is to categorize tests with tags like auth
so that I can easily run all authentication-related tests. Can anyone provide assistance or guidance on achieving this?