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 29, 2022
1 parent 9254998 commit 754a05e
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 22 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
@@ -1,7 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`jestProject --babelJest should generate proper jest.transform when --compiler=swc and supportTsx is true 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
Expand All @@ -14,7 +15,8 @@ exports[`jestProject --babelJest should generate proper jest.transform when --co
`;

exports[`jestProject --babelJest should generate proper jest.transform when babelJest and supportTsx is true 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
Expand All @@ -27,7 +29,8 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe
`;

exports[`jestProject --babelJest should generate proper jest.transform when babelJest is true 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'lib1',
preset: '../../jest.preset.ts',
transform: {
Expand All @@ -40,18 +43,21 @@ exports[`jestProject --babelJest should generate proper jest.transform when babe
`;

exports[`jestProject --setup-file should have setupFilesAfterEnv and globals.ts-jest in the jest.config when generated for angular 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'lib1',
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 @@ -65,7 +71,8 @@ exports[`jestProject --setup-file should have setupFilesAfterEnv and globals.ts-
`;

exports[`jestProject should create a jest.config.ts 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'lib1',
preset: '../../jest.preset.ts',
globals: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable */
module.exports = {
displayName: '<%= project %>',
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 +13,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
@@ -1,3 +1,4 @@
/* eslint-disable */
module.exports = {
displayName: '<%= project %>',
preset: '<%= offsetFromRoot %>jest.preset<%= ext %>',<% if(setupFile !== 'none') { %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
readProjectConfiguration,
Tree,
} from '@nrwl/devkit';
import { findRootJestPreset } from '../../../utils/config/find-root-jest-files';
import {
findRootJestConfig,
findRootJestPreset,
} from '../../../utils/config/find-root-jest-files';
import { join } from 'path';
import { JestProjectSchema } from '../schema';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 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 */
/* eslint-disable */
module.exports = {
displayName: 'lib-one',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
Expand All @@ -13,15 +15,17 @@ exports[`Jest Migration (v14.0.0) should rename project jest.config.js to jest.c
'^.+\\\\\\\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/lib-one',\\"preset\\": \\"../../jest.preset.ts\\"
coverageDirectory: '../../coverage/libs/lib-one'
};
"
`;

exports[`Jest Migration (v14.0.0) should update jest.config.ts preset to use the jest.preset.ts 1`] = `
"module.exports = {
"/* eslint-disable */
/* eslint-disable */
module.exports = {
displayName: 'lib-one',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
Expand All @@ -31,7 +35,7 @@ exports[`Jest Migration (v14.0.0) should update jest.config.ts preset to use the
'^.+\\\\\\\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/lib-one',\\"preset\\": \\"../../jest.preset.ts\\"
coverageDirectory: '../../coverage/libs/lib-one'
};
"
`;
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
@@ -1,3 +1,4 @@
/* eslint-disable */
const fs = require('fs');

// Reading the SWC compilation config and remove the "exclude"
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ describe('lib', () => {
expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy();
expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ exports[`@nrwl/linter:workspace-rules-project should generate the required files
`;

exports[`@nrwl/linter:workspace-rules-project should generate the required files 5`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'eslint-rules',
preset: '../../jest.preset.ts',
globals: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib --testEnvironment should set target jest testEnvironment to jsdom 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
Expand All @@ -19,7 +20,8 @@ exports[`lib --testEnvironment should set target jest testEnvironment to jsdom 1
`;

exports[`lib --testEnvironment should set target jest testEnvironment to node by default 1`] = `
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ describe('app', () => {

expect(tree.read(`apps/my-node-app/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-node-app',
preset: '../../jest.preset.ts',
testEnvironment: 'node',
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ describe('lib', () => {

expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
testEnvironment: 'node',
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ describe('app', () => {

expect(tree.read(`apps/my-app/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-app',
preset: '../../jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
Expand All @@ -443,7 +444,8 @@ describe('app', () => {

expect(tree.read(`apps/my-app/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-app',
preset: '../../jest.preset.ts',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
Expand Down
6 changes: 4 additions & 2 deletions packages/workspace/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ describe('lib', () => {
expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy();
expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
globals: {
Expand Down Expand Up @@ -829,7 +830,8 @@ describe('lib', () => {

expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
"/* eslint-disable */
module.exports = {
displayName: 'my-lib',
preset: '../../jest.preset.ts',
transform: {
Expand Down

0 comments on commit 754a05e

Please sign in to comment.