From ab4fb0485904275aa488e4b63dfcfa1f20a42d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Thu, 3 Aug 2023 13:58:45 +0100 Subject: [PATCH] cleanup(misc): add e2e tests --- e2e/js/src/js.test.ts | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/e2e/js/src/js.test.ts b/e2e/js/src/js.test.ts index daf756aad22b28..7612b1d053a56e 100644 --- a/e2e/js/src/js.test.ts +++ b/e2e/js/src/js.test.ts @@ -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); });