nx/packages/workspace/src/generators/move/lib/update-readme.spec.ts
Leosvel Pérez Espinosa 8564d9ba12
feat(misc): support new format to determine new project name and destination in move generators (#18878)
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
2023-09-05 09:40:16 -04:00

57 lines
1.6 KiB
TypeScript

import { Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { join } from 'path';
import { NormalizedSchema } from '../schema';
import { updateReadme } from './update-readme';
// nx-ignore-next-line
const { libraryGenerator } = require('@nx/js');
describe('updateReadme', () => {
let tree: Tree;
let schema: NormalizedSchema;
beforeEach(async () => {
schema = {
projectName: 'my-lib',
destination: 'shared/my-destination',
importPath: '@proj/shared-my-destination',
updateImportPath: true,
newProjectName: 'shared-my-destination',
relativeToRootDestination: 'shared/my-destination',
};
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
});
it('should handle README.md not existing', async () => {
await libraryGenerator(tree, {
name: 'my-lib',
projectNameAndRootFormat: 'as-provided',
});
const readmePath = join(schema.relativeToRootDestination, 'README.md');
tree.delete(readmePath);
expect(() => {
updateReadme(tree, schema);
}).not.toThrow();
});
it('should update README.md contents', async () => {
await libraryGenerator(tree, {
name: 'my-lib',
projectNameAndRootFormat: 'as-provided',
});
// This step is usually handled elsewhere
tree.rename('my-lib/README.md', 'shared/my-destination/README.md');
updateReadme(tree, schema);
const content = tree
.read('shared/my-destination/README.md')
.toString('utf8');
expect(content).toMatch('# shared-my-destination');
expect(content).toMatch('nx test shared-my-destination');
});
});