Skip to content

Commit f6eaad4

Browse files
ZachJW34JessicaSachsrockindahizzy
authored
feat: adding svelte component testing support (#23553)
Co-authored-by: Jessica Sachs <jess@jessicasachs.io> Co-authored-by: Rocky <25568640+rockindahizzy@users.noreply.github.com>
1 parent 8d2702f commit f6eaad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+7636
-373
lines changed

cli/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ vue
1919
vue2
2020
react*
2121
mount-utils
22-
angular
22+
angular
23+
svelte

cli/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
"react",
109109
"vue2",
110110
"react18",
111-
"angular"
111+
"angular",
112+
"svelte"
112113
],
113114
"bin": {
114115
"cypress": "bin/cypress"
@@ -155,6 +156,11 @@
155156
"import": "./angular/dist/index.js",
156157
"require": "./angular/dist/index.js",
157158
"types": "./angular/dist/index.d.ts"
159+
},
160+
"./svelte": {
161+
"import": "./svelte/dist/cypress-svelte.esm-bundler.js",
162+
"require": "./svelte/dist/cypress-svelte.cjs.js",
163+
"types": "./svelte/dist/index.d.ts"
158164
}
159165
},
160166
"workspaces": {

cli/scripts/post-build.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const npmModulesToCopy = [
1313
'vue',
1414
'vue2',
1515
'angular',
16+
'svelte',
1617
]
1718

1819
npmModulesToCopy.forEach((folder) => {

cli/types/cypress.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3058,11 +3058,11 @@ declare namespace Cypress {
30583058

30593059
type DevServerConfigOptions = {
30603060
bundler: 'webpack'
3061-
framework: 'react' | 'vue' | 'vue-cli' | 'nuxt' | 'create-react-app' | 'next'
3061+
framework: 'react' | 'vue' | 'vue-cli' | 'nuxt' | 'create-react-app' | 'next' | 'svelte'
30623062
webpackConfig?: PickConfigOpt<'webpackConfig'>
30633063
} | {
30643064
bundler: 'vite'
3065-
framework: 'react' | 'vue'
3065+
framework: 'react' | 'vue' | 'svelte'
30663066
viteConfig?: Omit<Exclude<PickConfigOpt<'viteConfig'>, undefined>, 'base' | 'root'>
30673067
} | {
30683068
bundler: 'webpack',

npm/angular/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "dist/index.js",
77
"scripts": {
88
"prebuild": "rimraf dist",
9-
"build": "rollup -c rollup.config.js",
9+
"build": "rollup -c rollup.config.mjs",
1010
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
1111
"build-prod": "yarn build",
1212
"check-ts": "tsc --noEmit"
@@ -16,8 +16,7 @@
1616
"@angular/common": "^14.0.6",
1717
"@angular/core": "^14.0.6",
1818
"@angular/platform-browser-dynamic": "^14.0.6",
19-
"@rollup/plugin-node-resolve": "^11.1.1",
20-
"rollup-plugin-typescript2": "^0.29.0",
19+
"@cypress/mount-utils": "0.0.0-development",
2120
"typescript": "^4.7.4",
2221
"zone.js": "~0.11.4"
2322
},

npm/angular/rollup.config.js

-61
This file was deleted.

npm/angular/rollup.config.mjs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createEntries } from '@cypress/mount-utils/create-rollup-entry.mjs'
2+
3+
const config = {
4+
external: [
5+
'@angular/core',
6+
'@angular/core/testing',
7+
'@angular/common',
8+
'@angular/platform-browser-dynamic/testing',
9+
'zone.js',
10+
'zone.js/testing',
11+
],
12+
}
13+
14+
export default createEntries({ formats: ['es'], input: 'src/index.ts', config })
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// CommonJS to easily share across packages
2+
import ts from 'rollup-plugin-typescript2'
3+
import resolve from '@rollup/plugin-node-resolve'
4+
import commonjs from '@rollup/plugin-commonjs'
5+
import _ from 'lodash'
6+
import { readFileSync } from 'fs'
7+
8+
const pkg = JSON.parse(readFileSync('./package.json'))
9+
10+
/** @type {(options: { formats: string[], input: string, config: {} }) => []} */
11+
export function createEntries (options) {
12+
const {
13+
formats,
14+
input,
15+
config = {},
16+
} = options
17+
18+
const banner = `
19+
/**
20+
* ${pkg.name} v${pkg.version}
21+
* (c) ${new Date().getFullYear()} Cypress.io
22+
* Released under the MIT License
23+
*/
24+
`
25+
26+
return formats.map((format) => {
27+
const baseConfig = {
28+
input,
29+
plugins: [
30+
resolve({ preferBuiltins: true }),
31+
commonjs(),
32+
ts({
33+
check: format === 'es',
34+
tsconfigOverride: {
35+
compilerOptions: {
36+
declaration: format === 'es',
37+
target: 'es6',
38+
module: format === 'cjs' ? 'es2015' : 'esnext',
39+
},
40+
exclude: ['tests'],
41+
},
42+
}),
43+
],
44+
output: {
45+
banner,
46+
name: 'CypressReact',
47+
file: pkg.unpkg,
48+
format,
49+
},
50+
}
51+
52+
const finalConfig = _.mergeWith({}, baseConfig, config, (objValue, srcValue) => {
53+
if (_.isArray(objValue)) {
54+
return objValue.concat(srcValue)
55+
}
56+
})
57+
58+
if (format === 'es') {
59+
finalConfig.output.file = pkg.module
60+
}
61+
62+
if (format === 'cjs') {
63+
finalConfig.output.file = pkg.main
64+
}
65+
66+
// eslint-disable-next-line no-console
67+
console.log(`Building ${format}: ${finalConfig.output.file}`)
68+
69+
return finalConfig
70+
})
71+
}

npm/mount-utils/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
},
1313
"dependencies": {},
1414
"devDependencies": {
15+
"@rollup/plugin-commonjs": "^17.1.0",
16+
"@rollup/plugin-node-resolve": "^11.1.1",
17+
"rollup": "^2.38.5",
18+
"rollup-plugin-typescript2": "^0.29.0",
1519
"typescript": "^4.7.4"
1620
},
1721
"files": [

npm/react/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Test React components using Cypress",
55
"main": "dist/cypress-react.cjs.js",
66
"scripts": {
7-
"build": "rimraf dist && rollup -c rollup.config.js",
7+
"build": "rimraf dist && rollup -c rollup.config.mjs",
88
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
99
"build-prod": "yarn build",
1010
"cy:open": "node ../../scripts/cypress.js open --component",
@@ -16,8 +16,6 @@
1616
},
1717
"devDependencies": {
1818
"@cypress/mount-utils": "0.0.0-development",
19-
"@rollup/plugin-commonjs": "^17.1.0",
20-
"@rollup/plugin-node-resolve": "^11.1.1",
2119
"@types/semver": "7.3.9",
2220
"@vitejs/plugin-react": "1.3.1",
2321
"axios": "0.21.2",
@@ -27,8 +25,6 @@
2725
"react-dom": "16.8.6",
2826
"react-router": "6.0.0-alpha.1",
2927
"react-router-dom": "6.0.0-alpha.1",
30-
"rollup": "^2.38.5",
31-
"rollup-plugin-typescript2": "^0.29.0",
3228
"semver": "^7.3.2",
3329
"typescript": "^4.7.4",
3430
"vite": "3.0.3",

npm/react/rollup.config.js

-74
This file was deleted.

npm/react/rollup.config.mjs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createEntries } from '@cypress/mount-utils/create-rollup-entry.mjs'
2+
3+
const config = {
4+
external: [
5+
'react',
6+
'react-dom',
7+
'react-dom/client',
8+
],
9+
output: {
10+
globals: {
11+
react: 'React',
12+
'react-dom': 'ReactDOM',
13+
'react-dom/client': 'ReactDOM/client',
14+
},
15+
},
16+
}
17+
18+
export default createEntries({ formats: ['es', 'cjs'], input: 'src/index.ts', config })

npm/react18/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Test React components using Cypress",
55
"main": "dist/cypress-react.cjs.js",
66
"scripts": {
7-
"build": "rimraf dist && rollup -c rollup.config.js",
7+
"build": "rimraf dist && rollup -c rollup.config.mjs",
88
"postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
99
"build-prod": "yarn build",
1010
"watch": "yarn build --watch --watch.exclude ./dist/**/*"

npm/react18/rollup.config.js

-3
This file was deleted.

npm/react18/rollup.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import rollupConfig from '@cypress/react/rollup.config.mjs'
2+
3+
export default rollupConfig

npm/svelte/.eslintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"plugins": [
3+
"cypress"
4+
],
5+
"extends": [
6+
"plugin:@cypress/dev/tests"
7+
],
8+
"env": {
9+
"cypress/globals": true
10+
},
11+
"rules": {
12+
"mocha/no-global-tests": "off",
13+
"no-unused-vars": "off",
14+
"no-console": "off",
15+
"@typescript-eslint/no-unused-vars": "off"
16+
}
17+
}

npm/svelte/.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
save-exact=true
2+
progress=false
3+
package-lock=true

npm/svelte/.releaserc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
...require('../../.releaserc.base'),
3+
branches: [
4+
// this one releases v3 on master on the latest channel
5+
'master',
6+
],
7+
}

npm/svelte/CHANGELOG.md

Whitespace-only changes.

0 commit comments

Comments
 (0)