Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(breaking): exclude node_modules from cross-origin-callback-loader #24952

Merged
merged 4 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion npm/webpack-preprocessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`\
Expand Down
1 change: 1 addition & 0 deletions system-tests/projects/origin-dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
5 changes: 5 additions & 0 deletions system-tests/projects/origin-dependencies/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
e2e: {
setupNodeEvents (on) {},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('uses custom cy.origin command', () => {
cy.customOriginCommand()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'custom-origin-command'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions system-tests/test/cy_origin_error_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
},
})
})