Skip to content

Commit

Permalink
fix(react-native): update generated jest config coverage dir (#18366)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored Jul 28, 2023
1 parent 6afe0a7 commit dbd61b5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ describe('app', () => {
expect(tsconfig.extends).toEqual('../../tsconfig.base.json');

expect(appTree.exists('apps/my-app/.eslintrc.json')).toBe(true);
expect(appTree.read('apps/my-app/jest.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
displayName: 'my-app',
preset: 'react-native',
resolver: '@nx/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
moduleNameMapper: {
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
},
coverageDirectory: '../../coverage/apps/my-app',
};
"
`);
});

it('should generate targets', async () => {
Expand All @@ -71,7 +86,6 @@ describe('app', () => {
install: false,
});
const targets = readProjectConfiguration(appTree, 'my-app').targets;
console.log(targets.test);
expect(targets.test).toBeDefined();
});

Expand Down
66 changes: 66 additions & 0 deletions packages/react-native/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,72 @@ describe('lib', () => {
outputs: ['{options.outputFile}'],
});
});

it('should generate test configuration', async () => {
await libraryGenerator(appTree, {
...defaultSchema,
unitTestRunner: 'jest',
});

expect(appTree.read('libs/my-lib/tsconfig.spec.json', 'utf-8'))
.toMatchInlineSnapshot(`
"{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
"
`);
expect(appTree.read('libs/my-lib/jest.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
displayName: 'my-lib',
preset: 'react-native',
resolver: '@nx/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
moduleNameMapper: {
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
},
coverageDirectory: '../../coverage/libs/my-lib',
};
"
`);
const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
expect(projectConfiguration.targets.test).toMatchInlineSnapshot(`
{
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true,
},
},
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "libs/my-lib/jest.config.ts",
"passWithNoTests": true,
},
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}",
],
}
`);
});
});

describe('--buildable', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/react-native/src/utils/add-jest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from '@nx/devkit';
import { Tree, offsetFromRoot } from '@nx/devkit';
import { configurationGenerator } from '@nx/jest';

export async function addJest(
Expand Down Expand Up @@ -34,7 +34,10 @@ export async function addJest(
setupFilesAfterEnv: ['<rootDir>/test-setup.${js ? 'js' : 'ts'}'],
moduleNameMapper: {
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock'
}
},
coverageDirectory: '${offsetFromRoot(
appProjectRoot
)}coverage/${appProjectRoot}'
};`;
host.write(configPath, content);

Expand Down

1 comment on commit dbd61b5

@vercel
Copy link

@vercel vercel bot commented on dbd61b5 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.