-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest): use babel-jest by default for all code
- Loading branch information
Showing
9 changed files
with
73 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'arui-scripts': major | ||
--- | ||
|
||
Теперь по умолчанию jest будет использовать babel для преобразования ts-кода. Если по какой-то причине это | ||
вас не устраивает - вы можете использовать настройку `jestUseTsJest`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,5 @@ | ||
module.exports = { | ||
testRegex: 'src/.*(test|spec|/__test__/|/__tests__/).*\\.(jsx?|tsx?)$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
collectCoverageFrom: [ | ||
'src/**/*.{js,jsx,ts,tsx}' | ||
], | ||
testURL: 'http://localhost', | ||
transform: { | ||
'^.+\\.jsx?$': require.resolve('./build/configs/jest/babel-transform'), | ||
'^.+\\.tsx?$': require.resolve('ts-jest'), | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': require.resolve('./build/configs/jest/file-transform') | ||
}, | ||
moduleNameMapper: { | ||
'\\.css$': require.resolve('./build/configs/jest/css-mock') | ||
}, | ||
snapshotSerializers: [ | ||
require.resolve('jest-snapshot-serializer-class-name-to-string') | ||
] | ||
} | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
const settings = require('./build/configs/jest/settings').default; | ||
|
||
module.exports = settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
// Мы используем эти настройки сразу в двух местах - в jest-presets и в настройках jest-а, которые мы загружаем в самих скриптах | ||
// jest-presets могут использоваться внешними утилитами, которые используют разработчики, настройки в скриптах | ||
// используются при запуске `arui-scripts test`. Посколько в jest жестко зафиксировано где именно должен лежать файл с пресетами | ||
// нам приходится отвязывать его от основного кода скриптов | ||
const fs = require('fs'); | ||
const { pathsToModuleNameMapper } = require('ts-jest'); | ||
const { parseConfigFileTextToJson } = require('typescript'); | ||
|
||
const configs = require('../app-configs').default; | ||
|
||
let tsConfigPaths = {}; | ||
|
||
if (configs.tsconfig) { | ||
const tsConfigText = fs.readFileSync(configs.tsconfig, 'utf8'); | ||
const tsConfig = parseConfigFileTextToJson(configs.tsconfig, tsConfigText); | ||
|
||
tsConfigPaths = tsConfig.config.compilerOptions.paths || {}; | ||
} | ||
|
||
module.exports = { | ||
testRegex: 'src/.*(((/__test__/|/__tests__/).*)|(test|spec|tests)).(jsx?|tsx?)$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], | ||
testEnvironmentOptions: { | ||
url: 'http://localhost', | ||
}, | ||
transform: { | ||
'^.+\\.jsx?$': require.resolve('./babel-transform'), | ||
'^.+\\.tsx?$': configs.jestUseTsJest | ||
? require.resolve('ts-jest') | ||
: require.resolve('./babel-transform'), | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': require.resolve('./file-transform') | ||
}, | ||
moduleNameMapper: { | ||
// replace all css files with simple empty exports | ||
'\\.css$': require.resolve('./css-mock'), | ||
...pathsToModuleNameMapper(tsConfigPaths, { prefix: '<rootDir>/' }), | ||
}, | ||
snapshotSerializers: [ | ||
require.resolve('jest-snapshot-serializer-class-name-to-string') | ||
], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: configs.tsconfig, | ||
}, | ||
}, | ||
}; |