From 5fe277ee02a77b1ce3a3d58f19e526a3b2f884e7 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Thu, 13 May 2021 07:29:02 -0400 Subject: [PATCH] remove duplication of all jest configs (#3375) * use jest-preset for all but app * separate properties that are the same as the preset for some reason, it doesn't work. you get: ``` Preset ../../jest-preset.js not found. ``` This needs to be investigated. * removes unused/unneeded npm script in `app`, `test:jest` --- jest.config.js => jest-preset.js | 14 +++------ packages/insomnia-app/jest.config.js | 34 +++++++++------------ packages/insomnia-app/package.json | 3 +- packages/insomnia-components/jest.config.js | 19 ++---------- packages/insomnia-cookies/jest.config.js | 15 +-------- packages/insomnia-importers/jest.config.js | 15 +-------- packages/insomnia-inso/jest.config.js | 26 ++-------------- packages/insomnia-prettify/jest.config.js | 15 +-------- packages/insomnia-testing/jest.config.js | 18 +---------- packages/insomnia-url/jest.config.js | 15 +-------- packages/insomnia-xpath/jest.config.js | 15 +-------- packages/openapi-2-kong/jest.config.js | 17 +---------- tsconfig.eslint.json | 2 +- 13 files changed, 33 insertions(+), 175 deletions(-) rename jest.config.js => jest-preset.js (78%) diff --git a/jest.config.js b/jest-preset.js similarity index 78% rename from jest.config.js rename to jest-preset.js index 31aa926f2..190612e11 100644 --- a/jest.config.js +++ b/jest-preset.js @@ -1,20 +1,16 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { + collectCoverage: false, globals: { 'ts-jest': { isolatedModules: true, }, }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testMatch: [ - '**/*.test.ts', - ], - verbose: false, resetMocks: true, resetModules: true, - collectCoverage: false, + testEnvironment: 'node', + testRegex: ['.+\\.test\\.tsx?$'], + transform: { '^.+\\.tsx?$': 'ts-jest' }, + verbose: false, }; diff --git a/packages/insomnia-app/jest.config.js b/packages/insomnia-app/jest.config.js index 0a5900f4e..172fae660 100644 --- a/packages/insomnia-app/jest.config.js +++ b/packages/insomnia-app/jest.config.js @@ -1,35 +1,29 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { + // preset: '../../jest-preset.js', // DOES NOT WORK + // same as preset: + collectCoverage: false, globals: { 'ts-jest': { isolatedModules: true, }, }, - testEnvironment: 'jsdom', - cache: false, - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - verbose: true, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], resetMocks: true, resetModules: true, testRegex: ['.+\\.test\\.tsx?$'], - collectCoverage: false, - collectCoverageFrom: ['app/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], - setupFiles: [ - './__jest__/setup.ts', - ], - setupFilesAfterEnv: [ - './__jest__/setup-after-env.ts', - ], + transform: { '^.+\\.tsx?$': 'ts-jest' }, + + // extended from preset: + cache: false, + modulePathIgnorePatterns: ['/network/.*/__mocks__'], + rootDir: 'app', + setupFiles: ['./__jest__/setup.ts'], + setupFilesAfterEnv: ['./__jest__/setup-after-env.ts'], + testEnvironment: 'jsdom', + verbose: true, moduleNameMapper: { '\\.(css|less|png)$': '/__mocks__/dummy.ts', '^worker-loader!': '/__mocks__/dummy.ts', }, - modulePathIgnorePatterns: [ - '/network/.*/__mocks__', - ], - rootDir: 'app', }; diff --git a/packages/insomnia-app/package.json b/packages/insomnia-app/package.json index b51c6218c..2addd6659 100644 --- a/packages/insomnia-app/package.json +++ b/packages/insomnia-app/package.json @@ -9,8 +9,7 @@ "main": "app/main.min.js", "scripts": { "clean": "tsc --build tsconfig.webpack.json --clean && tsc --build tsconfig.build.json --clean", - "test": "npm run test:jest", - "test:jest": "cross-env NODE_ENV=test jest --silent", + "test": "jest", "test-appveyor": "npm run test -- --maxWorkers 1", "start:electron": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" cross-env NODE_ENV=development webpack --config webpack/webpack.config.electron.ts && electron .", "start:dev-server": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack-dev-server --config webpack/webpack.config.development.ts", diff --git a/packages/insomnia-components/jest.config.js b/packages/insomnia-components/jest.config.js index 340144740..a5813cb05 100644 --- a/packages/insomnia-components/jest.config.js +++ b/packages/insomnia-components/jest.config.js @@ -1,21 +1,6 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'jsdom', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, + preset: '../../jest-preset.js', setupFilesAfterEnv: ['./src/jest/setup-after-env.ts'], - verbose: false, - resetMocks: true, - resetModules: true, - testRegex: ['.+\\.test\\.tsx?$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + testEnvironment: 'jsdom', }; diff --git a/packages/insomnia-cookies/jest.config.js b/packages/insomnia-cookies/jest.config.js index 537ce057d..0f631282e 100644 --- a/packages/insomnia-cookies/jest.config.js +++ b/packages/insomnia-cookies/jest.config.js @@ -1,17 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/packages/insomnia-importers/jest.config.js b/packages/insomnia-importers/jest.config.js index 537ce057d..0f631282e 100644 --- a/packages/insomnia-importers/jest.config.js +++ b/packages/insomnia-importers/jest.config.js @@ -1,17 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/packages/insomnia-inso/jest.config.js b/packages/insomnia-inso/jest.config.js index dd1cda985..b07257993 100644 --- a/packages/insomnia-inso/jest.config.js +++ b/packages/insomnia-inso/jest.config.js @@ -1,29 +1,8 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testMatch: [ - '**/*.test.ts', - ], - verbose: false, - resetMocks: true, - resetModules: true, - - setupFiles: [ - './src/jest/setup.ts', - ], + preset: '../../jest-preset.js', collectCoverage: true, - coveragePathIgnorePatterns: [ - '/node_modules/', - ], + coveragePathIgnorePatterns: ['/node_modules/'], coverageThreshold: { global: { branches: 88, @@ -32,4 +11,5 @@ module.exports = { statements: 95, }, }, + setupFiles: ['./src/jest/setup.ts'], }; diff --git a/packages/insomnia-prettify/jest.config.js b/packages/insomnia-prettify/jest.config.js index 537ce057d..0f631282e 100644 --- a/packages/insomnia-prettify/jest.config.js +++ b/packages/insomnia-prettify/jest.config.js @@ -1,17 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/packages/insomnia-testing/jest.config.js b/packages/insomnia-testing/jest.config.js index 31aa926f2..0f631282e 100644 --- a/packages/insomnia-testing/jest.config.js +++ b/packages/insomnia-testing/jest.config.js @@ -1,20 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testMatch: [ - '**/*.test.ts', - ], - verbose: false, - resetMocks: true, - resetModules: true, - collectCoverage: false, + preset: '../../jest-preset.js', }; diff --git a/packages/insomnia-url/jest.config.js b/packages/insomnia-url/jest.config.js index 537ce057d..0f631282e 100644 --- a/packages/insomnia-url/jest.config.js +++ b/packages/insomnia-url/jest.config.js @@ -1,17 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/packages/insomnia-xpath/jest.config.js b/packages/insomnia-xpath/jest.config.js index 537ce057d..0f631282e 100644 --- a/packages/insomnia-xpath/jest.config.js +++ b/packages/insomnia-xpath/jest.config.js @@ -1,17 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/packages/openapi-2-kong/jest.config.js b/packages/openapi-2-kong/jest.config.js index a96ee5410..0f631282e 100644 --- a/packages/openapi-2-kong/jest.config.js +++ b/packages/openapi-2-kong/jest.config.js @@ -1,19 +1,4 @@ /** @type { import('@jest/types').Config.InitialOptions } */ module.exports = { - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: ['.+\\.test\\.ts$'], - collectCoverage: false, - resetMocks: true, - resetModules: true, - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - coverageReporters: ['text-summary', 'lcov'], + preset: '../../jest-preset.js', }; diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 9d94533a3..f1ffc6415 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -2,6 +2,6 @@ "extends": "./tsconfig.base.json", "include": [ ".eslintrc.js", - "jest.config.js" + "jest-preset.js" ] } \ No newline at end of file