Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated Jest (latest v27.x) and require React ^17.0.2 #22

Merged
merged 4 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/natterstefan/jest-preset-ns.git"
"url": "https://github.com/natterstefan/jest-preset-ns.git"
},
"bugs": {
"url": "https://github.com/natterstefan/jest-preset-ns/issues"
Expand All @@ -40,14 +40,14 @@
"eslint-config-prettier": "6.11.0",
"eslint-import-resolver-lerna": "1.1.1",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-jest": "23.13.1",
"eslint-plugin-jest": "24.4.0",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.3",
"eslint-plugin-react": "7.20.0",
"eslint-plugin-react-hooks": "4.2.0",
"husky": "7.0.1",
"is-ci": "3.0.0",
"jest": "26.0.1",
"jest": "27.0.6",
"lerna": "4.0.0",
"lint-staged": "11.1.1",
"prettier": "2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/example-app-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "Apache2.0",
"dependencies": {
"enzyme": "^3.11.0",
"jest": "^26.0.1",
"jest": "^27.0.6",
"jest-preset-ns": "^0.2.0",
"react": "^17.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "Apache2.0",
"dependencies": {
"enzyme": "^3.11.0",
"jest": "^26.0.1",
"jest": "^27.0.6",
"jest-preset-ns": "^0.2.0"
}
}
16 changes: 13 additions & 3 deletions packages/jest-preset-ns/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('jest-preset-ns', () => {
cache: expect.any(Boolean),
cacheDirectory: expect.any(String),
changedFilesWithAncestor: false,
ci: expect.any(Boolean),
clearMocks: false,
collectCoverage: false,
collectCoverageFrom: [
Expand All @@ -21,18 +22,25 @@ describe('jest-preset-ns', () => {
coveragePathIgnorePatterns: ['/node_modules/'],
coverageProvider: 'babel',
coverageReporters: ['json', 'text', 'lcov', 'clover'],
detectLeaks: false,
detectOpenHandles: false,
errorOnDeprecated: false,
expand: false,
extensionsToTreatAsEsm: expect.any(Array),
forceCoverageMatch: [],
globals: {},
haste: {
computeSha1: false,
enableSymlinks: false,
forceNodeFilesystemAPI: false,
throwOnModuleCollision: false,
},
injectGlobals: true,
listTests: false,
maxConcurrency: 5,
maxWorkers: '50%',
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
moduleNameMapper: {
'^.+\\.(png|gif|jpe?g|webp|html|svg|((o|t)tf)|woff2?|ico)$': expect.stringContaining(
'mocks/file.js',
Expand All @@ -42,6 +50,7 @@ describe('jest-preset-ns', () => {
noStackTrace: false,
notify: false,
notifyMode: 'failure-change',
passWithNoTests: false,
prettierPath: 'prettier',
resetMocks: false,
resetModules: false,
Expand All @@ -52,6 +61,7 @@ describe('jest-preset-ns', () => {
setupFiles: ['regenerator-runtime/runtime', 'jest-date-mock'],
setupFilesAfterEnv: [],
skipFilter: false,
slowTestThreshold: 5,
snapshotSerializers: [],
testEnvironment: 'node',
testEnvironmentOptions: {},
Expand All @@ -67,15 +77,15 @@ describe('jest-preset-ns', () => {
'<rootDir>/(build|dist|es|esm|lib|node_modules|tmp)/',
],
testRegex: [],
testRunner: 'jasmine2',
testRunner: 'jest-circus/runner',
testSequencer: '@jest/test-sequencer',
testURL: 'http://localhost',
timers: 'real',
transform: {
'^.+\\.(js|jsx|mjs)$': expect.stringContaining('transforms/babel.js'),
'^.+\\.(ts|tsx)$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/'],
transformIgnorePatterns: ['/node_modules/', '\\.pnp\\.[^\\/]+$'],
useStderr: false,
watch: false,
watchPathIgnorePatterns: [],
Expand Down
28 changes: 25 additions & 3 deletions packages/jest-preset-ns/lib/configs/create-jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,34 @@
*
* partially inspired by
* @see https://github.com/americanexpress/amex-jest-preset/blob/v6.0.0/jest-preset.js
* @see https://github.com/xing/hops/blob/4cfaba925984ea89ce520a3ddc9ea9810b10721b/packages/jest-preset/jest-preset.js
*/
const isCI = require('is-ci')
const { defaults } = require('jest-config')
const semver = require('semver')
const colors = require('colors')
const merge = require('lodash.merge')
const importFrom = require('import-from')
const jestVersion = require('jest/package.json').version

const config = merge({}, defaults, {
// returns undefined instead of throwing when the module can't be found.
const jestConfig = importFrom.silent(require.resolve('jest'), 'jest-config')

if (!jestConfig) {
throw new Error(
colors.red('Could not initialize jest-preset-ns. jest-config is missing.'),
)
}

if (semver.lt(jestVersion, '27.0.0')) {
// eslint-disable-next-line no-console
console.log(
colors.red(
'Error: You are using an unsupported version of Jest! Please upgrade to Jest v27.',
),
)
}

const config = merge({}, jestConfig.defaults, {
cache: !isCI,
// useful as it eliminates issues caused by several projects sharing the same Jest cache on CI builds
cacheDirectory: '<rootDir>/.jest-cache',
Expand All @@ -33,7 +55,7 @@ const config = merge({}, defaults, {
// @see https://github.com/americanexpress/amex-jest-preset
testEnvironment: 'node',
testMatch: [
...defaults.testMatch,
...jestConfig.defaults.testMatch,
// add typescript support
'**/__tests__/**/*.[jt]s(x)?',
'**/?(*.)+(spec|test).[jt]s(x)?',
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-preset-ns/lib/configs/react/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* TODO:
* - add: testEnvironment: 'jest-environment-jsdom-global',
*/
const createPreset = require('../create-jest-preset')

const config = createPreset({
Expand All @@ -22,6 +18,7 @@ const config = createPreset({
* setupFilesAfterEnv: ['jest-preset-ns/presets/react/jest-setup.js'],
*/
setupFilesAfterEnv: [require.resolve('../../../presets/react/jest-setup.js')],
// TODO: use testEnvironment: 'jest-environment-jsdom-global' instead?
testEnvironment: 'jest-environment-jsdom',
})

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset-ns/lib/transforms/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
const { dirname } = require('path')

const babelJest = require('babel-jest')
const babelJest = require('babel-jest').default

module.exports = babelJest.createTransformer({
presets: [
Expand Down
14 changes: 8 additions & 6 deletions packages/jest-preset-ns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,29 @@
},
"homepage": "https://github.com/natterstefan/jest-preset-ns#readme",
"peerDependencies": {
"jest": "^26.0.1",
"jest": "^27.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"dependencies": {
"@babel/core": "^7.14.8",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/preset-env": "^7.14.8",
"@babel/preset-env": "^7.14.9",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"babel-jest": "^26.0.1",
"core-js": "^3.15.2",
"babel-jest": "^27.0.6",
"colors": "^1.4.0",
"core-js": "^3.16.0",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"identity-obj-proxy": "^3.0.0",
"import-from": "^4.0.0",
"is-ci": "^3.0.0",
"jest-config": "^26.0.1",
"jest-date-mock": "^1.0.8",
"lodash.merge": "^4.6.2",
"regenerator-runtime": "^0.13.9",
"ts-jest": "^26.0.0"
"semver": "^7.3.5",
"ts-jest": "^27.0.4"
}
}
Loading