Skip to content

Commit

Permalink
fix: allow asynchronous vue cli init phase (#23936)
Browse files Browse the repository at this point in the history
Co-authored-by: Zachary Williams <ZachJW34@gmail.com>
  • Loading branch information
msebas and ZachJW34 authored Sep 26, 2022
1 parent 88ecb1e commit 6a40936
Show file tree
Hide file tree
Showing 8 changed files with 4,239 additions and 9 deletions.
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/vue-cli.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path="../support/e2e.ts" />
import type { ProjectFixtureDir } from '@tooling/system-tests/lib/fixtureDirs'

const PROJECTS: ProjectFixtureDir[] = ['vuecli4-vue2', 'vuecli4-vue3', 'vuecli5-vue3']
const PROJECTS: ProjectFixtureDir[] = ['vuecli4-vue2', 'vuecli4-vue3', 'vuecli5-vue3', 'vuecli5-vue3-type-module']

// Add to this list to focus on a particular permutation
const ONLY_PROJECTS: ProjectFixtureDir[] = []
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/src/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function getPreset (devServerConfig: WebpackDevServerConfig): Promise<Opti
return await nuxtHandler(devServerConfig)

case 'vue-cli':
return vueCliHandler(devServerConfig)
return await vueCliHandler(devServerConfig)

case 'next':
return await nextHandler(devServerConfig)
Expand Down
12 changes: 7 additions & 5 deletions npm/webpack-dev-server/src/helpers/vueCliHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import { sourceDefaultWebpackDependencies } from './sourceRelativeWebpackModules

const debug = debugLib('cypress:webpack-dev-server:vueCliHandler')

export function vueCliHandler (devServerConfig: WebpackDevServerConfig): PresetHandlerResult {
export async function vueCliHandler (devServerConfig: WebpackDevServerConfig): Promise<PresetHandlerResult> {
const sourceWebpackModulesResult = sourceDefaultWebpackDependencies(devServerConfig)

try {
const config = require.resolve('@vue/cli-service/webpack.config', {
const Service = require(require.resolve('@vue/cli-service', {
paths: [devServerConfig.cypressConfig.projectRoot],
})
}))
let service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())

const webpackConfig = require(config) as Configuration
await service.init(process.env.VUE_CLI_MODE || process.env.NODE_ENV)
const webpackConfig = service.resolveWebpackConfig() as Configuration

debug('webpack config %o', webpackConfig)

return { frameworkConfig: webpackConfig, sourceWebpackModulesResult }
} catch (e) {
console.error(e) // eslint-disable-line no-console
throw Error(`Error loading @vue/cli-service/webpack.config.js. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`)
throw Error(`Error loading @vue/cli-service/lib/Service or resolving WebpackConfig. Looked in ${require.resolve.paths(devServerConfig.cypressConfig.projectRoot)}`)
}
}
4 changes: 2 additions & 2 deletions npm/webpack-dev-server/test/handlers/vueCliHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('vueCliHandler', function () {

process.chdir(projectRoot)

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = vueCliHandler({
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await vueCliHandler({
cypressConfig: { projectRoot } as Cypress.PluginConfigOptions,
framework: 'vue-cli',
} as WebpackDevServerConfig)
Expand All @@ -30,7 +30,7 @@ describe('vueCliHandler', function () {

process.chdir(projectRoot)

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = vueCliHandler({
const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await vueCliHandler({
cypressConfig: { projectRoot } as Cypress.PluginConfigOptions,
framework: 'vue-cli',
} as WebpackDevServerConfig)
Expand Down
10 changes: 10 additions & 0 deletions system-tests/projects/vuecli5-vue3-type-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": {
"vue": "^3.2.13"
},
"devDependencies": {
"@vue/cli-service": "~5.0.0"
},
"type": "module",
"projectFixtureDirectory": "vue-cli"
}
5 changes: 5 additions & 0 deletions system-tests/projects/vuecli5-vue3-type-module/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "es6"
}
}
3 changes: 3 additions & 0 deletions system-tests/projects/vuecli5-vue3-type-module/vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@vue/cli-service'

export default defineConfig({})
Loading

5 comments on commit 6a40936

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6a40936 Sep 26, 2022

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/linux-arm64/develop-6a40936604ae24b0b40996692c4a03e5a3c1c9a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6a40936 Sep 26, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/linux-x64/develop-6a40936604ae24b0b40996692c4a03e5a3c1c9a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6a40936 Sep 26, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/darwin-x64/develop-6a40936604ae24b0b40996692c4a03e5a3c1c9a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6a40936 Sep 26, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/win32-x64/develop-6a40936604ae24b0b40996692c4a03e5a3c1c9a2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6a40936 Sep 26, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/darwin-arm64/develop-6a40936604ae24b0b40996692c4a03e5a3c1c9a2/cypress.tgz

Please sign in to comment.