fix(react-native): update generated jest config coverage dir (#18366)
This commit is contained in:
parent
6afe0a7c20
commit
dbd61b5d9a
@ -60,6 +60,21 @@ describe('app', () => {
|
|||||||
expect(tsconfig.extends).toEqual('../../tsconfig.base.json');
|
expect(tsconfig.extends).toEqual('../../tsconfig.base.json');
|
||||||
|
|
||||||
expect(appTree.exists('apps/my-app/.eslintrc.json')).toBe(true);
|
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 () => {
|
it('should generate targets', async () => {
|
||||||
@ -71,7 +86,6 @@ describe('app', () => {
|
|||||||
install: false,
|
install: false,
|
||||||
});
|
});
|
||||||
const targets = readProjectConfiguration(appTree, 'my-app').targets;
|
const targets = readProjectConfiguration(appTree, 'my-app').targets;
|
||||||
console.log(targets.test);
|
|
||||||
expect(targets.test).toBeDefined();
|
expect(targets.test).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -242,6 +242,72 @@ describe('lib', () => {
|
|||||||
outputs: ['{options.outputFile}'],
|
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', () => {
|
describe('--buildable', () => {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Tree } from '@nx/devkit';
|
import { Tree, offsetFromRoot } from '@nx/devkit';
|
||||||
import { configurationGenerator } from '@nx/jest';
|
import { configurationGenerator } from '@nx/jest';
|
||||||
|
|
||||||
export async function addJest(
|
export async function addJest(
|
||||||
@ -34,7 +34,10 @@ export async function addJest(
|
|||||||
setupFilesAfterEnv: ['<rootDir>/test-setup.${js ? 'js' : 'ts'}'],
|
setupFilesAfterEnv: ['<rootDir>/test-setup.${js ? 'js' : 'ts'}'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock'
|
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock'
|
||||||
}
|
},
|
||||||
|
coverageDirectory: '${offsetFromRoot(
|
||||||
|
appProjectRoot
|
||||||
|
)}coverage/${appProjectRoot}'
|
||||||
};`;
|
};`;
|
||||||
host.write(configPath, content);
|
host.write(configPath, content);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user