From bc788ff876fdf45778cbfc90e7b13b4012364fb0 Mon Sep 17 00:00:00 2001 From: Caleb Ukle Date: Thu, 2 Feb 2023 11:02:06 -0600 Subject: [PATCH] fix(node): quote filepath in cli e2e sample test (#14779) Fixes https://github.com/nrwl/nx/issues/14761 --- .../e2e-project/e2e-project.spec.ts | 29 +++++++++++++++++++ .../__fileName__/__fileName__.spec.ts__tmpl__ | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/node/src/generators/e2e-project/e2e-project.spec.ts b/packages/node/src/generators/e2e-project/e2e-project.spec.ts index a2b8a21093..2f7d1fee73 100644 --- a/packages/node/src/generators/e2e-project/e2e-project.spec.ts +++ b/packages/node/src/generators/e2e-project/e2e-project.spec.ts @@ -38,4 +38,33 @@ describe('e2eProjectGenerator', () => { expect(tree.exists(`e2e/src/server/server.spec.ts`)).toBeTruthy(); }); + + it('should generate cli project', async () => { + await applicationGenerator(tree, { + name: 'api', + framework: 'none', + e2eTestRunner: 'none', + }); + await e2eProjectGenerator(tree, { + projectType: 'cli', + project: 'api', + }); + expect(tree.read('api-e2e/src/api/api.spec.ts', 'utf-8')) + .toMatchInlineSnapshot(` + "import { execSync } from 'child_process'; + import { join } from 'path'; + + describe('CLI tests', () => { + it('should print a message', () => { + const cliPath = join(process.cwd(), \\"dist/api\\"); + + const output = execSync(\`node \${cliPath}\`).toString(); + + expect(output).toMatch(/Hello World/); + }); + }); + + " + `); + }); }); diff --git a/packages/node/src/generators/e2e-project/files/cli/src/__fileName__/__fileName__.spec.ts__tmpl__ b/packages/node/src/generators/e2e-project/files/cli/src/__fileName__/__fileName__.spec.ts__tmpl__ index 1b1971bb24..1c32cd3219 100644 --- a/packages/node/src/generators/e2e-project/files/cli/src/__fileName__/__fileName__.spec.ts__tmpl__ +++ b/packages/node/src/generators/e2e-project/files/cli/src/__fileName__/__fileName__.spec.ts__tmpl__ @@ -3,7 +3,7 @@ import { join } from 'path'; describe('CLI tests', () => { it('should print a message', () => { - const cliPath = join(process.cwd(), <%= mainFile %>); + const cliPath = join(process.cwd(), "<%= mainFile %>"); const output = execSync(`node ${cliPath}`).toString();