fix(core): update root jest config with move generator (#6313)

ISSUES CLOSED: #6303
This commit is contained in:
Katerina Skroumpelou 2021-07-09 16:30:09 +03:00 committed by GitHub
parent dbb74c6c67
commit cfff767b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 6 deletions

View File

@ -69,4 +69,52 @@ describe('updateJestConfig', () => {
expect(rootJestConfigAfter).not.toContain('<rootDir>/libs/my-source');
expect(rootJestConfigAfter).toContain('<rootDir>/libs/my-destination');
});
it('should update jest configs properly even if project is in many layers of subfolders', async () => {
const jestConfig = `module.exports = {
name: 'some-test-dir-my-source',
preset: '../../jest.config.js',
coverageDirectory: '../../coverage/libs/some/test/dir/my-source',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};`;
const jestConfigPath = '/libs/other/test/dir/my-destination/jest.config.js';
const rootJestConfigPath = '/jest.config.js';
await libraryGenerator(tree, {
name: 'some/test/dir/my-source',
standaloneConfig: false,
});
const projectConfig = readProjectConfiguration(
tree,
'some-test-dir-my-source'
);
tree.write(jestConfigPath, jestConfig);
const schema: Schema = {
projectName: 'some-test-dir-my-source',
destination: 'other/test/dir/my-destination',
importPath: undefined,
updateImportPath: true,
};
updateJestConfig(tree, schema, projectConfig);
const jestConfigAfter = tree.read(jestConfigPath, 'utf-8');
const rootJestConfigAfter = tree.read(rootJestConfigPath, 'utf-8');
expect(jestConfigAfter).toContain(`name: 'other-test-dir-my-destination'`);
expect(jestConfigAfter).toContain(
`coverageDirectory: '../../coverage/libs/other/test/dir/my-destination'`
);
expect(rootJestConfigAfter).not.toContain(
'<rootDir>/libs/some/test/dir/my-source'
);
expect(rootJestConfigAfter).toContain(
'<rootDir>/libs/other/test/dir/my-destination'
);
});
});

View File

@ -1,4 +1,4 @@
import { Tree, ProjectConfiguration, getWorkspaceLayout } from '@nrwl/devkit';
import { Tree, ProjectConfiguration } from '@nrwl/devkit';
import * as path from 'path';
@ -44,11 +44,7 @@ export function updateJestConfig(
return;
}
const { libsDir, appsDir } = getWorkspaceLayout(tree);
const findProject = new RegExp(
`<rootDir>\/(${libsDir}|${appsDir})\/${schema.projectName}`,
'g'
);
const findProject = new RegExp(`<rootDir>\/${project.root}`, 'g');
const oldRootJestConfigContent = tree.read(rootJestConfigPath, 'utf-8');