Skip to content

Commit

Permalink
Separate custom matchers declarations into .d.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
nibble-4bits committed Oct 15, 2023
1 parent 885bcea commit 3e48711
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 44 deletions.
3 changes: 3 additions & 0 deletions __tests__/EventLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type {
} from '../src/typings/EventLogs';
import { StatesRuntimeError } from '../src/error/predefined/StatesRuntimeError';
import { EventLogger } from '../src/stateMachine/EventLogger';

// NOTE: We need to import the custom matcher declarations, since VSCode doesn't recognize custom tsconfigs
// See: https://github.com/microsoft/vscode/issues/12463
import './_customMatchers';

afterEach(() => {
Expand Down
15 changes: 15 additions & 0 deletions __tests__/_customMatchers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
export {};

interface CustomMatchers<R = unknown> {
toSettle(ms: number): Promise<R>;
numberBetween(argumentOne: number, argumentTwo: number): R;
}

declare global {
namespace jest {
interface Expect extends CustomMatchers {}
interface Matchers<R> extends CustomMatchers<R> {}
interface InverseAsymmetricMatchers extends CustomMatchers {}
}
}
43 changes: 0 additions & 43 deletions __tests__/_customMatchers.ts

This file was deleted.

8 changes: 8 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"skipLibCheck": false,
"noEmit": true
},
"files": ["_customMatchers.d.ts"]
}
16 changes: 15 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const { defaults: tsjPreset } = require('ts-jest/presets');

/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.test.ts'],
setupFilesAfterEnv: ['./__tests__/customMatchers.ts'],
moduleFileExtensions: ['js', 'mjs', 'cjs', 'ts', 'd.ts', 'json'],
verbose: true,
transform: {
'^.+\\.ts$': [
'ts-jest',
{
...tsjPreset.transform,
tsconfig: './__tests__/tsconfig.json',
},
],
},
};

0 comments on commit 3e48711

Please sign in to comment.