Skip to content

Commit 6d918c2

Browse files
authored
Merge pull request #114 from BinaryStudioAcademy/task/thjs-63-move-project-into-typescript
thjs-64: Fix hands on backend tests
2 parents f2472ec + 8e0fcc7 commit 6d918c2

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

server/.eslintrc.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@ extends:
1010

1111
overrides:
1212
- files:
13-
- knexfile.js
13+
- knexfile.ts
1414
rules:
1515
'import/no-default-export':
1616
- off
1717
- files:
18-
- src/db/migrations/**/*.js
18+
- src/db/migrations/**/*.ts
1919
rules:
2020
'unicorn/filename-case':
2121
- error
2222
- case: snakeCase
23+
- files:
24+
- jest.config.js
25+
rules:
26+
'@typescript-eslint/no-unsafe-return':
27+
- off
28+
'@typescript-eslint/no-unsafe-member-access':
29+
- off
30+
'@typescript-eslint/explicit-function-return-type':
31+
- off
32+
'@typescript-eslint/no-unsafe-argument':
33+
- off
34+
'@typescript-eslint/no-unsafe-assignment':
35+
- off
36+
'@typescript-eslint/no-unsafe-call':
37+
- off
38+
'import/no-default-export':
39+
- off

server/jest.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { pathsToModuleNameMapper } from 'ts-jest';
5+
6+
import tsconfigJson from './tsconfig.json' assert { type: 'json' };
7+
8+
const sourcePath = join(fileURLToPath(import.meta.url), '../');
9+
10+
const manageKey = key => {
11+
return key.includes('(.*)') ? key.slice(0, -1) + '\\.js$' : key;
12+
};
13+
14+
const manageMapper = mapper => ({
15+
...Object.fromEntries(
16+
Object.entries(mapper).map(([key, value]) => [manageKey(key), value])
17+
),
18+
'^(\\.{1,2}/.*)\\.js$': '$1'
19+
});
20+
21+
export default {
22+
testEnvironment: 'jest-environment-node',
23+
preset: 'ts-jest/presets/default-esm',
24+
extensionsToTreatAsEsm: ['.ts'],
25+
transformIgnorePatterns: ['node_modules/'],
26+
testPathIgnorePatterns: ['node_modules/', 'dist/', 'build/'],
27+
moduleNameMapper: manageMapper(
28+
pathsToModuleNameMapper(tsconfigJson.compilerOptions.paths, {
29+
prefix: sourcePath
30+
})
31+
),
32+
transform: {
33+
'^.+\\.tsx?$': ['ts-jest', { useESM: true }]
34+
},
35+
testTimeout: 10_000,
36+
workerIdleMemoryLimit: '1GB'
37+
};

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"lint": "npm run lint:js",
2121
"build": "tsc && tsc-alias",
2222
"pretest": "cross-env NODE_ENV=test npm run migrate:dev",
23-
"test": "cross-env NODE_ENV=test node --experimental-vm-modules --expose-gc --no-compilation-cache ../node_modules/jest/bin/jest.js --runInBand",
23+
"test": "cross-env NODE_ENV=test node --experimental-vm-modules --expose-gc --no-compilation-cache ../node_modules/jest/bin/jest.js --config jest.config.js --runInBand --forceExit --detectOpenHandles",
2424
"test:starter": "npm run test -- --verbose --rootDir=tests/api/0-starter/",
2525
"test:dislike-post": "npm run test -- --verbose --rootDir=tests/api/1-dislike-post/",
2626
"test:update-post": "npm run test -- --verbose --rootDir=tests/api/2-update-post/",

server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../tsconfig.json",
3-
"include": ["src/**/*.ts", "tests/**/*.ts", "knexfile.ts", "jest.config.ts"],
3+
"include": ["src/**/*.ts", "tests/**/*.ts", "knexfile.ts"],
44
"files": ["src/index.d.ts"],
55
"exclude": ["node_modules"],
66
"compilerOptions": {

0 commit comments

Comments
 (0)