diff --git a/npm/vite-dev-server/cypress/components/Foo.tsx b/npm/vite-dev-server/cypress/components/Foo.tsx
new file mode 100644
index 000000000000..ffdd0bfb5505
--- /dev/null
+++ b/npm/vite-dev-server/cypress/components/Foo.tsx
@@ -0,0 +1,5 @@
+import React from 'react'
+
+export const Foo: React.FC = () => {
+ return
Hello world!!!!
+}
diff --git a/npm/vite-dev-server/cypress/components/react-no-jsx.spec.jsx b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.jsx
new file mode 100644
index 000000000000..7b8255976344
--- /dev/null
+++ b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.jsx
@@ -0,0 +1,13 @@
+import React from 'react'
+import { mount } from '@cypress/react'
+
+const Comp = () => {
+ return Hello world!
+}
+
+describe('React', () => {
+ it('renders a react component', () => {
+ mount()
+ cy.get('div').contains('Hello world')
+ })
+})
diff --git a/npm/vite-dev-server/cypress/components/react-no-jsx.spec.ts b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.ts
new file mode 100644
index 000000000000..dc5596642633
--- /dev/null
+++ b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.ts
@@ -0,0 +1,13 @@
+import React from 'react'
+import { mount } from '@cypress/react'
+
+const Comp = () => {
+ return React.createElement('div', {}, 'Hello world')
+}
+
+describe('React', () => {
+ it('renders a react component', () => {
+ mount(React.createElement(Comp))
+ cy.get('div').contains('Hello world')
+ })
+})
diff --git a/npm/vite-dev-server/cypress/components/react-no-jsx.spec.tsx b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.tsx
new file mode 100644
index 000000000000..12c969717333
--- /dev/null
+++ b/npm/vite-dev-server/cypress/components/react-no-jsx.spec.tsx
@@ -0,0 +1,25 @@
+import React from 'react'
+import { mount } from '@cypress/react'
+import { Foo } from './Foo'
+
+describe('React', () => {
+ it('renders a react component #1', () => {
+ mount()
+ cy.get('div').contains('Hello world')
+ })
+
+ it('renders a react component #2', () => {
+ mount()
+ cy.get('div').contains('Hello world')
+ })
+
+ it('renders a react component #3', () => {
+ mount()
+ cy.get('div').contains('Hello world')
+ })
+
+ it('renders a react component #4', () => {
+ mount()
+ cy.get('div').contains('Hello world')
+ })
+})
diff --git a/npm/vite-dev-server/cypress/fixtures/example.json b/npm/vite-dev-server/cypress/fixtures/example.json
new file mode 100644
index 000000000000..da18d9352a17
--- /dev/null
+++ b/npm/vite-dev-server/cypress/fixtures/example.json
@@ -0,0 +1,5 @@
+{
+ "name": "Using fixtures to represent data",
+ "email": "hello@cypress.io",
+ "body": "Fixtures are a great way to mock data for responses to routes"
+}
\ No newline at end of file
diff --git a/npm/vite-dev-server/cypress/plugins.js b/npm/vite-dev-server/cypress/plugins.js
index 9764b3ffaf61..16054ce032f7 100644
--- a/npm/vite-dev-server/cypress/plugins.js
+++ b/npm/vite-dev-server/cypress/plugins.js
@@ -1,9 +1,7 @@
import { startDevServer } from '@cypress/vite-dev-server'
module.exports = (on, config) => {
- on('dev-server:start', async (options) => {
- return startDevServer({ options })
- })
+ on('dev-server:start', async (options) => startDevServer({ options }))
return config
}
diff --git a/npm/vite-dev-server/index-template.html b/npm/vite-dev-server/index-template.html
index 0140f725593e..d08afceb111e 100644
--- a/npm/vite-dev-server/index-template.html
+++ b/npm/vite-dev-server/index-template.html
@@ -24,7 +24,27 @@
return node
}
- let importsToLoad = [() => import("{{{specPath}}}")];
+ const specPath = "{{{specPath}}}"
+
+ let importsToLoad = [() => import(specPath).catch(e => {
+ // if the import failed, it might be because of dependencies
+ // so we try a quick refresh just in case it is
+
+ // Since vite does not work with IE we can use URLSearchParams without polyfill
+ const searchParams = new URLSearchParams(window.location.search);
+ const r = searchParams.has("refresh") ? parseInt(searchParams.get("refresh"), 10) + 1 : 0
+ // limit the number of refresh (dependency discovery depths)
+ // to 2 instead of 1 for React-DOM
+ if (r < 2) {
+ searchParams.set('refresh', r)
+ window.location.search = searchParams
+ } else {
+ throw new Error(`
+ **Error during compilation.**
+ Check the terminal log for more info
+`, e)
+ }
+ })];
if ("{{{supportPath}}}") {
importsToLoad.push(() => import("{{{supportPath}}}"));
}
@@ -38,7 +58,7 @@
Cypress.onSpecWindow(window, importsToLoad)
Cypress.action('app:window:before:load', window)
- beforeEach(() => {
+ before(() => {
const root = appendTargetIfNotExists('__cy_root')
root.appendChild(appendTargetIfNotExists('__cy_app'))
diff --git a/npm/vite-dev-server/package.json b/npm/vite-dev-server/package.json
index be2b963b0e28..a5af7dc96ffd 100644
--- a/npm/vite-dev-server/package.json
+++ b/npm/vite-dev-server/package.json
@@ -17,13 +17,14 @@
},
"devDependencies": {
"@types/mustache": "4.1.1",
- "vite": "2.0.1"
+ "vite": "2.0.5"
},
"peerDependencies": {
"vite": ">= 2"
},
"files": [
- "dist"
+ "dist",
+ "index-template.html"
],
"license": "MIT",
"repository": {
@@ -34,5 +35,8 @@
"bugs": "https://github.com/cypress-io/cypress/issues/new?template=1-bug-report.md",
"publishConfig": {
"access": "public"
- }
+ },
+ "ciJobs": [
+ "npm-vite-dev-server"
+ ]
}
diff --git a/npm/vite-dev-server/src/makeCypressPlugin.ts b/npm/vite-dev-server/src/makeCypressPlugin.ts
index cb089183f064..878a1e87a8d8 100644
--- a/npm/vite-dev-server/src/makeCypressPlugin.ts
+++ b/npm/vite-dev-server/src/makeCypressPlugin.ts
@@ -29,7 +29,6 @@ export const makeCypressPlugin = (
server.middlewares.use('/index.html', (req, res) => handleIndex(indexHtml, projectRoot, supportFilePath, req, res))
},
handleHotUpdate: () => {
- console.log('HOT UPDATE')
devServerEvents.emit('dev-server:compile:success')
return []
diff --git a/npm/vue/.gitignore b/npm/vue/.gitignore
new file mode 100644
index 000000000000..46a115b981fe
--- /dev/null
+++ b/npm/vue/.gitignore
@@ -0,0 +1 @@
+cypress/videos
\ No newline at end of file
diff --git a/npm/vue/examples/cli-ts/package.json b/npm/vue/examples/cli-ts/package.json
index 9b31f05e18f2..7d72b041dbbd 100644
--- a/npm/vue/examples/cli-ts/package.json
+++ b/npm/vue/examples/cli-ts/package.json
@@ -4,8 +4,8 @@
"private": true,
"scripts": {
"build": "vue-cli-service build",
- "cy:open": "../../node_modules/.bin/cypress open",
- "cy:run": "../../node_modules/.bin/cypress run",
+ "cy:open": "node ../../../../scripts/cypress open",
+ "cy:run": "node ../../../../scripts/cypress run",
"serve": "vue-cli-service serve"
},
"dependencies": {
diff --git a/npm/vue/package.json b/npm/vue/package.json
index 32da693e5a9a..092bdea6dacc 100644
--- a/npm/vue/package.json
+++ b/npm/vue/package.json
@@ -2,18 +2,16 @@
"name": "@cypress/vue",
"version": "0.0.0-development",
"description": "Browser-based Component Testing for Vue.js with Cypress.io ✌️🌲",
- "main": "dist/index.js",
+ "main": "dist/cypress-vue.cjs.js",
"scripts": {
- "build": "tsc",
+ "build": "rimraf dist && yarn rollup -c rollup.config.js",
"build-prod": "yarn build",
"cy:open": "node ../../scripts/cypress.js open-ct --project ${PWD}",
"cy:run": "node ../../scripts/cypress.js run-ct --project ${PWD}",
"test": "yarn cy:run",
- "watch": "tsc -w"
+ "watch": "yarn build --watch --watch.exclude ./dist/**/*"
},
"dependencies": {
- "@cypress/code-coverage": "3.8.1",
- "@cypress/webpack-dev-server": "0.0.0-development",
"@vue/test-utils": "1.0.3",
"unfetch": "4.1.0"
},
@@ -21,7 +19,11 @@
"@babel/core": "7.9.0",
"@babel/plugin-transform-modules-commonjs": "7.10.4",
"@babel/preset-env": "7.9.5",
+ "@cypress/code-coverage": "3.8.1",
+ "@cypress/webpack-dev-server": "0.0.0-development",
"@intlify/vue-i18n-loader": "1.0.0",
+ "@rollup/plugin-commonjs": "^17.1.0",
+ "@rollup/plugin-node-resolve": "^11.1.1",
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"axios": "0.19.2",
@@ -33,6 +35,9 @@
"eslint-plugin-vue": "^6.2.2",
"find-webpack": "2.1.0",
"mocha": "7.1.1",
+ "rollup": "^2.38.5",
+ "rollup-plugin-istanbul": "2.0.1",
+ "rollup-plugin-typescript2": "^0.29.0",
"tailwindcss": "1.1.4",
"typescript": "3.9.6",
"vue": "2.6.11",
@@ -45,12 +50,14 @@
"webpack": "4.42.0"
},
"peerDependencies": {
+ "@cypress/webpack-dev-server": "*",
"babel-loader": "8",
"cypress": ">=4.5.0",
"vue": "2.x"
},
"files": [
- "dist/**/*"
+ "dist/**/*",
+ "src/**/*.js"
],
"engines": {
"node": ">=8"
@@ -68,6 +75,13 @@
"cypress",
"vue"
],
+ "unpkg": "dist/cypress-vue.browser.js",
+ "module": "dist/cypress-vue.esm-bundler.js",
+ "peerDependenciesMeta": {
+ "@cypress/webpack-dev-server": {
+ "optional": true
+ }
+ },
"publishConfig": {
"access": "public",
"registry": "http://registry.npmjs.org/"
diff --git a/npm/vue/rollup.config.js b/npm/vue/rollup.config.js
new file mode 100644
index 000000000000..4e1c4fb6033e
--- /dev/null
+++ b/npm/vue/rollup.config.js
@@ -0,0 +1,86 @@
+import ts from 'rollup-plugin-typescript2'
+import resolve from '@rollup/plugin-node-resolve'
+import commonjs from '@rollup/plugin-commonjs'
+
+import pkg from './package.json'
+
+const banner = `
+/**
+ * ${pkg.name} v${pkg.version}
+ * (c) ${new Date().getFullYear()} Cypress.io
+ * Released under the MIT License
+ */
+`
+
+function createEntry (options) {
+ const {
+ format,
+ input,
+ isBrowser,
+ } = options
+
+ const config = {
+ input,
+ external: [
+ 'vue',
+ '@vue/test-utils',
+ '@cypress/webpack-dev-server',
+ ],
+ plugins: [
+ resolve({ preferBuiltins: true }), commonjs(),
+ ],
+ output: {
+ banner,
+ name: 'CypressVue',
+ file: pkg.unpkg,
+ format,
+ globals: {
+ vue: 'Vue',
+ '@vue/test-utils': 'VueTestUtils',
+ },
+ exports: 'auto',
+ },
+ }
+
+ if (input === 'src/index.ts') {
+ if (format === 'es') {
+ config.output.file = pkg.module
+ if (isBrowser) {
+ config.output.file = pkg.unpkg
+ }
+ }
+
+ if (format === 'cjs') {
+ config.output.file = pkg.main
+ }
+ } else {
+ config.output.file = input.replace(/^src\//, 'dist/')
+ }
+
+ console.log(`Building ${format}: ${config.output.file}`)
+
+ config.plugins.push(
+ ts({
+ check: format === 'es' && isBrowser,
+ tsconfigOverride: {
+ compilerOptions: {
+ declaration: format === 'es',
+ target: 'es5', // not sure what this should be?
+ module: format === 'cjs' ? 'es2015' : 'esnext',
+ },
+ exclude: ['tests'],
+ },
+ }),
+ )
+
+ return config
+}
+
+export default [
+ createEntry({ format: 'es', input: 'src/index.ts', isBrowser: false }),
+ createEntry({ format: 'es', input: 'src/index.ts', isBrowser: true }),
+ createEntry({ format: 'iife', input: 'src/index.ts', isBrowser: true }),
+ createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false }),
+ createEntry({ format: 'cjs', input: 'src/support.js', isBrowser: false }),
+ createEntry({ format: 'cjs', input: 'src/plugins/webpack/index.js', isBrowser: false }),
+]
diff --git a/npm/vue/src/index.ts b/npm/vue/src/index.ts
index 99aacd0c8d80..d7a442ae0434 100644
--- a/npm/vue/src/index.ts
+++ b/npm/vue/src/index.ts
@@ -6,6 +6,7 @@ import {
VueTestUtilsConfigOptions,
Wrapper,
} from '@vue/test-utils'
+import { renderTestingPlatform, ROOT_ID } from './renderTestingPlatform'
const defaultOptions: (keyof MountOptions)[] = [
'vue',
@@ -357,15 +358,11 @@ export const mount = (
const document: Document = cy.state('document')
document.body.innerHTML = ''
- let el = document.getElementById('cypress-jsdom')
+ let el = document.getElementById(ROOT_ID)
// If the target div doesn't exist, create it
if (!el) {
- const div = document.createElement('div')
-
- div.id = 'cypress-jsdom'
- document.body.appendChild(div)
- el = div
+ el = renderTestingPlatform(document.head.innerHTML)
}
if (typeof options.stylesheets === 'string') {
diff --git a/npm/vue/src/plugins/webpack/index.js b/npm/vue/src/plugins/webpack/index.js
index 5854b87e2b60..b30e6534da50 100644
--- a/npm/vue/src/plugins/webpack/index.js
+++ b/npm/vue/src/plugins/webpack/index.js
@@ -17,7 +17,6 @@ const { startDevServer } = require('@cypress/webpack-dev-server')
* }
*/
const cypressPluginsFn = (on, config, webpackConfig) => {
- require('@cypress/code-coverage/task')(on, config)
on('dev-server:start', (options) => startDevServer({ options, webpackConfig }))
return config
diff --git a/npm/vue/src/renderTestingPlatform.ts b/npm/vue/src/renderTestingPlatform.ts
new file mode 100644
index 000000000000..64efe6bf52dc
--- /dev/null
+++ b/npm/vue/src/renderTestingPlatform.ts
@@ -0,0 +1,20 @@
+export const ROOT_ID = '__cy_root'
+
+/** Initialize an empty document with root element
+ * This only needs for experimentalComponentTesting
+*/
+export function renderTestingPlatform (headInnerHTML: string) {
+ // @ts-expect-error no idea
+ const document = cy.state('document')
+
+ if (document.body) document.body.innerHTML = ''
+
+ if (document.head) document.head.innerHTML = headInnerHTML
+
+ const rootNode = document.createElement('div')
+
+ rootNode.setAttribute('id', ROOT_ID)
+ document.getElementsByTagName('body')[0].prepend(rootNode)
+
+ return rootNode
+}
diff --git a/npm/vue/src/support.js b/npm/vue/src/support.js
index 5e2454e3cb14..2e5c51a411c8 100644
--- a/npm/vue/src/support.js
+++ b/npm/vue/src/support.js
@@ -1,47 +1,11 @@
/* eslint-env mocha */
-import unfetch from 'unfetch'
-require('@cypress/code-coverage/support')
+const { renderTestingPlatform } = require('./renderTestingPlatform')
let headInnerHTML = document.head.innerHTML
-/** Initialize an empty document with root element */
-function renderTestingPlatform () {
- const document = cy.state('document')
-
- if (document.body) document.body.innerHTML = ''
-
- if (document.head) document.head.innerHTML = headInnerHTML
-
- const rootNode = document.createElement('div')
-
- rootNode.setAttribute('id', 'cypress-jsdom')
- document.getElementsByTagName('body')[0].prepend(rootNode)
-
- return cy.get('#cypress-jsdom', { log: false })
-}
-
-/**
- * Replaces window.fetch with a polyfill based on XMLHttpRequest
- * that Cypress can spy on and stub
- * @see https://www.cypress.io/blog/2020/06/29/experimental-fetch-polyfill/
- */
-function polyfillFetchIfNeeded () {
- // @ts-ignore
- if (Cypress.config('experimentalFetchPolyfill')) {
- // @ts-ignore
- if (!cy.state('fetchPolyfilled')) {
- delete window.fetch
- window.fetch = unfetch
- // @ts-ignore
- cy.state('fetchPolyfilled', true)
- }
- }
-}
-
beforeEach(() => {
- renderTestingPlatform()
- polyfillFetchIfNeeded()
+ renderTestingPlatform(headInnerHTML)
})
before(() => {
diff --git a/npm/vue/tsconfig.json b/npm/vue/tsconfig.json
index edf0d1e70806..ea20f06c3e05 100644
--- a/npm/vue/tsconfig.json
+++ b/npm/vue/tsconfig.json
@@ -28,7 +28,7 @@
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
+ "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
diff --git a/npm/vue/webpack.config.js b/npm/vue/webpack.config.js
index e822524b35a4..86e7423304e7 100644
--- a/npm/vue/webpack.config.js
+++ b/npm/vue/webpack.config.js
@@ -4,6 +4,7 @@
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
+const pkg = require('package.json')
module.exports = {
mode: 'development',
@@ -18,7 +19,7 @@ module.exports = {
extensions: ['.js', '.json', '.vue'],
alias: {
// point at the built file
- '@cypress/vue': path.join(__dirname, 'dist'),
+ '@cypress/vue': path.join(__dirname, pkg.main),
vue: 'vue/dist/vue.esm.js',
},
},
diff --git a/npm/webpack-dev-server/index-template.html b/npm/webpack-dev-server/index-template.html
index 70e10108dfbf..75e28860533f 100644
--- a/npm/webpack-dev-server/index-template.html
+++ b/npm/webpack-dev-server/index-template.html
@@ -7,6 +7,5 @@
Components App
-