Skip to content

Commit

Permalink
test: update jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Mar 10, 2023
1 parent 323c682 commit c932781
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ module.exports = {
'react/prop-types': 'off',
'react/jsx-props-no-spreading': 'off',
},
}, {
files: ['*.spec.ts'],
rules: {
'import/no-extraneous-dependencies': 'off',
},
}],
};
19 changes: 17 additions & 2 deletions jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
"rootDir": "./spec",
"testEnvironment": "node",
"testRegex": ".spec.ts$",
"extensionsToTreatAsEsm": [".ts"],
"transformIgnorePatterns": ["node_modules"],
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
"^.+\\.(t|j)sx?$": [
"ts-jest",
{
"useESM": true,
"tsconfig": "./tsconfig.test.json",
"isolatedModules": true
}
]
},
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"testTimeout": 10000,
"preset": "ts-jest"
"preset": "ts-jest/presets/default-esm",
"verbose": true,
"silent": true,
"forceExit": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"clean": "rm -fR lib",
"build": "tsc",
"dev": "yarn clean && tsc -w",
"test": "dotenv -e .env -- jest --config ./jest.json --runInBand --forceExit --detectOpenHandles --verbose --silent",
"test": "NODE_OPTIONS=--experimental-vm-modules dotenv -e .env -- jest --config ./jest.json --runInBand --detectOpenHandles",
"ts-node": "ts-node",
"lint": "eslint './src/**/*.{ts,js}' './spec/**/*.{ts,js}' './example-app/**/*.{ts,js}' --ignore-pattern 'build' --ignore-pattern 'yarn.lock'",
"check:all": "yarn lint && yarn test && yarn build",
Expand All @@ -47,6 +47,7 @@
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@jest/globals": "^29.5.0",
"@mikro-orm/core": "^5.6.13",
"@mikro-orm/postgresql": "^5.6.13",
"@semantic-release/git": "^10.0.1",
Expand Down
3 changes: 3 additions & 0 deletions spec/Database.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'reflect-metadata';
import { MikroORM } from '@mikro-orm/core';
import { jest } from '@jest/globals';

import { Database } from '../src/Database.js';
import { initORM } from './utils/init-orm.js';

jest.useFakeTimers();

describe('Database', () => {
let orm: MikroORM;

Expand Down
3 changes: 3 additions & 0 deletions spec/Property.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'reflect-metadata';
import { MikroORM } from '@mikro-orm/core';
import { jest } from '@jest/globals';

import { Property } from '../src/Property.js';
import { Car } from './entities/Car.js';
import { initORM } from './utils/init-orm.js';
import { Resource } from '../src/Resource.js';

jest.useFakeTimers();

const findProperty = (properties: Array<Property>, field: string): Property | undefined => properties.find(
(p) => p.getColumnMetadata().name === field,
);
Expand Down
4 changes: 3 additions & 1 deletion spec/Resource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import 'reflect-metadata';
import { BaseProperty, BaseRecord, ValidationError, Filter, flat } from 'adminjs';
import { validate } from 'class-validator';
import { MikroORM } from '@mikro-orm/core';
import { jest } from '@jest/globals';

import { Resource } from '../src/Resource.js';

import { Car, CarType } from './entities/Car.js';
import { initORM } from './utils/init-orm.js';
import { User, UserRole } from './entities/User.js';
import { Seller } from './entities/Seller.js';

jest.useFakeTimers();

describe('Resource', () => {
let resource: Resource;
let orm: MikroORM;
Expand Down
2 changes: 1 addition & 1 deletion spec/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { v4 } from 'uuid';
import { BaseEntity, Entity, Enum, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';

import type { Car } from './Car.js';
import { Car } from './Car.js';

export enum UserRole {
ADMIN = 'admin',
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"baseUrl": ".",
"skipLibCheck": true
"skipLibCheck": true,
"allowJs": true
},
"include": [
"./src/**/*.ts"
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"./src/**/*.ts",
"./spec/**/*.ts"
]
}

0 comments on commit c932781

Please sign in to comment.