From e3b80146a9cd8d47808f7463876931278e545fc5 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Thu, 5 Oct 2023 09:48:58 +0100 Subject: [PATCH] chore(react): check ts-node in e2es --- .../src/react-module-federation.test.ts | 61 ++++++++++++++++--- e2e/utils/command-utils.ts | 6 +- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/e2e/react-core/src/react-module-federation.test.ts b/e2e/react-core/src/react-module-federation.test.ts index ed122c1be3b9b..4b660bc969950 100644 --- a/e2e/react-core/src/react-module-federation.test.ts +++ b/e2e/react-core/src/react-module-federation.test.ts @@ -109,8 +109,17 @@ describe('React Module Federation', () => { ); if (runE2ETests()) { - const e2eResults = runCLI(`e2e ${shell}-e2e --no-watch --verbose`); - expect(e2eResults).toContain('All specs passed!'); + const e2eResultsSwc = runCLI(`e2e ${shell}-e2e --no-watch --verbose`); + expect(e2eResultsSwc).toContain('All specs passed!'); + await killPorts(readPort(shell)); + await killPorts(readPort(remote1)); + await killPorts(readPort(remote2)); + await killPorts(readPort(remote3)); + + const e2eResultsTsNode = runCLI(`e2e ${shell}-e2e --no-watch --verbose`, { + env: { NX_PREFER_TS_NODE: 'true' }, + }); + expect(e2eResultsTsNode).toContain('All specs passed!'); await killPorts(readPort(shell)); await killPorts(readPort(remote1)); await killPorts(readPort(remote2)); @@ -136,19 +145,37 @@ describe('React Module Federation', () => { checkFilesExist(`${remote}/module-federation.config.ts`); // check default generated host is built successfully - const buildOutput = runCLI(`run ${shell}:build:development`); - expect(buildOutput).toContain('Successfully ran target build'); + const buildOutputSwc = runCLI(`run ${shell}:build:development`); + expect(buildOutputSwc).toContain('Successfully ran target build'); + + const buildOutputTsNode = runCLI(`run ${shell}:build:development`, { + env: { NX_PREFER_TS_NODE: 'true' }, + }); + expect(buildOutputTsNode).toContain('Successfully ran target build'); // check serves devRemotes ok - const shellProcess = await runCommandUntil( + const shellProcessSwc = await runCommandUntil( + `serve ${shell} --devRemotes=${remote} --verbose`, + (output) => { + return output.includes( + `All remotes started, server ready at http://localhost:${shellPort}` + ); + } + ); + await killProcessAndPorts(shellProcessSwc.pid, shellPort); + + const shellProcessTsNode = await runCommandUntil( `serve ${shell} --devRemotes=${remote} --verbose`, (output) => { return output.includes( `All remotes started, server ready at http://localhost:${shellPort}` ); + }, + { + env: { NX_PREFER_TS_NODE: 'true' }, } ); - await killProcessAndPorts(shellProcess.pid, shellPort); + await killProcessAndPorts(shellProcessTsNode.pid, shellPort); }, 500_000); it('should support different versions workspace libs for host and remote', async () => { @@ -374,11 +401,25 @@ describe('React Module Federation', () => { expect(remoteOutput).toContain('Successfully ran target build'); if (runE2ETests()) { - const hostE2eResults = runCLI(`e2e ${shell}-e2e --no-watch --verbose`); - const remoteE2eResults = runCLI(`e2e ${remote}-e2e --no-watch --verbose`); + const hostE2eResultsSwc = runCLI(`e2e ${shell}-e2e --no-watch --verbose`); + const remoteE2eResultsSwc = runCLI( + `e2e ${remote}-e2e --no-watch --verbose` + ); - expect(hostE2eResults).toContain('All specs passed!'); - expect(remoteE2eResults).toContain('All specs passed!'); + expect(hostE2eResultsSwc).toContain('All specs passed!'); + expect(remoteE2eResultsSwc).toContain('All specs passed!'); + + const hostE2eResultsTsNode = runCLI( + `e2e ${shell}-e2e --no-watch --verbose`, + { env: { NX_PREFER_TS_NODE: 'true' } } + ); + const remoteE2eResultsTsNode = runCLI( + `e2e ${remote}-e2e --no-watch --verbose`, + { env: { NX_PREFER_TS_NODE: 'true' } } + ); + + expect(hostE2eResultsTsNode).toContain('All specs passed!'); + expect(remoteE2eResultsTsNode).toContain('All specs passed!'); } }, 500_000); diff --git a/e2e/utils/command-utils.ts b/e2e/utils/command-utils.ts index 9f0144e3f8276..a145318f09293 100644 --- a/e2e/utils/command-utils.ts +++ b/e2e/utils/command-utils.ts @@ -229,7 +229,10 @@ export function runCommandAsync( export function runCommandUntil( command: string, - criteria: (output: string) => boolean + criteria: (output: string) => boolean, + opts: RunCmdOpts = { + env: undefined, + } ): Promise { const pm = getPackageManagerCommand(); const p = exec(`${pm.runNx} ${command}`, { @@ -238,6 +241,7 @@ export function runCommandUntil( env: { CI: 'true', ...getStrippedEnvironmentVariables(), + ...opts.env, FORCE_COLOR: 'false', }, });