fix: do not register CT specific event in e2e mode

This commit is contained in:
Lachlan Miller
2021-07-22 17:24:38 +10:00
parent 3054f063da
commit 58362037fd
6 changed files with 26 additions and 3 deletions
+6 -2
View File
@@ -1339,8 +1339,12 @@ jobs:
name: Build
command: yarn workspace @cypress/vue build
- run:
name: Run tests
command: yarn test-ci
name: Run component tests
command: yarn test-ci:ct
working_directory: npm/vue
- run:
name: Run e2e tests
command: yarn test:ci:e2e
working_directory: npm/vue
- store_test_results:
path: npm/vue/test_results
+1 -1
View File
@@ -7,7 +7,7 @@ const webpackConfig = require('../../webpack.config')
*/
module.exports = (on, config) => {
if (config.testingType !== 'component') {
throw Error(`This is a component testing project. testingType should be 'component'. Received ${config.testingType}`)
return config
}
if (!webpackConfig.resolve) {
+6
View File
@@ -0,0 +1,6 @@
/// <reference types="cypress" />
import { mount } from '@cypress/vue'
Cypress.Commands.add('mount', (comp) => {
return mount(comp)
})
+2
View File
@@ -1 +1,3 @@
// created automatically when cy:open starts
import './commands'
+1
View File
@@ -8,6 +8,7 @@
"build-prod": "yarn build",
"cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
"cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
"cy:run:e2e": "node ../../scripts/cypress.js run --project ${PWD}",
"test": "yarn cy:run",
"watch": "yarn build --watch --watch.exclude ./dist/**/*",
"test-ci": "node ../../scripts/run-ct-examples.js --examplesList=./examples.env"
+10
View File
@@ -36,6 +36,16 @@ type CyMountOptions<Props> = Omit<MountingOptions<Props>, 'attachTo'> & {
let initialInnerHtml = ''
Cypress.on('run:start', () => {
// `mount` is designed to work with component testing only.
// it assumes ROOT_ID exists, which is not the case in e2e.
// if the user registers a custom command that imports `cypress/vue`,
// this event will be registered and cause an error when the user
// launches e2e (since it's common to use Cypress for both CT and E2E.
// https://github.com/cypress-io/cypress/issues/17438
if (Cypress.testingType !== 'component') {
return
}
initialInnerHtml = document.head.innerHTML
Cypress.on('test:before:run', () => {
Cypress.vueWrapper?.unmount()