diff --git a/circle.yml b/circle.yml index ee71591d5d..272041bc9b 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/npm/vue/cypress/plugins/index.js b/npm/vue/cypress/plugins/index.js index f505daf3d0..9e363ab7e0 100644 --- a/npm/vue/cypress/plugins/index.js +++ b/npm/vue/cypress/plugins/index.js @@ -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) { diff --git a/npm/vue/cypress/support/commands.js b/npm/vue/cypress/support/commands.js new file mode 100644 index 0000000000..73197c8042 --- /dev/null +++ b/npm/vue/cypress/support/commands.js @@ -0,0 +1,6 @@ +/// +import { mount } from '@cypress/vue' + +Cypress.Commands.add('mount', (comp) => { + return mount(comp) +}) diff --git a/npm/vue/cypress/support/index.js b/npm/vue/cypress/support/index.js index 0741db5b69..d6de64c3c5 100644 --- a/npm/vue/cypress/support/index.js +++ b/npm/vue/cypress/support/index.js @@ -1 +1,3 @@ // created automatically when cy:open starts + +import './commands' diff --git a/npm/vue/package.json b/npm/vue/package.json index 806eaf940e..4320ad9af5 100644 --- a/npm/vue/package.json +++ b/npm/vue/package.json @@ -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" diff --git a/npm/vue/src/index.ts b/npm/vue/src/index.ts index 6f3d1667f0..94474a25a3 100644 --- a/npm/vue/src/index.ts +++ b/npm/vue/src/index.ts @@ -36,6 +36,16 @@ type CyMountOptions = Omit, '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()