From 1abc5d7d3ef9329496a43677b808e8b922b5bb94 Mon Sep 17 00:00:00 2001 From: Jonathan Kolberg Date: Sat, 4 Jun 2022 10:12:52 +0200 Subject: [PATCH] feat(node): allow executing esm compiled scripts --- e2e/node/src/node.test.ts | 50 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index d0cfbf504a47d2..22b00998170fde 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -232,44 +232,40 @@ describe('Node Applications', () => { } }, 120000); - it('should be able to run es module applications', async () => { + it('should be able to run ESM applications', async () => { const esmapp = uniq('esmapp'); - runCLI(`generate @nrwl/node:app ${esmapp} --linter=eslint`); + runCLI( + `generate @nrwl/node:app ${esmapp} --linter=eslint --framework=none --bundler=webpack` + ); updateJson(`apps/${esmapp}/tsconfig.app.json`, (config) => { config.module = 'esnext'; config.target = 'es2020'; return config; }); - updateProjectConfig(esmapp, (config) => { - config.targets.build.executor = '@nrwl/node:webpack'; - config.targets.build.options.outputFileName = 'main.mjs'; - config.targets.build.options.webpackConfig = `apps/${esmapp}/webpack.config.js`; - config.targets.serve.executor = '@nrwl/node:node'; - config.targets.serve.options.watch = false; - return config; - }); updateFile( `apps/${esmapp}/webpack.config.js`, - `module.exports = (config, context) => ({ - ...config, - experiments: { - ...config.experiments, - outputModule: true, - topLevelAwait: true, - }, - output: { - path: config.output.path, - chunkFormat: 'module', - library: { - type: 'module', - }, - }, - })` + ` + const { composePlugins, withNx } = require('@nx/webpack'); + module.exports = composePlugins(withNx(), (config) => { + config.experiments = { + ...config.experiments, + outputModule: true, + topLevelAwait: true, + }; + config.output = { + path: config.output.path, + chunkFormat: 'module', + library: { type: 'module' } + } + return config; + }); + ` ); await runCLIAsync(`build ${esmapp}`); - const { stdout } = await runCLIAsync(`serve ${esmapp}`); - expect(stdout).toBe('Hello World!'); + await runCommandUntil(`serve ${esmapp}`, (output) => { + return output.includes('Hello World!'); + }); }, 300000); });