Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit d2a05e9

Browse files
authored
test: fix root execution (#350)
* chore(deps): patched ts-jest and fast-check * chore(workspace): fix test execution from root * ci: run all tests in daily and beta flows
1 parent 1539ea6 commit d2a05e9

19 files changed

+152
-121
lines changed

.github/workflows/beta_release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- name: Install dependencies
2828
run: yarn
2929

30+
- name: Test project
31+
run: yarn test
32+
3033
- name: Release
3134
env:
3235
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/daily_release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- name: Install dependencies
2828
run: yarn
2929

30+
- name: Test project
31+
run: yarn test
32+
3033
- name: Build Dashboard
3134
env:
3235
DOTENV_CONFIG_PATH: .env.beta

YCAI/jest.config.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
const { pathsToModuleNameMapper } = require('ts-jest');
2+
const jestConfigBase = require('../jest.config.base');
23
const tsConfig = require('./tsconfig.json');
34

4-
const moduleNameMapper = pathsToModuleNameMapper(
5-
tsConfig.compilerOptions.paths, {
6-
prefix: '<rootDir>/src'
7-
}
8-
);
5+
const tsPaths = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
6+
prefix: '<rootDir>/src/',
7+
});
8+
9+
const moduleNameMapper = {
10+
...tsPaths,
11+
'\\.(svg|ttf)$': '<rootDir>/__mocks__/fileMock.js',
12+
'\\.(css)$': '<rootDir>/__mocks__/styleMock.js',
13+
};
914

1015
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
1116
module.exports = {
12-
preset: 'ts-jest',
17+
...jestConfigBase,
1318
testEnvironment: 'jsdom',
14-
moduleNameMapper: {
15-
...moduleNameMapper,
16-
'\\.(svg|ttf)$': '<rootDir>/__mocks__/fileMock.js',
17-
'\\.(css)$': '<rootDir>/__mocks__/styleMock.js',
18-
},
19+
displayName: 'YCAI',
20+
moduleNameMapper,
1921
globals: {
2022
'ts-jest': {
2123
// TS reports strange errors with jest,
2224
// that it doesn't report when running plain tsc...
23-
diagnostics: false,
25+
diagnostics: true,
2426
isolatedModules: true,
27+
useESM: true,
28+
tsconfig: '<rootDir>/tsconfig.json',
2529
},
2630
},
27-
setupFilesAfterEnv: ['./jest.setup.js'],
31+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
32+
collectCoverageFrom: ['<rootDir>src/**'],
2833
};

YCAI/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"semantic-release": "^19.0.2",
6262
"style-loader": "^3.3.1",
6363
"svgdom": "^0.1.10",
64-
"ts-jest": "^27.1.2",
64+
"ts-jest": "^27.1.3",
6565
"ts-loader": "^9.2.6",
6666
"ts-node": "^10.4.0",
6767
"typescript": "^4.5.4",

backend/jest.config.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
const tsConfig = require("./tsconfig.json");
1+
const jestBaseConfig = require('../jest.config.base');
2+
const tsConfig = require('./tsconfig.json');
23
// jest.config.js
3-
const { pathsToModuleNameMapper } = require("ts-jest");
4-
const { jsWithTsESM } = require("ts-jest/presets");
4+
const { pathsToModuleNameMapper } = require('ts-jest');
55

6-
const moduleNameMapper = pathsToModuleNameMapper(
7-
tsConfig.compilerOptions.paths,
8-
{
9-
prefix: "<rootDir>",
10-
}
11-
);
6+
const paths = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
7+
prefix: '<rootDir>',
8+
});
9+
10+
const moduleNameMapper = {
11+
...paths,
12+
...jestBaseConfig.moduleNameMapper,
13+
};
1214

1315
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
1416
module.exports = {
15-
preset: "ts-jest",
16-
testEnvironment: "node",
17-
roots: ["./", "../packages/shared"],
18-
projects: ['./', '../packages/shared'],
17+
...jestBaseConfig,
18+
displayName: 'backend',
1919
moduleNameMapper,
2020
globals: {
21-
"ts-jest": {
21+
'ts-jest': {
2222
// TS reports strange errors with jest,
2323
// that it doesn't report when running plain tsc...
2424
diagnostics: false,
2525
isolatedModules: true,
26-
useESM: true
26+
useESM: true,
27+
tsconfig: '<rootDir>/tsconfig.json',
2728
},
2829
},
29-
transform: {
30-
...jsWithTsESM.transform,
31-
'\\.js$': 'ts-jest'
32-
},
33-
clearMocks: true,
3430
testTimeout: 10000,
35-
setupFilesAfterEnv: ["./jest.setup.js"],
36-
coverageProvider:"v8",
37-
collectCoverageFrom: ["./bin/**", "./lib/**", "./routes/**", "./parsers/**"],
31+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
32+
coverageProvider: 'v8',
33+
collectCoverageFrom: [
34+
'<rootDir>/bin/**',
35+
'<rootDir>/lib/**',
36+
'<rootDir>/routes/**',
37+
'<rootDir>/parsers/**',
38+
],
3839
coverageThreshold: {
3940
global: {
4041
branches: 30,
@@ -43,5 +44,4 @@ module.exports = {
4344
statements: 60,
4445
},
4546
},
46-
coveragePathIgnorePatterns: ["node_modules"],
4747
};

backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"jest": "^27.4.7",
6666
"prettier": "^2.5.1",
6767
"supertest": "^6.1.6",
68-
"ts-jest": "^27.1.2",
68+
"ts-jest": "^27.1.3",
6969
"tsconfig-paths": "^3.12.0",
7070
"typescript": "^4.5.4"
7171
}

guardoni/global-setup.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// global-setup.js
22
const { setup: setupDevServer } = require('jest-dev-server');
3+
const { basename } = require('path');
34

45
module.exports = async function globalSetup() {
6+
const currentDir = basename(process.cwd());
7+
const currentDirCommand = currentDir === 'guardoni' ? '../' : './';
58
await setupDevServer({
6-
command: `cd ../ && yarn backend watch`,
9+
command: `cd ${currentDirCommand} && yarn backend watch`,
710
launchTimeout: 50000,
811
port: 9000,
912
});
13+
1014
// Your global setup
1115
};

guardoni/jest.config.js

+22-32
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,40 @@
1+
const jestBaseConfig = require('../jest.config.base');
12
const tsConfig = require('./tsconfig.json');
2-
// jest.config.js
33
const { pathsToModuleNameMapper } = require('ts-jest');
4-
const { jsWithTsESM } = require('ts-jest/presets');
54

6-
const moduleNameMapper = pathsToModuleNameMapper(
7-
tsConfig.compilerOptions.paths,
8-
{
9-
prefix: '<rootDir>/src',
10-
}
11-
);
5+
const tsPaths = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
6+
prefix: '<rootDir>/src/',
7+
});
8+
9+
const moduleNameMapper = {
10+
...tsPaths,
11+
};
1212

1313
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
1414
module.exports = {
15-
preset: 'ts-jest',
16-
testEnvironment: 'node',
17-
roots: ['./', '../packages/shared'],
18-
projects: ['./', '../packages/shared'],
15+
...jestBaseConfig,
16+
rootDir: __dirname,
17+
displayName: 'guardoni',
1918
moduleNameMapper,
20-
modulePathIgnorePatterns: ['profiles', 'build'],
19+
modulePathIgnorePatterns: [
20+
...jestBaseConfig.modulePathIgnorePatterns,
21+
'profiles',
22+
'build',
23+
],
2124
globals: {
2225
'ts-jest': {
2326
// TS reports strange errors with jest,
2427
// that it doesn't report when running plain tsc...
25-
diagnostics: false,
28+
diagnostics: true,
2629
isolatedModules: true,
2730
useESM: true,
31+
tsconfig: '<rootDir>/tsconfig.json',
2832
},
2933
},
30-
transform: {
31-
...jsWithTsESM.transform,
32-
'\\.js$': 'ts-jest',
33-
},
34-
clearMocks: true,
3534
testTimeout: 10000,
36-
setupFilesAfterEnv: ['./jest.setup.js'],
37-
globalSetup: './global-setup.js',
38-
globalTeardown: './global-teardown.js',
35+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
36+
globalSetup: '<rootDir>/global-setup.js',
37+
globalTeardown: '<rootDir>/global-teardown.js',
3938
coverageProvider: 'v8',
40-
collectCoverageFrom: ['./src/**'],
41-
coverageThreshold: {
42-
global: {
43-
branches: 30,
44-
functions: 60,
45-
lines: 60,
46-
statements: 60,
47-
},
48-
},
49-
coveragePathIgnorePatterns: ['node_modules'],
39+
collectCoverageFrom: ['<rootDir>/src/**'],
5040
};

guardoni/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"prettier": "^2.5.1",
9292
"rpmbuild": "^0.0.23",
9393
"style-loader": "^3.3.1",
94-
"ts-jest": "^27.1.2",
94+
"ts-jest": "^27.1.3",
9595
"ts-loader": "^9.2.6",
9696
"typescript": "^4.5.4",
9797
"utf-8-validate": "^5.0.7",

guardoni/tsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
"compilerOptions": {
44
"allowJs": true,
55
"strict": true,
6-
"noEmit": true,
6+
"noEmit": false,
77
"target": "ES3",
88
"lib": ["ESNext", "DOM"],
99
"jsx": "react",
10-
"rootDir": "./",
10+
"outDir": "./build/ts",
1111
"baseUrl": "./src",
1212
"esModuleInterop": true,
1313
"skipLibCheck": true,
1414
"resolveJsonModule": true,
15-
"sourceMap": true,
1615
"typeRoots": ["../node_modules/@types", "node_modules/@types"],
1716
"paths": {
1817
"@shared/*": ["../../packages/shared/src/*"]
1918
}
2019
},
20+
"include": ["./src"],
21+
"exclude": ["node_modules", "build", "dist"],
2122
"watchOptions": {
2223
"watchFile": "useFsEvents",
2324
"watchDirectory": "useFsEvents",

jest.config.base.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const tsJestPresets = require('ts-jest/presets');
2+
3+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
4+
module.exports = {
5+
...tsJestPresets.jsWithTsESM,
6+
preset: 'ts-jest',
7+
verbose: true,
8+
testEnvironment: 'node',
9+
globals: {
10+
'ts-jest': {
11+
// TS reports strange errors with jest,
12+
// that it doesn't report when running plain tsc...
13+
diagnostics: true,
14+
isolatedModules: true,
15+
useESM: true,
16+
tsconfig: '<rootDir>/tsconfig.json',
17+
},
18+
},
19+
moduleNameMapper: {
20+
'^@shared/(.*)$': '<rootDir>/../packages/shared/src/$1',
21+
'^@taboule/(.*)$': '<rootDir>/../packages/taboule/src/$1',
22+
},
23+
testMatch: [
24+
'**/__tests__/**/*.[jt]s?(x)',
25+
'**/?(*.)+(spec|test|e2e).[tj]s?(x)',
26+
],
27+
moduleDirectories: ['node_modules'],
28+
modulePathIgnorePatterns: ['__mocks__'],
29+
clearMocks: true,
30+
coverageThreshold: {
31+
global: {
32+
branches: 30,
33+
functions: 60,
34+
lines: 60,
35+
statements: 60,
36+
},
37+
},
38+
coveragePathIgnorePatterns: ['node_modules'],
39+
};

jest.config.js

+3-34
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
1-
const { pathsToModuleNameMapper } = require('ts-jest');
2-
3-
const moduleNameMapper = pathsToModuleNameMapper(
4-
{
5-
'@shared/*': ['./shared/src/*'],
6-
},
7-
{
8-
prefix: '<rootDir>',
9-
}
10-
);
1+
const jestBaseConfig = require('./jest.config.base');
112

123
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
134
module.exports = {
14-
preset: 'ts-jest',
15-
testEnvironment: 'node',
16-
roots: ['./', './backend', './guardoni', './YCAI'],
17-
projects: ['./backend', './guardoni', './YCAI'],
18-
modulePathIgnorePatterns: ['__mocks__'],
19-
globals: {
20-
'ts-jest': {
21-
// TS reports strange errors with jest,
22-
// that it doesn't report when running plain tsc...
23-
diagnostics: false,
24-
isolatedModules: true,
25-
},
26-
},
27-
moduleNameMapper,
28-
clearMocks: true,
29-
coverageThreshold: {
30-
global: {
31-
branches: 30,
32-
functions: 60,
33-
lines: 60,
34-
statements: 60,
35-
},
36-
},
37-
coveragePathIgnorePatterns: ['node_modules'],
5+
...jestBaseConfig,
6+
projects: ['<rootDir>/backend', '<rootDir>/guardoni', '<rootDir>/YCAI'],
387
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"prettier": "^2.5.1",
5656
"release-it": "^14.12.4",
5757
"release-it-yarn-workspaces": "^2.0.1",
58-
"ts-jest": "^27.1.2",
58+
"ts-jest": "^27.1.3",
5959
"typescript": "^4.5.4",
6060
"webpack": "^5.67.0"
6161
},

packages/shared/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"eslint-plugin-node": "^11.1.0",
5050
"eslint-plugin-promise": "^5.2.0",
5151
"eslint-plugin-react": "^7.28.0",
52-
"fast-check": "^2.20.0",
52+
"fast-check": "^2.21.0",
5353
"fast-check-io-ts": "^0.5.0",
5454
"filemanager-webpack-plugin": "^6.1.7",
5555
"mini-css-extract-plugin": "^2.4.6",

packages/shared/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4+
"noEmit": false,
45
"composite": true,
56
"lib": ["ESNext", "DOM"],
67
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"],

services/tktrex/shared/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"eslint-plugin-promise": "^5.2.0",
2020
"eslint-plugin-react": "^7.28.0",
2121
"jest": "^27.4.7",
22-
"ts-jest": "^27.1.2",
22+
"ts-jest": "^27.1.3",
2323
"ts-node": "^10.4.0",
2424
"typescript": "^4.5.4",
2525
"yargs": "^17.3.1"

0 commit comments

Comments
 (0)