From 5599f519faee39ea3dd2be1c09f5de1d8c492499 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 09:58:40 -0400 Subject: [PATCH 1/7] fix: #22038 better windows ESM interop --- packages/server/lib/plugins/child/run_require_async_child.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/plugins/child/run_require_async_child.js b/packages/server/lib/plugins/child/run_require_async_child.js index 378bbf5ef217..676f914c5961 100644 --- a/packages/server/lib/plugins/child/run_require_async_child.js +++ b/packages/server/lib/plugins/child/run_require_async_child.js @@ -1,6 +1,7 @@ require('graceful-fs').gracefulify(require('fs')) const stripAnsi = require('strip-ansi') const debug = require('debug')(`cypress:lifecycle:child:run_require_async_child:${process.pid}`) +const { pathToFileURL } = require('url') const tsNodeUtil = require('./ts_node') const util = require('../util') const { RunPlugins } = require('./run_plugins') @@ -127,7 +128,8 @@ function run (ipc, file, projectRoot) { // Certain modules cannot be dynamically imported. If this throws, however, we want // to show the original error that was thrown, because that's ultimately the source of the problem try { - return await import(file) + // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 + return await import(pathToFileURL(pathToFileURL).href) } catch (e) { // If we aren't able to import the file at all, throw the original error, since that has more accurate information // of what failed to begin with From 7d3169f0d990fa69931fe947cb677129c6a50b7b Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 10:06:51 -0400 Subject: [PATCH 2/7] attempt to get failing tests first --- packages/launchpad/cypress/e2e/scaffold-project.cy.ts | 1 + packages/server/lib/plugins/child/run_require_async_child.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/launchpad/cypress/e2e/scaffold-project.cy.ts b/packages/launchpad/cypress/e2e/scaffold-project.cy.ts index 38efdae2f4da..7af62c3fd944 100644 --- a/packages/launchpad/cypress/e2e/scaffold-project.cy.ts +++ b/packages/launchpad/cypress/e2e/scaffold-project.cy.ts @@ -44,6 +44,7 @@ function scaffoldAndOpenE2EProject (opts: { cy.contains('E2E Testing').click() cy.contains('We added the following files to your project:') cy.contains('Continue').click() + cy.contains('Choose a Browser') } function scaffoldAndOpenCTProject (opts: { diff --git a/packages/server/lib/plugins/child/run_require_async_child.js b/packages/server/lib/plugins/child/run_require_async_child.js index 676f914c5961..09a168eefa86 100644 --- a/packages/server/lib/plugins/child/run_require_async_child.js +++ b/packages/server/lib/plugins/child/run_require_async_child.js @@ -129,7 +129,8 @@ function run (ipc, file, projectRoot) { // to show the original error that was thrown, because that's ultimately the source of the problem try { // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 - return await import(pathToFileURL(pathToFileURL).href) + // return await import(pathToFileURL(pathToFileURL).href) + return await import(pathToFileURL) } catch (e) { // If we aren't able to import the file at all, throw the original error, since that has more accurate information // of what failed to begin with From 5588c8fd3370f88473d28ca22afcf34d95def65a Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 10:27:42 -0400 Subject: [PATCH 3/7] fix typo, don't throw originalError --- .../plugins/child/run_require_async_child.js | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/server/lib/plugins/child/run_require_async_child.js b/packages/server/lib/plugins/child/run_require_async_child.js index 09a168eefa86..3edebf7ac140 100644 --- a/packages/server/lib/plugins/child/run_require_async_child.js +++ b/packages/server/lib/plugins/child/run_require_async_child.js @@ -1,7 +1,7 @@ require('graceful-fs').gracefulify(require('fs')) const stripAnsi = require('strip-ansi') const debug = require('debug')(`cypress:lifecycle:child:run_require_async_child:${process.pid}`) -const { pathToFileURL } = require('url') +// const { pathToFileURL } = require('url') const tsNodeUtil = require('./ts_node') const util = require('../util') const { RunPlugins } = require('./run_plugins') @@ -98,12 +98,10 @@ function run (ipc, file, projectRoot) { // 3a. Yes: Use bundleRequire // 3b. No: Continue through to `await import(configFile)` // 4. Use node's dynamic import to import the configFile - let originalError try { return require(file) } catch (err) { - originalError = err if (!err.stack.includes('[ERR_REQUIRE_ESM]') && !err.stack.includes('SyntaxError: Cannot use import statement outside a module')) { throw err } @@ -125,18 +123,11 @@ function run (ipc, file, projectRoot) { debug(`User doesn't have esbuild. Going to use native node imports.`) // We cannot replace the initial `require` with `await import` because - // Certain modules cannot be dynamically imported. If this throws, however, we want - // to show the original error that was thrown, because that's ultimately the source of the problem - try { - // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 - // return await import(pathToFileURL(pathToFileURL).href) - return await import(pathToFileURL) - } catch (e) { - // If we aren't able to import the file at all, throw the original error, since that has more accurate information - // of what failed to begin with - debug('esbuild fallback for loading config failed, throwing original error. node import error: %o', e) - throw originalError - } + // Certain modules cannot be dynamically imported. + + // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 + // return await import(pathToFileURL(pathToFileURL).href) + return await import(file) } throw err From 36e8740f05d2fc288731601f52123d5641f3e7af Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 11:15:52 -0400 Subject: [PATCH 4/7] add pathToFileURL for windows interop --- packages/server/lib/plugins/child/run_require_async_child.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/server/lib/plugins/child/run_require_async_child.js b/packages/server/lib/plugins/child/run_require_async_child.js index 3edebf7ac140..40e0e97fca18 100644 --- a/packages/server/lib/plugins/child/run_require_async_child.js +++ b/packages/server/lib/plugins/child/run_require_async_child.js @@ -1,7 +1,7 @@ require('graceful-fs').gracefulify(require('fs')) const stripAnsi = require('strip-ansi') const debug = require('debug')(`cypress:lifecycle:child:run_require_async_child:${process.pid}`) -// const { pathToFileURL } = require('url') +const { pathToFileURL } = require('url') const tsNodeUtil = require('./ts_node') const util = require('../util') const { RunPlugins } = require('./run_plugins') @@ -126,8 +126,7 @@ function run (ipc, file, projectRoot) { // Certain modules cannot be dynamically imported. // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 - // return await import(pathToFileURL(pathToFileURL).href) - return await import(file) + return await import(pathToFileURL(pathToFileURL).href) } throw err From 98608d8c0af1342b69295816992aab7cf92f5897 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 11:33:25 -0400 Subject: [PATCH 5/7] typo again --- packages/server/lib/plugins/child/run_require_async_child.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/lib/plugins/child/run_require_async_child.js b/packages/server/lib/plugins/child/run_require_async_child.js index 40e0e97fca18..2c4aba824600 100644 --- a/packages/server/lib/plugins/child/run_require_async_child.js +++ b/packages/server/lib/plugins/child/run_require_async_child.js @@ -126,7 +126,7 @@ function run (ipc, file, projectRoot) { // Certain modules cannot be dynamically imported. // pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 - return await import(pathToFileURL(pathToFileURL).href) + return await import(pathToFileURL(file).href) } throw err From c83af1a783c90eefcfec4bd07f4e4bbc4d9c90a5 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 12:03:26 -0400 Subject: [PATCH 6/7] updates from @flotwig feedback --- packages/launchpad/cypress/e2e/scaffold-project.cy.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/launchpad/cypress/e2e/scaffold-project.cy.ts b/packages/launchpad/cypress/e2e/scaffold-project.cy.ts index 7af62c3fd944..dda36061fc76 100644 --- a/packages/launchpad/cypress/e2e/scaffold-project.cy.ts +++ b/packages/launchpad/cypress/e2e/scaffold-project.cy.ts @@ -44,6 +44,12 @@ function scaffoldAndOpenE2EProject (opts: { cy.contains('E2E Testing').click() cy.contains('We added the following files to your project:') cy.contains('Continue').click() + // Going through the loading of config + cy.get('[data-cy="loading-spinner"]') + cy.get('[data-cy="loading-spinner"]').should('not.exist') + // No errrors were encountered + cy.get('[data-testid="error-header"]').should('not.exist') + // Asserts that we've made it through the flow cy.contains('Choose a Browser') } From 0a43737ce8d7bd74fb1da96dfdef8f82bf66941f Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 2 Jun 2022 14:22:52 -0400 Subject: [PATCH 7/7] remove invalid snapshot --- system-tests/__snapshots__/config_modules_spec.ts.js | 3 --- system-tests/test/config_modules_spec.ts | 7 ------- 2 files changed, 10 deletions(-) delete mode 100644 system-tests/__snapshots__/config_modules_spec.ts.js diff --git a/system-tests/__snapshots__/config_modules_spec.ts.js b/system-tests/__snapshots__/config_modules_spec.ts.js deleted file mode 100644 index 7b06c15a4063..000000000000 --- a/system-tests/__snapshots__/config_modules_spec.ts.js +++ /dev/null @@ -1,3 +0,0 @@ -exports['cypress config with esm and cjs / does not support modules and ts without esbuild in config-cjs-and-esm/config-with-ts-module'] = ` -STDOUT_ERROR_VALIDATED -` diff --git a/system-tests/test/config_modules_spec.ts b/system-tests/test/config_modules_spec.ts index d6490f8d814b..fc727a36c8ea 100644 --- a/system-tests/test/config_modules_spec.ts +++ b/system-tests/test/config_modules_spec.ts @@ -32,13 +32,6 @@ describe('cypress config with esm and cjs', function () { spec: 'app.cy.js', browser: 'chrome', expectedExitCode: 1, - snapshot: true, - onStdout (stdout) { - expect(stdout).to.include('nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules') - - // Need to make this stable b/c of filepaths, and snapshot: true is needed to invoke onStdout - return 'STDOUT_ERROR_VALIDATED' - }, }) })