fix(testing): use root preset for snapshot config changes first (#15237)
This commit is contained in:
parent
0a8c5db482
commit
8c7a27f3da
@ -1,6 +1,31 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Jest Migration - jest 29 update configs should be idempotent 1`] = `
|
exports[`Jest Migration - jest 29 update configs should NOT update ts-jest with no globals are preset 1`] = `
|
||||||
|
"const nxPreset = require('@nrwl/jest/preset').default;
|
||||||
|
module.exports = {
|
||||||
|
...nxPreset,
|
||||||
|
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\.(ts|js|html)$': 'ts-jest',
|
||||||
|
},
|
||||||
|
resolver: '@nrwl/jest/plugins/resolver',
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageReporters: ['html'],
|
||||||
|
/* TODO: Update to latest Jest snapshotFormat
|
||||||
|
* By default Nx has kept the older style of Jest Snapshot formats
|
||||||
|
* to prevent breaking of any existing tests with snapshots.
|
||||||
|
* It's recommend you update to the latest format.
|
||||||
|
* You can do this by removing snapshotFormat property
|
||||||
|
* and running tests with --update-snapshot flag.
|
||||||
|
* Example: \\"nx affected --targets=test --update-snapshot\\"
|
||||||
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
|
*/
|
||||||
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should add snapshot config with no root preset 1`] = `
|
||||||
"/* eslint-disable */
|
"/* eslint-disable */
|
||||||
export default {
|
export default {
|
||||||
displayName: 'my-lib',
|
displayName: 'my-lib',
|
||||||
@ -19,7 +44,7 @@ coverageDirectory: '../../coverage/libs/my-lib',
|
|||||||
* It's recommend you update to the latest format.
|
* It's recommend you update to the latest format.
|
||||||
* You can do this by removing snapshotFormat property
|
* You can do this by removing snapshotFormat property
|
||||||
* and running tests with --update-snapshot flag.
|
* and running tests with --update-snapshot flag.
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
* Example: From within the project directory, run \\"nx test --update-snapshot\\"
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
*/
|
*/
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
@ -27,7 +52,7 @@ snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Jest Migration - jest 29 update configs should be idempotent 2`] = `
|
exports[`Jest Migration - jest 29 update configs should add snapshot config with no root preset 2`] = `
|
||||||
"module.exports = {
|
"module.exports = {
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||||
@ -50,7 +75,7 @@ preset: '../../jest.preset.js',
|
|||||||
* It's recommend you update to the latest format.
|
* It's recommend you update to the latest format.
|
||||||
* You can do this by removing snapshotFormat property
|
* You can do this by removing snapshotFormat property
|
||||||
* and running tests with --update-snapshot flag.
|
* and running tests with --update-snapshot flag.
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
* Example: From within the project directory, run \\"nx test --update-snapshot\\"
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
*/
|
*/
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
@ -58,6 +83,44 @@ snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should be idempotent 1`] = `
|
||||||
|
"/* eslint-disable */
|
||||||
|
export default {
|
||||||
|
displayName: 'my-lib',
|
||||||
|
preset: '../../jest.preset.js',
|
||||||
|
globals: { },
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||||
|
coverageDirectory: '../../coverage/libs/my-lib'
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should be idempotent 2`] = `
|
||||||
|
"module.exports = {
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
// I am a comment and shouldn't be removed
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||||
|
globals: { something: 'else',
|
||||||
|
abc: [1234, true, {abc: 'yes'}] },
|
||||||
|
/**
|
||||||
|
* Multi-line comment shouldn't be removed
|
||||||
|
*/
|
||||||
|
displayName: 'jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
preset: '../../jest.preset.js'
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Jest Migration - jest 29 update configs should update globalThis.ngJest.teardown to testEnvironmentOptions 1`] = `
|
exports[`Jest Migration - jest 29 update configs should update globalThis.ngJest.teardown to testEnvironmentOptions 1`] = `
|
||||||
"globalThis.ngJest = {
|
"globalThis.ngJest = {
|
||||||
|
|
||||||
@ -75,16 +138,6 @@ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
|||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test jest-preset-angular --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true },
|
|
||||||
testEnvironmentOptions: { teardown: true },
|
testEnvironmentOptions: { teardown: true },
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
@ -112,16 +165,6 @@ testEnvironmentOptions: {
|
|||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test jest-preset-angular --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -137,17 +180,7 @@ transform: {
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||||
coverageDirectory: '../../coverage/libs/my-lib',
|
coverageDirectory: '../../coverage/libs/my-lib'
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
@ -168,14 +201,90 @@ abc: [1234, true, {abc: 'yes'}] },
|
|||||||
*/
|
*/
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js'
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should update root preset 1`] = `
|
||||||
|
"
|
||||||
|
const nxPreset = require('@nrwl/jest/preset').default;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...nxPreset,
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
/* TODO: Update to latest Jest snapshotFormat
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
* By default Nx has kept the older style of Jest Snapshot formats
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
* to prevent breaking of any existing tests with snapshots.
|
||||||
* It's recommend you update to the latest format.
|
* It's recommend you update to the latest format.
|
||||||
* You can do this by removing snapshotFormat property
|
* You can do this by removing snapshotFormat property
|
||||||
* and running tests with --update-snapshot flag.
|
* and running tests with --update-snapshot flag.
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
* Example: \\"nx affected --targets=test --update-snapshot\\"
|
||||||
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
|
*/
|
||||||
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should update root preset 2`] = `
|
||||||
|
"/* eslint-disable */
|
||||||
|
export default {
|
||||||
|
displayName: 'my-lib',
|
||||||
|
preset: '../../jest.preset.js',
|
||||||
|
globals: { },
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||||
|
coverageDirectory: '../../coverage/libs/my-lib'
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should update root preset 3`] = `
|
||||||
|
"module.exports = {
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\\\\\.[tj]sx?$': ['ts-jest', {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
// I am a comment and shouldn't be removed
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
||||||
|
globals: { something: 'else',
|
||||||
|
abc: [1234, true, {abc: 'yes'}] },
|
||||||
|
/**
|
||||||
|
* Multi-line comment shouldn't be removed
|
||||||
|
*/
|
||||||
|
displayName: 'jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
preset: '../../jest.preset.js'
|
||||||
|
};
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Jest Migration - jest 29 update configs should update root preset if ts-jest is preset 1`] = `
|
||||||
|
"const nxPreset = require('@nrwl/jest/preset').default;
|
||||||
|
module.exports = {
|
||||||
|
...nxPreset,
|
||||||
|
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||||
|
globals: { something: 'else',
|
||||||
|
abc: [1234, true, {abc: 'yes'}] },
|
||||||
|
transform: {
|
||||||
|
'^.+\\\\.(ts|js|html)$': ['ts-jest', {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
resolver: '@nrwl/jest/plugins/resolver',
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageReporters: ['html'],
|
||||||
|
/* TODO: Update to latest Jest snapshotFormat
|
||||||
|
* By default Nx has kept the older style of Jest Snapshot formats
|
||||||
|
* to prevent breaking of any existing tests with snapshots.
|
||||||
|
* It's recommend you update to the latest format.
|
||||||
|
* You can do this by removing snapshotFormat property
|
||||||
|
* and running tests with --update-snapshot flag.
|
||||||
|
* Example: \\"nx affected --targets=test --update-snapshot\\"
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
*/
|
*/
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
@ -188,20 +297,10 @@ exports[`Jest Migration - jest 29 update configs should work if not using ts-jes
|
|||||||
transform: {
|
transform: {
|
||||||
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test no-ts-jest --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -210,20 +309,10 @@ exports[`Jest Migration - jest 29 update configs should work if not using ts-jes
|
|||||||
transform: {
|
transform: {
|
||||||
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest',
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test no-ts-jest --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -268,20 +357,10 @@ transform: {
|
|||||||
stringifyContentPathRegex: '\\\\.(html|svg)$',
|
stringifyContentPathRegex: '\\\\.(html|svg)$',
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test jest-preset-angular --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -294,20 +373,10 @@ transform: {
|
|||||||
stringifyContentPathRegex: '\\\\.(html|svg)$',
|
stringifyContentPathRegex: '\\\\.(html|svg)$',
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js',
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test jest-preset-angular --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};"
|
};"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -323,17 +392,7 @@ transform: {
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||||
coverageDirectory: '../../coverage/libs/my-lib',
|
coverageDirectory: '../../coverage/libs/my-lib'
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
@ -354,17 +413,7 @@ abc: [1234, true, {abc: 'yes'}] },
|
|||||||
*/
|
*/
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js'
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test my-lib --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
@ -381,17 +430,7 @@ transform: {
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||||
coverageDirectory: '../../coverage/libs/another-lib',
|
coverageDirectory: '../../coverage/libs/another-lib'
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test another-lib --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
@ -412,17 +451,7 @@ abc: [1234, true, {abc: 'yes'}] },
|
|||||||
*/
|
*/
|
||||||
displayName: 'jest',
|
displayName: 'jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
preset: '../../jest.preset.js',
|
preset: '../../jest.preset.js'
|
||||||
/* TODO: Update to latest Jest snapshotFormat
|
|
||||||
* By default Nx has kept the older style of Jest Snapshot formats
|
|
||||||
* to prevent breaking of any existing tests with snapshots.
|
|
||||||
* It's recommend you update to the latest format.
|
|
||||||
* You can do this by removing snapshotFormat property
|
|
||||||
* and running tests with --update-snapshot flag.
|
|
||||||
* Example: \\"nx test another-lib --update-snapshot\\"
|
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
|
||||||
*/
|
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|
||||||
};
|
};
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -35,6 +35,86 @@ describe('Jest Migration - jest 29 update configs', () => {
|
|||||||
expect(actualJestConfigJs).toMatchSnapshot();
|
expect(actualJestConfigJs).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update root preset', async () => {
|
||||||
|
await setup(tree, 'my-lib');
|
||||||
|
await updateConfigsJest29(tree);
|
||||||
|
|
||||||
|
const actualPreset = tree.read('jest.preset.js', 'utf-8');
|
||||||
|
expect(actualPreset).toMatchSnapshot();
|
||||||
|
const actualJestConfigTs = tree.read('libs/my-lib/jest.config.ts', 'utf-8');
|
||||||
|
expect(actualJestConfigTs).toMatchSnapshot();
|
||||||
|
const actualJestConfigJs = tree.read('libs/my-lib/jest.config.js', 'utf-8');
|
||||||
|
expect(actualJestConfigJs).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update root preset if ts-jest is preset', async () => {
|
||||||
|
await setup(tree, 'my-lib');
|
||||||
|
tree.write(
|
||||||
|
'jest.preset.js',
|
||||||
|
`const nxPreset = require('@nrwl/jest/preset').default;
|
||||||
|
module.exports = {
|
||||||
|
...nxPreset,
|
||||||
|
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||||
|
globals: {
|
||||||
|
'ts-jest': {
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json'
|
||||||
|
},
|
||||||
|
something: 'else',
|
||||||
|
abc: [1234, true, {abc: 'yes'}]
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(ts|js|html)$': 'ts-jest',
|
||||||
|
},
|
||||||
|
resolver: '@nrwl/jest/plugins/resolver',
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageReporters: ['html'],
|
||||||
|
};
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateConfigsJest29(tree);
|
||||||
|
|
||||||
|
const actualPreset = tree.read('jest.preset.js', 'utf-8');
|
||||||
|
expect(actualPreset).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT update ts-jest with no globals are preset', async () => {
|
||||||
|
await setup(tree, 'my-lib');
|
||||||
|
tree.write(
|
||||||
|
'jest.preset.js',
|
||||||
|
`const nxPreset = require('@nrwl/jest/preset').default;
|
||||||
|
module.exports = {
|
||||||
|
...nxPreset,
|
||||||
|
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(ts|js|html)$': 'ts-jest',
|
||||||
|
},
|
||||||
|
resolver: '@nrwl/jest/plugins/resolver',
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageReporters: ['html'],
|
||||||
|
};
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateConfigsJest29(tree);
|
||||||
|
|
||||||
|
const actualPreset = tree.read('jest.preset.js', 'utf-8');
|
||||||
|
expect(actualPreset).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add snapshot config with no root preset', async () => {
|
||||||
|
await setup(tree, 'my-lib');
|
||||||
|
|
||||||
|
tree.delete('jest.preset.js');
|
||||||
|
|
||||||
|
await updateConfigsJest29(tree);
|
||||||
|
|
||||||
|
const actualJestConfigTs = tree.read('libs/my-lib/jest.config.ts', 'utf-8');
|
||||||
|
expect(actualJestConfigTs).toMatchSnapshot();
|
||||||
|
const actualJestConfigJs = tree.read('libs/my-lib/jest.config.js', 'utf-8');
|
||||||
|
expect(actualJestConfigJs).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
it('should work with multiple projects + configs', async () => {
|
it('should work with multiple projects + configs', async () => {
|
||||||
await setup(tree, 'my-lib');
|
await setup(tree, 'my-lib');
|
||||||
await setup(tree, 'another-lib', projectGraph);
|
await setup(tree, 'another-lib', projectGraph);
|
||||||
|
|||||||
@ -10,8 +10,11 @@ import { tsquery } from '@phenomnomnominal/tsquery';
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { JestExecutorOptions } from '../../executors/jest/schema';
|
import { JestExecutorOptions } from '../../executors/jest/schema';
|
||||||
import { forEachExecutorOptionsInGraph } from '@nrwl/workspace/src/utilities/executor-options-utils';
|
import { forEachExecutorOptionsInGraph } from '@nrwl/workspace/src/utilities/executor-options-utils';
|
||||||
|
import { findRootJestPreset } from '../../utils/config/find-root-jest-files';
|
||||||
|
|
||||||
export async function updateConfigsJest29(tree: Tree) {
|
export async function updateConfigsJest29(tree: Tree) {
|
||||||
|
const rootPreset = findRootJestPreset(tree);
|
||||||
|
const targetsWithJest = new Set<string>();
|
||||||
// have to use graph so the negative configuration targets are expanded
|
// have to use graph so the negative configuration targets are expanded
|
||||||
const graph = await createProjectGraphAsync();
|
const graph = await createProjectGraphAsync();
|
||||||
forEachExecutorOptionsInGraph<JestExecutorOptions>(
|
forEachExecutorOptionsInGraph<JestExecutorOptions>(
|
||||||
@ -19,18 +22,31 @@ export async function updateConfigsJest29(tree: Tree) {
|
|||||||
'@nrwl/jest:jest',
|
'@nrwl/jest:jest',
|
||||||
(options, projectName, targetName) => {
|
(options, projectName, targetName) => {
|
||||||
if (options.jestConfig && tree.exists(options.jestConfig)) {
|
if (options.jestConfig && tree.exists(options.jestConfig)) {
|
||||||
|
targetsWithJest.add(targetName);
|
||||||
|
// if the default root preset exists or if the project doesn't have a 'preset' configured
|
||||||
|
// -> update snapshot config
|
||||||
|
if (!rootPreset || !hasPresetConfigured(tree, options.jestConfig)) {
|
||||||
addSnapshotOptionsToConfig(
|
addSnapshotOptionsToConfig(
|
||||||
tree,
|
tree,
|
||||||
options.jestConfig,
|
options.jestConfig,
|
||||||
projectName,
|
`From within the project directory, run "nx test --update-snapshot"`
|
||||||
targetName
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
updateTsJestOptions(tree, options.jestConfig);
|
updateTsJestOptions(tree, options.jestConfig);
|
||||||
updateNgJestOptions(tree, options.jestConfig);
|
updateNgJestOptions(tree, options.jestConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (rootPreset && tree.exists(rootPreset)) {
|
||||||
|
const cmd = `"nx affected --targets=${Array.from(targetsWithJest).join(
|
||||||
|
','
|
||||||
|
)} --update-snapshot"`;
|
||||||
|
addSnapshotOptionsToConfig(tree, rootPreset, cmd);
|
||||||
|
updateTsJestOptions(tree, rootPreset);
|
||||||
|
updateNgJestOptions(tree, rootPreset);
|
||||||
|
}
|
||||||
|
|
||||||
await formatFiles(tree);
|
await formatFiles(tree);
|
||||||
logger.info(stripIndents`NX Jest Snapshot format changed in v29.
|
logger.info(stripIndents`NX Jest Snapshot format changed in v29.
|
||||||
By default Nx kept the older style to prevent breaking of existing tests with snapshots.
|
By default Nx kept the older style to prevent breaking of existing tests with snapshots.
|
||||||
@ -43,8 +59,7 @@ More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format`);
|
|||||||
function addSnapshotOptionsToConfig(
|
function addSnapshotOptionsToConfig(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
configPath: string,
|
configPath: string,
|
||||||
projectName: string,
|
updateSnapshotExample: string
|
||||||
targetName: string
|
|
||||||
) {
|
) {
|
||||||
const config = tree.read(configPath, 'utf-8');
|
const config = tree.read(configPath, 'utf-8');
|
||||||
const hasSnapshotOptions = tsquery.query(
|
const hasSnapshotOptions = tsquery.query(
|
||||||
@ -66,7 +81,7 @@ ${node.properties.map((p) => getNodeWithComments(config, p)).join(',\n')},
|
|||||||
* It's recommend you update to the latest format.
|
* It's recommend you update to the latest format.
|
||||||
* You can do this by removing snapshotFormat property
|
* You can do this by removing snapshotFormat property
|
||||||
* and running tests with --update-snapshot flag.
|
* and running tests with --update-snapshot flag.
|
||||||
* Example: "nx ${targetName} ${projectName} --update-snapshot"
|
* Example: ${updateSnapshotExample}
|
||||||
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
* More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
|
||||||
*/
|
*/
|
||||||
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
||||||
@ -78,6 +93,17 @@ snapshotFormat: { escapeString: true, printBasicPrototype: true }
|
|||||||
tree.write(configPath, updatedConfig);
|
tree.write(configPath, updatedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasPresetConfigured(tree: Tree, configPath: string): boolean {
|
||||||
|
const contents = tree.read(configPath, 'utf-8');
|
||||||
|
|
||||||
|
return (
|
||||||
|
tsquery.query(
|
||||||
|
contents,
|
||||||
|
`${TS_QUERY_JEST_CONFIG_PREFIX} > ObjectLiteralExpression PropertyAssignment:has(Identifier[name="preset"])`
|
||||||
|
)?.length > 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function updateTsJestOptions(tree: Tree, configPath: string) {
|
function updateTsJestOptions(tree: Tree, configPath: string) {
|
||||||
// query for the globals property, if they don't have one then there's nothing to modify.
|
// query for the globals property, if they don't have one then there's nothing to modify.
|
||||||
const contents = tree.read(configPath, 'utf-8');
|
const contents = tree.read(configPath, 'utf-8');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user