<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: Colum Ferry <cferry09@gmail.com> Co-authored-by: Nicholas Cunningham <ndcunningham@gmail.com>
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import 'nx/src/internal-testing-utils/mock-project-graph';
|
|
|
|
import { readProjectConfiguration, Tree } from '@nx/devkit';
|
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
import { NormalizedSchema } from '../schema';
|
|
import { updateProjectRootFiles } from './update-project-root-files';
|
|
|
|
// nx-ignore-next-line
|
|
const { libraryGenerator } = require('@nx/js');
|
|
|
|
describe('updateProjectRootFiles', () => {
|
|
let tree: Tree;
|
|
|
|
beforeEach(async () => {
|
|
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
});
|
|
|
|
it('should update the relative root in files at the root of the project', async () => {
|
|
const testFile = `module.exports = {
|
|
name: 'my-source',
|
|
preset: '../jest.config.js',
|
|
coverageDirectory: '../coverage/my-source',
|
|
snapshotSerializers: [
|
|
'jest-preset-angular/AngularSnapshotSerializer.js',
|
|
'jest-preset-angular/HTMLCommentSerializer.js'
|
|
]
|
|
};`;
|
|
const testFilePath = 'subfolder/my-destination/jest.config.js';
|
|
await libraryGenerator(tree, {
|
|
directory: 'my-source',
|
|
});
|
|
const projectConfig = readProjectConfiguration(tree, 'my-source');
|
|
tree.write(testFilePath, testFile);
|
|
const schema: NormalizedSchema = {
|
|
projectName: 'my-source',
|
|
destination: 'subfolder/my-destination',
|
|
importPath: '@proj/subfolder-my-destination',
|
|
updateImportPath: true,
|
|
newProjectName: 'subfolder-my-destination',
|
|
relativeToRootDestination: 'subfolder/my-destination',
|
|
};
|
|
|
|
updateProjectRootFiles(tree, schema, projectConfig);
|
|
|
|
const testFileAfter = tree.read(testFilePath, 'utf-8');
|
|
expect(testFileAfter).toContain(`preset: '../../jest.config.js'`);
|
|
expect(testFileAfter).toContain(
|
|
`coverageDirectory: '../../coverage/my-source'`
|
|
);
|
|
});
|
|
|
|
it('should handle cypress configs correctly', async () => {
|
|
const cypressConfigContents = `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
|
|
|
|
import { defineConfig } from 'cypress';
|
|
|
|
export default defineConfig({
|
|
e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src' }) },
|
|
});
|
|
`;
|
|
const cypressConfigPath = 'apps/my-app-e2e/cypress.config.ts';
|
|
await libraryGenerator(tree, {
|
|
directory: 'e2e',
|
|
root: 'e2e',
|
|
});
|
|
const projectConfig = readProjectConfiguration(tree, 'e2e');
|
|
tree.write(cypressConfigPath, cypressConfigContents);
|
|
const schema: NormalizedSchema = {
|
|
projectName: 'e2e',
|
|
destination: 'apps/my-app-e2e',
|
|
importPath: '@proj/e2e',
|
|
updateImportPath: false,
|
|
newProjectName: 'my-app-e2e',
|
|
relativeToRootDestination: 'apps/my-app-e2e',
|
|
};
|
|
|
|
updateProjectRootFiles(tree, schema, projectConfig);
|
|
|
|
const cypressConfigAfter = tree.read(cypressConfigPath, 'utf-8');
|
|
expect(cypressConfigAfter).toContain(
|
|
`e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src' }) }`
|
|
);
|
|
});
|
|
});
|