Skip to content

Commit

Permalink
fix: do not register CT specific event in e2e mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Jul 22, 2021
1 parent 3054f06 commit 5836203
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions circle.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion npm/vue/cypress/plugins/index.js
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions npm/vue/cypress/support/commands.js
@@ -0,0 +1,6 @@
/// <reference types="cypress" />
import { mount } from '@cypress/vue'

Cypress.Commands.add('mount', (comp) => {
return mount(comp)
})
2 changes: 2 additions & 0 deletions npm/vue/cypress/support/index.js
@@ -1 +1,3 @@
// created automatically when cy:open starts

import './commands'
1 change: 1 addition & 0 deletions npm/vue/package.json
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions npm/vue/src/index.ts
Expand Up @@ -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()
Expand Down

0 comments on commit 5836203

Please sign in to comment.