Skip to content

Commit

Permalink
fix(testing): add eslint ignore comments for jest config properties
Browse files Browse the repository at this point in the history
fixes: #10021
  • Loading branch information
barbados-clemens committed Apr 28, 2022
1 parent b381e38 commit 7ed074d
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,14 @@ describe('nest libraries', function () {
displayName: '${nestlib}',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when --co
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]sx?$': ['@swc/jest', { jsc: { transform: { react: { runtime: 'automatic' } } } }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand All @@ -18,6 +19,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand All @@ -31,6 +33,7 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand All @@ -45,13 +48,15 @@ exports[`jestProject --setup-file should have setupFilesAfterEnv and globals.ts-
preset: '../../jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\\\\\\\.(html|svg)$',
}
},
coverageDirectory: '../../coverage/libs/lib1',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.(ts|mjs|js|html)$': 'jest-preset-angular'
},
transformIgnorePatterns: ['node_modules/(?!.*\\\\\\\\.mjs$)'],
Expand All @@ -69,6 +74,7 @@ exports[`jestProject should create a jest.config.ts 1`] = `
displayName: 'lib1',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
preset: '<%= offsetFromRoot %>jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
Expand All @@ -11,6 +12,7 @@ module.exports = {
testEnvironment: '<%= testEnvironment %>',<% } %>
coverageDirectory: '<%= offsetFromRoot %>coverage/<%= projectRoot %>',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular'
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)']<% if(!skipSerializers) { %>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module.exports = {
preset: '<%= offsetFromRoot %>jest.preset<%= ext %>',<% if(setupFile !== 'none') { %>
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],<% } %><% if (transformer === 'ts-jest') { %>
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},<% } %><% if(testEnvironment) { %>
testEnvironment: '<%= testEnvironment %>',<% } %><% if(skipSerializers){ %>
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
<% if (supportTsx){ %>'^.+\\.[tj]sx?$'<% } else { %>'^.+\\.[tj]s$'<% } %>: <% if (supportTsx && transformer === '@swc/jest') { %>['<%= transformer %>', { jsc: { transform: { react: { runtime: 'automatic' } } } }]<% } else { %>'<%= transformer %>'<% } %>
},
<% if (supportTsx) { %>moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],<% } else { %>moduleFileExtensions: ['ts', 'js', 'html'],<% } %><% } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Jest Migration (v14.0.0) should rename project jest.config.js to jest.config.ts 1`] = `
"module.exports = {
"/* eslint-disable @typescript-eslint/naming-convention */
module.exports = {
displayName: 'lib-one',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
transform: {
'^.+\\\\\\\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand All @@ -19,15 +22,18 @@ exports[`Jest Migration (v14.0.0) should rename project jest.config.js to jest.c
`;

exports[`Jest Migration (v14.0.0) should update jest.config.ts preset to use the jest.preset.ts 1`] = `
"module.exports = {
"/* eslint-disable @typescript-eslint/naming-convention */
module.exports = {
displayName: 'lib-one',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
transform: {
'^.+\\\\\\\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ function updateTsConfig(tree: Tree, tsConfigPath: string) {
}
}

function addEsLintIgnoreComments(tree: Tree, filePath: string) {
if (tree.exists(filePath)) {
const contents = tree.read(filePath, 'utf-8');
tree.write(filePath, `/* eslint-disable @typescript-eslint/naming-convention */
${contents}`);
}
}

function isJestConfigValid(tree: Tree, options: JestExecutorOptions) {
const configExt = extname(options.jestConfig);

Expand Down Expand Up @@ -112,6 +120,7 @@ export async function updateJestConfigExt(tree: Tree) {
}

updateJestPreset(tree, options, projectName);
addEsLintIgnoreComments(tree, options.jestConfig);

const newJestConfigPath = options.jestConfig.replace('.js', '.ts');
tree.rename(options.jestConfig, newJestConfigPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
displayName: '<%= project %>',
preset: '<%= offsetFromRoot %>jest.preset.<%= ext %>',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
2 changes: 2 additions & 0 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@ describe('lib', () => {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ exports[`@nrwl/linter:workspace-rules-project should generate the required files
displayName: 'eslint-rules',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ exports[`lib --testEnvironment should set target jest testEnvironment to jsdom 1
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand All @@ -23,12 +25,14 @@ exports[`lib --testEnvironment should set target jest testEnvironment to node by
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
}
},
testEnvironment: 'node',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ describe('app', () => {
preset: '../../jest.preset.ts',
testEnvironment: 'node',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ describe('lib', () => {
preset: '../../jest.preset.ts',
testEnvironment: 'node',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]sx?$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ describe('app', () => {
preset: '../../jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand All @@ -448,6 +449,7 @@ describe('app', () => {
preset: '../../jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\\\\\\\.[tj]s$': '@swc/jest'
},
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down

0 comments on commit 7ed074d

Please sign in to comment.