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

feat: vue-cli and nuxt preset for CT object API architecture #20956

Merged
merged 11 commits into from
Apr 8, 2022

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Apr 7, 2022

User facing changelog

Add out-of-the-box support for Vue CLI and Nuxt.js in the new Object API CT architecture.

Now you easily configure Vue CLI with Cypress CT, like this:

module.exports = {
  component: {
    devServer: {
      framework: 'vue-cli',
      bundler: 'webpack'
    }
  },
}

Additional details

How has the user experience changed?

Heavily inspired by @ZachJW34's branch: https://github.com/cypress-io/cypress/pull/20954/files#diff-c96246e7228f1e151b9a664f2465af2aee6f1eefef8cc69b2cd1b7e4d650a0f0

Since we did not bundle cypress/vue-2 with the binary, I skipped that test. It can be added once https://cypress-io.atlassian.net/browse/UNIFY-1253 is completed.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 7, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Apr 7, 2022



Test summary

441 0 21 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 602ca20
Started Apr 8, 2022 1:37 PM
Ended Apr 8, 2022 1:45 PM
Duration 07:47 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 changed the title feat: vue-cli preset for CT object API architecture feat: vue-cli and nuxt preset for CT object API architecture Apr 7, 2022
@lmiller1990 lmiller1990 marked this pull request as ready for review April 7, 2022 08:00
@lmiller1990 lmiller1990 requested review from a team as code owners April 7, 2022 08:00
@lmiller1990 lmiller1990 requested review from jennifer-shehane, tgriesser, BlueWinds and ZachJW34 and removed request for a team April 7, 2022 08:00
@lmiller1990 lmiller1990 removed request for jennifer-shehane and a team April 7, 2022 08:23
Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

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

Should we add coverage for vuecli/nuxt typescript projects?

Some comments, nothing blocking. Tested and it works great 👍


// Add to this list to focus on a particular permutation
// TODO: run vuecli4-vue2 tests once cypress/vue-2 is bundled
const ONLY_PROJECTS: ProjectDirs[number][] = ['vuecli5-vue3']
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a test for vuecli4-vue3 as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

export function vueCliHandler ({ devServerConfig }: PresetHandler): Configuration {
try {
const config = require.resolve('@vue/cli-service/webpack.config', {
paths: [devServerConfig.cypressConfig.projectRoot],
Copy link
Contributor

Choose a reason for hiding this comment

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

The sourceRelativeWebpackModules.ts has the framework and importPath (though since this is coming from @vue/cli-service it would have to be mapped) which can be used to do a direct require. This works as well, what are your thoughts on which system to use? I'm fine with either but going this route would make the work done inside of sourceRelativeWebpackModules.ts for frameworks largely redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think using require.resolve.paths is nice since it gives better stack traces if the module isn't found: #20956 (review)

My understanding is the sourceRelativeWebpackModules is more for sourcing the modules we ship in the binary and pointing to the right ones (eg, webpack-dev-server, html-webpack-plugin, etc).

@@ -49,8 +78,8 @@ export function makeWebpackConfig (
config: CreateFinalWebpackConfig,
) {
const { module: webpack } = config.sourceWebpackModulesResult.webpack
const userWebpackConfig = config.devServerConfig.webpackConfig as Partial<Configuration>
const frameworkWebpackConfig = config.frameworkConfig as Partial<Configuration>
const userWebpackConfig = modifyWebpackConfigForCypress(config.devServerConfig.webpackConfig as Partial<Configuration>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to do this twice or can we just modify the mergedConfig? I did something similar here:

const finalUserWebpackConfig = merge(frameworkWebpackConfig ?? {}, userWebpackConfig ?? {})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@tgriesser tgriesser left a comment

Choose a reason for hiding this comment

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

Looking good, the require.resolve.paths is nice b/c it shows all the places it searched for the module.

npm/webpack-dev-server-fresh/src/helpers/vueCliHandler.ts Outdated Show resolved Hide resolved

const { getWebpackConfig } = require(nuxt)

const webpackConfig = await getWebpackConfig()
Copy link
Member

Choose a reason for hiding this comment

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

😢 that this forces async everywhere. Was looking into nuxt internal to understand why it does, and it seems only to be because of the ability to have nuxt options be async: https://github.com/nuxt/nuxt.js/blame/db11f7bf937cdbb96ff0067bdee1aa153978e4e0/packages/config/src/load.js#L63

Oh well, probably not worth tapping into internal APIs, but I was half wondering if we could just source from @nuxt/webpack directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I shed a tear when I saw this was async. We can def explore tapping into the internals, but it seems better to use their public API, at least for now, where the goal is stability. Can definitely dig into this more later, or even make a PR to nuxt (we are good friends with them).

npm/webpack-dev-server-fresh/src/helpers/nuxtHandler.ts Outdated Show resolved Hide resolved
@tgriesser tgriesser self-requested a review April 8, 2022 14:36
@ZachJW34 ZachJW34 merged commit 57659c4 into 10.0-release Apr 8, 2022
@ZachJW34 ZachJW34 deleted the lmiller1990/UNIFY-1415 branch April 8, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants