Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Fixing dynamic imports #288

Merged

Conversation

JessicaSachs
Copy link
Contributor

@JessicaSachs JessicaSachs commented Apr 7, 2020

Adds support for the following use cases

  • Components rendering dynamic routes with <router-link>
  • Asynchronous components with delays
  • Any dynamic import () => import('./myCoolCode')

Context

Cypress does not have the ability to serve static assets. This becomes problematic when dealing with chunks like [name]-[hash].js.

Vue CLI, by default, splits out vendors into their own chunk, so the splitChunks plugin is enabled by default. While we can turn Split Chunks off, we still have to contend with raw Dynamic Imports.

Because Cypress cannot serve static assets, we would like a single chunk to be generated by webpack. This solution must also work for any dynamic imports that will be executed.

Solution

delete webpackOptions.optimization.splitChunks // remove previous chunk settings
webpackOptions.plugins.push(
  new webpack.optimize.LimitChunkCountPlugin({
    maxChunks: 1 // no chunks from dynamic imports -- includes the entry file
  })
)
  • For Webpack 4, we can achieve this behavior by settings the LimitChunkCountPlugin to include the value maxChunks: 1. Documentation found here
  • Coincidentally, this will be done by default in Webpack 5.

@@ -1 +0,0 @@
import 'cypress-vue-unit-test/support'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this delete looks suspicious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was breaking the e2e tests. I was also suspicious. @bahmutov what's this line doing for us? I don't see a support file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to load suport file which creates a placeholder element in the iframe, which we do in
we point at that support file here https://github.com/bahmutov/cypress-vue-unit-test/pull/247/files#diff-73ffe0d8ebfaf5bdc6b0546e41f576c0R11 using an alias to avoid coding ../../support https://github.com/bahmutov/cypress-vue-unit-test/pull/247/files#diff-6d4bb79610683d9749d2cbb62e708d88

If this breaks, land this PR after #287 and we can check out the merged result to see if it works correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly no issues after merging that PR... will continue merging and then validate again

preprocessor/webpack.js Outdated Show resolved Hide resolved
Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to land

Support images loaded with url-loader
@JessicaSachs JessicaSachs changed the base branch from feature/vue-cli to feature/cypress-mount-mode April 8, 2020 21:21
@JessicaSachs JessicaSachs merged commit 53bc68e into feature/cypress-mount-mode Apr 8, 2020
@bahmutov
Copy link
Contributor

🎉 This PR is included in version 1.12.0-cypress-mount-mode.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants