Skip to content

Commit

Permalink
cleanup(misc): add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Aug 3, 2023
1 parent b3e8fd2 commit ab4fb04
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions e2e/js/src/js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,55 @@ export function ${lib}Wildcard() {
// restore nx.json
updateFile('nx.json', () => originalNxJson);
});

it('should generate project with name and directory as provided when --nameDirectoryFormat=as-provided', async () => {
const lib1 = uniq('lib1');
runCLI(
`generate @nx/js:lib ${lib1} --directory=shared --bundler=tsc --name-directory-format=as-provided --no-interactive`
);

// check files are generated without the layout directory ("libs/") and
// in the directory provided (no project name appended)
checkFilesExist('shared/src/index.ts');
// check project name is as provided (no prefixed directory name)
expect(runCLI(`build ${lib1}`)).toContain(
'Done compiling TypeScript files'
);
// check tests pass
const testResult = await runCLIAsync(`test ${lib1}`);
expect(testResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total'
);
}, 500_000);

it('should support generating with a scoped project name when --nameDirectoryFormat=as-provided', async () => {
const scopedLib = uniq('@my-org/lib1');

// assert scoped project names are not supported when --nameDirectoryFormat=derived
expect(() =>
runCLI(
`generate @nx/js:lib ${scopedLib} --bundler=tsc --name-directory-format=derived --no-interactive`
)
).toThrow();

runCLI(
`generate @nx/js:lib ${scopedLib} --bundler=tsc --name-directory-format=as-provided --no-interactive`
);

// check files are generated without the layout directory ("libs/") and
// using the project name as the directory when no directory is provided
checkFilesExist(
`${scopedLib}/src/index.ts`,
`${scopedLib}/src/lib/${scopedLib.split('/')[1]}.ts`
);
// check build works
expect(runCLI(`build ${scopedLib}`)).toContain(
'Done compiling TypeScript files'
);
// check tests pass
const testResult = await runCLIAsync(`test ${scopedLib}`);
expect(testResult.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total'
);
}, 500_000);
});

0 comments on commit ab4fb04

Please sign in to comment.