Skip to content

Commit

Permalink
feat: adding svelte component testing support (#23553)
Browse files Browse the repository at this point in the history
Co-authored-by: Jessica Sachs <[email protected]>
Co-authored-by: Rocky <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2022
1 parent 8d2702f commit f6eaad4
Show file tree
Hide file tree
Showing 84 changed files with 7,636 additions and 373 deletions.
3 changes: 2 additions & 1 deletion cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ vue
vue2
react*
mount-utils
angular
angular
svelte
8 changes: 7 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"react",
"vue2",
"react18",
"angular"
"angular",
"svelte"
],
"bin": {
"cypress": "bin/cypress"
Expand Down Expand Up @@ -155,6 +156,11 @@
"import": "./angular/dist/index.js",
"require": "./angular/dist/index.js",
"types": "./angular/dist/index.d.ts"
},
"./svelte": {
"import": "./svelte/dist/cypress-svelte.esm-bundler.js",
"require": "./svelte/dist/cypress-svelte.cjs.js",
"types": "./svelte/dist/index.d.ts"
}
},
"workspaces": {
Expand Down
1 change: 1 addition & 0 deletions cli/scripts/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const npmModulesToCopy = [
'vue',
'vue2',
'angular',
'svelte',
]

npmModulesToCopy.forEach((folder) => {
Expand Down
4 changes: 2 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3058,11 +3058,11 @@ declare namespace Cypress {

type DevServerConfigOptions = {
bundler: 'webpack'
framework: 'react' | 'vue' | 'vue-cli' | 'nuxt' | 'create-react-app' | 'next'
framework: 'react' | 'vue' | 'vue-cli' | 'nuxt' | 'create-react-app' | 'next' | 'svelte'
webpackConfig?: PickConfigOpt<'webpackConfig'>
} | {
bundler: 'vite'
framework: 'react' | 'vue'
framework: 'react' | 'vue' | 'svelte'
viteConfig?: Omit<Exclude<PickConfigOpt<'viteConfig'>, undefined>, 'base' | 'root'>
} | {
bundler: 'webpack',
Expand Down
5 changes: 2 additions & 3 deletions npm/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "dist/index.js",
"scripts": {
"prebuild": "rimraf dist",
"build": "rollup -c rollup.config.js",
"build": "rollup -c rollup.config.mjs",
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
"build-prod": "yarn build",
"check-ts": "tsc --noEmit"
Expand All @@ -16,8 +16,7 @@
"@angular/common": "^14.0.6",
"@angular/core": "^14.0.6",
"@angular/platform-browser-dynamic": "^14.0.6",
"@rollup/plugin-node-resolve": "^11.1.1",
"rollup-plugin-typescript2": "^0.29.0",
"@cypress/mount-utils": "0.0.0-development",
"typescript": "^4.7.4",
"zone.js": "~0.11.4"
},
Expand Down
61 changes: 0 additions & 61 deletions npm/angular/rollup.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions npm/angular/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createEntries } from '@cypress/mount-utils/create-rollup-entry.mjs'

const config = {
external: [
'@angular/core',
'@angular/core/testing',
'@angular/common',
'@angular/platform-browser-dynamic/testing',
'zone.js',
'zone.js/testing',
],
}

export default createEntries({ formats: ['es'], input: 'src/index.ts', config })
71 changes: 71 additions & 0 deletions npm/mount-utils/create-rollup-entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// CommonJS to easily share across packages
import ts from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import _ from 'lodash'
import { readFileSync } from 'fs'

const pkg = JSON.parse(readFileSync('./package.json'))

/** @type {(options: { formats: string[], input: string, config: {} }) => []} */
export function createEntries (options) {
const {
formats,
input,
config = {},
} = options

const banner = `
/**
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} Cypress.io
* Released under the MIT License
*/
`

return formats.map((format) => {
const baseConfig = {
input,
plugins: [
resolve({ preferBuiltins: true }),
commonjs(),
ts({
check: format === 'es',
tsconfigOverride: {
compilerOptions: {
declaration: format === 'es',
target: 'es6',
module: format === 'cjs' ? 'es2015' : 'esnext',
},
exclude: ['tests'],
},
}),
],
output: {
banner,
name: 'CypressReact',
file: pkg.unpkg,
format,
},
}

const finalConfig = _.mergeWith({}, baseConfig, config, (objValue, srcValue) => {
if (_.isArray(objValue)) {
return objValue.concat(srcValue)
}
})

if (format === 'es') {
finalConfig.output.file = pkg.module
}

if (format === 'cjs') {
finalConfig.output.file = pkg.main
}

// eslint-disable-next-line no-console
console.log(`Building ${format}: ${finalConfig.output.file}`)

return finalConfig
})
}
4 changes: 4 additions & 0 deletions npm/mount-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
},
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"rollup": "^2.38.5",
"rollup-plugin-typescript2": "^0.29.0",
"typescript": "^4.7.4"
},
"files": [
Expand Down
6 changes: 1 addition & 5 deletions npm/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Test React components using Cypress",
"main": "dist/cypress-react.cjs.js",
"scripts": {
"build": "rimraf dist && rollup -c rollup.config.js",
"build": "rimraf dist && rollup -c rollup.config.mjs",
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
"build-prod": "yarn build",
"cy:open": "node ../../scripts/cypress.js open --component",
Expand All @@ -16,8 +16,6 @@
},
"devDependencies": {
"@cypress/mount-utils": "0.0.0-development",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@types/semver": "7.3.9",
"@vitejs/plugin-react": "1.3.1",
"axios": "0.21.2",
Expand All @@ -27,8 +25,6 @@
"react-dom": "16.8.6",
"react-router": "6.0.0-alpha.1",
"react-router-dom": "6.0.0-alpha.1",
"rollup": "^2.38.5",
"rollup-plugin-typescript2": "^0.29.0",
"semver": "^7.3.2",
"typescript": "^4.7.4",
"vite": "3.0.3",
Expand Down
74 changes: 0 additions & 74 deletions npm/react/rollup.config.js

This file was deleted.

18 changes: 18 additions & 0 deletions npm/react/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createEntries } from '@cypress/mount-utils/create-rollup-entry.mjs'

const config = {
external: [
'react',
'react-dom',
'react-dom/client',
],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/client': 'ReactDOM/client',
},
},
}

export default createEntries({ formats: ['es', 'cjs'], input: 'src/index.ts', config })
2 changes: 1 addition & 1 deletion npm/react18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Test React components using Cypress",
"main": "dist/cypress-react.cjs.js",
"scripts": {
"build": "rimraf dist && rollup -c rollup.config.js",
"build": "rimraf dist && rollup -c rollup.config.mjs",
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
"build-prod": "yarn build",
"watch": "yarn build --watch --watch.exclude ./dist/**/*"
Expand Down
3 changes: 0 additions & 3 deletions npm/react18/rollup.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions npm/react18/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import rollupConfig from '@cypress/react/rollup.config.mjs'

export default rollupConfig
17 changes: 17 additions & 0 deletions npm/svelte/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"cypress"
],
"extends": [
"plugin:@cypress/dev/tests"
],
"env": {
"cypress/globals": true
},
"rules": {
"mocha/no-global-tests": "off",
"no-unused-vars": "off",
"no-console": "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
3 changes: 3 additions & 0 deletions npm/svelte/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
save-exact=true
progress=false
package-lock=true
7 changes: 7 additions & 0 deletions npm/svelte/.releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
...require('../../.releaserc.base'),
branches: [
// this one releases v3 on master on the latest channel
'master',
],
}
Empty file added npm/svelte/CHANGELOG.md
Empty file.
Loading

0 comments on commit f6eaad4

Please sign in to comment.