diff --git a/npm/webpack-preprocessor/index.ts b/npm/webpack-preprocessor/index.ts index 3b93af15b35b..c61f9bf12291 100644 --- a/npm/webpack-preprocessor/index.ts +++ b/npm/webpack-preprocessor/index.ts @@ -222,7 +222,7 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F }) .tap((opts) => { if (opts.devtool === false) { - // disable any overrides if we've explictly turned off sourcemaps + // disable any overrides if we've explicitly turned off sourcemaps overrideSourceMaps(false, options.typescript) return @@ -248,6 +248,7 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F // so that it's working with plain javascript webpackOptions.module.rules.unshift({ test: /\.(js|ts|jsx|tsx)$/, + exclude: /node_modules/, use: [{ loader: require.resolve('@cypress/webpack-preprocessor/dist/lib/cross-origin-callback-loader.js'), options: { diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index 5340ae35757d..78d34e344eb3 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -1228,7 +1228,9 @@ export default { Variables must either be defined within the ${cmd('origin')} command or passed in using the args option. - Using \`require()\` or \`import()\` to include dependencies requires enabling the \`experimentalOriginDependencies\` flag and using the latest version of \`@cypress/webpack-preprocessor\`.`, + Using \`require()\` or \`import()\` to include dependencies requires enabling the \`experimentalOriginDependencies\` flag and using the latest version of \`@cypress/webpack-preprocessor\`. + + Note: Using \`require()\` or \`import()\` within ${cmd('origin')} from a \`node_modules\` plugin is not currently supported.`, }, callback_mixes_sync_and_async: { message: stripIndent`\ diff --git a/system-tests/projects/origin-dependencies/.gitignore b/system-tests/projects/origin-dependencies/.gitignore new file mode 100644 index 000000000000..cf4bab9ddde9 --- /dev/null +++ b/system-tests/projects/origin-dependencies/.gitignore @@ -0,0 +1 @@ +!node_modules diff --git a/system-tests/projects/origin-dependencies/cypress.config.js b/system-tests/projects/origin-dependencies/cypress.config.js new file mode 100644 index 000000000000..091d7c0451d5 --- /dev/null +++ b/system-tests/projects/origin-dependencies/cypress.config.js @@ -0,0 +1,5 @@ +module.exports = { + e2e: { + setupNodeEvents (on) {}, + }, +} diff --git a/system-tests/projects/origin-dependencies/cypress/e2e/cross_origin.cy.js b/system-tests/projects/origin-dependencies/cypress/e2e/cross_origin.cy.js new file mode 100644 index 000000000000..361985aeda1a --- /dev/null +++ b/system-tests/projects/origin-dependencies/cypress/e2e/cross_origin.cy.js @@ -0,0 +1,3 @@ +it('uses custom cy.origin command', () => { + cy.customOriginCommand() +}) diff --git a/system-tests/projects/origin-dependencies/cypress/support/e2e.js b/system-tests/projects/origin-dependencies/cypress/support/e2e.js new file mode 100644 index 000000000000..3125df81f8a8 --- /dev/null +++ b/system-tests/projects/origin-dependencies/cypress/support/e2e.js @@ -0,0 +1 @@ +import 'custom-origin-command' diff --git a/system-tests/projects/origin-dependencies/node_modules/custom-origin-command/index.js b/system-tests/projects/origin-dependencies/node_modules/custom-origin-command/index.js new file mode 100644 index 000000000000..c8ea51e8c29c --- /dev/null +++ b/system-tests/projects/origin-dependencies/node_modules/custom-origin-command/index.js @@ -0,0 +1,5 @@ +Cypress.Commands.add('customOriginCommand', () => { + cy.origin('foobar.com', () => { + require('lodash') + }) +}) diff --git a/system-tests/test/cy_origin_error_spec.ts b/system-tests/test/cy_origin_error_spec.ts index 810a9eb8c44b..29a620086477 100644 --- a/system-tests/test/cy_origin_error_spec.ts +++ b/system-tests/test/cy_origin_error_spec.ts @@ -72,4 +72,18 @@ describe('e2e cy.origin errors', () => { expect(res.stdout).to.contain('Using `require()` or `import()` to include dependencies requires enabling the `experimentalOriginDependencies` flag and using the latest version of `@cypress/webpack-preprocessor`') }, }) + + systemTests.it('errors when using a plugin that has a custom command that uses cy.origin with a dependency', { + browser: '!webkit', // TODO(webkit): cy.origin is not currently supported in webkit + project: 'origin-dependencies', + spec: 'cross_origin.cy.js', + expectedExitCode: 1, + config: commonConfig, + async onRun (exec) { + const res = await exec() + + expect(res.stdout).to.contain('Using `require()` or `import()` to include dependencies requires enabling the `experimentalOriginDependencies` flag and using the latest version of `@cypress/webpack-preprocessor`') + expect(res.stdout).to.contain('Note: Using `require()` or `import()` within `cy.origin()` from a `node_modules` plugin is not currently supported.') + }, + }) })