cypress 16.2.1 → 16.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/angular/dist/index.js +4 -5
  2. package/dist/bin/cypress +8 -8
  3. package/dist/{cli-DoJnc1F1.js → cli-y9Bb9Y77.js} +212 -38
  4. package/dist/cli.js +6 -6
  5. package/dist/{cypress-BTgp4zGi.js → cypress-CvEs5adm.js} +2 -2
  6. package/dist/cypress.js +8 -8
  7. package/dist/exec/spawn.js +4 -4
  8. package/dist/exec/xvfb.js +7 -4
  9. package/dist/index.js +8 -8
  10. package/dist/{spawn-zPuxj7Kz.js → spawn-Bx99tBTm.js} +527 -67
  11. package/dist/{tap-D2mHgoNE.js → tap-BMFGLoCT.js} +108 -26
  12. package/dist/{xvfb-CbW2_YXR.js → xvfb-DxbcANVl.js} +238 -25
  13. package/mount-utils/dist/index.js +1 -0
  14. package/mount-utils/package.json +1 -0
  15. package/package.json +4 -4
  16. package/react/dist/cypress-react.cjs.js +4 -1
  17. package/react/dist/cypress-react.esm-bundler.js +4 -1
  18. package/svelte/dist/cypress-svelte.cjs.js +3 -1
  19. package/svelte/dist/cypress-svelte.esm-bundler.js +3 -1
  20. package/types/cy-bluebird.d.ts +1 -0
  21. package/types/cypress.d.ts +8 -1
  22. package/types/net-stubbing.d.ts +1 -1
  23. package/vue/dist/cypress-vue.cjs.js +3 -0
  24. package/vue/dist/cypress-vue.esm-bundler.js +3 -0
  25. package/vue/dist/index.d.ts +3 -3
  26. package/vue/package.json +1 -1
  27. package/angular/angular/README.md +0 -18
  28. package/angular/angular/dist/index.d.ts +0 -120
  29. package/angular/angular/dist/index.js +0 -478
  30. package/angular/angular/package.json +0 -67
  31. package/mount-utils/mount-utils/README.md +0 -140
  32. package/mount-utils/mount-utils/dist/index.d.ts +0 -12
  33. package/mount-utils/mount-utils/dist/index.js +0 -40
  34. package/mount-utils/mount-utils/package.json +0 -52
  35. package/react/react/README.md +0 -19
  36. package/react/react/dist/cypress-react.cjs.js +0 -292
  37. package/react/react/dist/cypress-react.esm-bundler.js +0 -267
  38. package/react/react/dist/index.d.ts +0 -95
  39. package/react/react/package.json +0 -93
  40. package/svelte/svelte/README.md +0 -19
  41. package/svelte/svelte/dist/cypress-svelte.cjs.js +0 -121
  42. package/svelte/svelte/dist/cypress-svelte.esm-bundler.js +0 -119
  43. package/svelte/svelte/dist/index.d.ts +0 -31
  44. package/svelte/svelte/package.json +0 -65
  45. package/vue/vue/README.md +0 -14
  46. package/vue/vue/dist/cypress-vue.cjs.js +0 -8691
  47. package/vue/vue/dist/cypress-vue.esm-bundler.js +0 -8670
  48. package/vue/vue/dist/index.d.ts +0 -1413
  49. package/vue/vue/package.json +0 -90
@@ -1,267 +0,0 @@
1
-
2
- /**
3
- * @cypress/react v0.0.0-development
4
- * (c) 2026 Cypress.io
5
- * Released under the MIT License
6
- */
7
-
8
- import * as React from 'react';
9
- import ReactDOM from 'react-dom/client';
10
-
11
- /**
12
- * Gets the display name of the component when possible.
13
- * @param type {JSX} The type object returned from creating the react element.
14
- * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
15
- * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
16
- */
17
- function getDisplayName(node, fallbackName = 'Unknown') {
18
- const type = node === null || node === void 0 ? void 0 : node.type;
19
- if (!type) {
20
- return fallbackName;
21
- }
22
- let displayName = null;
23
- // The displayName property is not guaranteed to be a string.
24
- // It's only safe to use for our purposes if it's a string.
25
- // github.com/facebook/react-devtools/issues/803
26
- if (typeof type.displayName === 'string') {
27
- displayName = type.displayName;
28
- }
29
- if (!displayName) {
30
- displayName = type.name || fallbackName;
31
- }
32
- // Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
33
- // We need displayName with module name for error reports but it clutters the DevTools.
34
- const match = displayName.match(/^(.*) \[from (.*)\]$/);
35
- if (match) {
36
- const componentName = match[1];
37
- const moduleName = match[2];
38
- if (componentName && moduleName) {
39
- if (moduleName === componentName ||
40
- moduleName.startsWith(`${componentName}.`)) {
41
- displayName = componentName;
42
- }
43
- }
44
- }
45
- return displayName;
46
- }
47
-
48
- const ROOT_SELECTOR = '[data-cy-root]';
49
- /**
50
- * Gets the root element used to mount the component.
51
- * @returns {HTMLElement} The root element
52
- * @throws {Error} If the root element is not found
53
- */
54
- const getContainerEl = () => {
55
- const el = document.querySelector(ROOT_SELECTOR);
56
- if (el) {
57
- return el;
58
- }
59
- throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please add a root element with data-cy-root attribute to your "component-index.html" file so that Cypress can attach your component to the DOM.`);
60
- };
61
- /**
62
- * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
63
- * @param optionalCallback Callback to be called before the next test runs
64
- */
65
- function setupHooks(optionalCallback) {
66
- // We don't want CT side effects to run when e2e
67
- // testing so we early return.
68
- // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
69
- if (Cypress.testingType !== 'component') {
70
- return;
71
- }
72
- // When running component specs, we cannot allow "cy.visit"
73
- // because it will wipe out our preparation work, and does not make much sense
74
- // thus we overwrite "cy.visit" to throw an error
75
- Cypress.Commands.overwrite('visit', () => {
76
- throw new Error('cy.visit from a component spec is not allowed');
77
- });
78
- Cypress.Commands.overwrite('session', () => {
79
- throw new Error('cy.session from a component spec is not allowed');
80
- });
81
- Cypress.Commands.overwrite('origin', () => {
82
- throw new Error('cy.origin from a component spec is not allowed');
83
- });
84
- Cypress.on('test:before:after:run:async', () => {
85
- optionalCallback?.();
86
- });
87
- }
88
-
89
- let mountCleanup;
90
- /**
91
- * Create an `mount` function. Performs all the non-React-version specific
92
- * behavior related to mounting. The React-version-specific code
93
- * is injected. This helps us to maintain a consistent public API
94
- * and handle breaking changes in React's rendering API.
95
- *
96
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
97
- * or people writing adapters for third-party, custom adapters.
98
- */
99
- const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
100
- if (!internalMountOptions) {
101
- throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
102
- }
103
- mountCleanup = internalMountOptions.cleanup;
104
- return cy
105
- .then(() => {
106
- var _a, _b, _c;
107
- const reactDomToUse = internalMountOptions.reactDom;
108
- const el = getContainerEl();
109
- if (!el) {
110
- throw new Error([
111
- `[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
112
- ].join(' '));
113
- }
114
- const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
115
- // @ts-expect-error - `mocha` is not in the public Cypress types. Provide unique key to the wrapped component to make sure we are rerendering between tests
116
- (((_c = (_b = (_a = Cypress === null || Cypress === void 0 ? void 0 : Cypress.mocha) === null || _a === void 0 ? void 0 : _a.getRunner()) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.title) || '') + Math.random();
117
- const props = {
118
- key,
119
- };
120
- const reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
121
- // since we always surround the component with a fragment
122
- // let's get back the original component
123
- const userComponent = reactComponent.props.children;
124
- internalMountOptions.render(reactComponent, el, reactDomToUse);
125
- return (cy.wrap(userComponent, { log: false })
126
- .then(() => {
127
- return cy.wrap({
128
- component: userComponent,
129
- rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
130
- }, { log: false });
131
- })
132
- // by waiting, we delaying test execution for the next tick of event loop
133
- // and letting hooks and component lifecycle methods to execute mount
134
- // https://github.com/bahmutov/cypress-react-unit-test/issues/200
135
- .wait(0, { log: false })
136
- .then(() => {
137
- if (options.log !== false) {
138
- // Get the display name property via the component constructor
139
- const componentName = getDisplayName(jsx);
140
- const jsxComponentName = `<${componentName} ... />`;
141
- Cypress.log({
142
- name: type,
143
- type: 'parent',
144
- message: [jsxComponentName],
145
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- @ts-expect-error would be unused once the cli typedefs are generated
146
- // @ts-ignore - JQuery comes from cli/types/jquery, which is generated by the cli build and missing when this package builds first
147
- $el: el.children.item(0),
148
- consoleProps: () => {
149
- return {
150
- // @ts-expect-error - `props` is not on every `ReactNode` member, such as string
151
- props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
152
- description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
153
- home: 'https://github.com/cypress-io/cypress',
154
- };
155
- },
156
- });
157
- }
158
- }));
159
- // Bluebird types are terrible. I don't think the return type can be carried without this cast
160
- });
161
- };
162
- /**
163
- * Create an `unmount` function. Performs all the non-React-version specific
164
- * behavior related to unmounting.
165
- *
166
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
167
- * or people writing adapters for third-party, custom adapters.
168
- *
169
- * @param {UnmountArgs} options used during unmounting
170
- */
171
- const makeUnmountFn = (options) => {
172
- return cy.then(() => {
173
- var _a;
174
- const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
175
- if (wasUnmounted && options.log) {
176
- Cypress.log({
177
- name: 'unmount',
178
- type: 'parent',
179
- message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
180
- consoleProps: () => {
181
- return {
182
- description: 'Unmounts React component',
183
- parent: getContainerEl().parentNode,
184
- home: 'https://github.com/cypress-io/cypress',
185
- };
186
- },
187
- });
188
- }
189
- });
190
- };
191
- // Cleanup before each run
192
- // NOTE: we cannot use unmount here because
193
- // we are not in the context of a test
194
- const preMountCleanup = () => {
195
- mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
196
- };
197
- const _mount = (jsx, options = {}) => makeMountFn('mount', jsx, options);
198
- const createMount = (defaultOptions) => {
199
- return (element, options) => {
200
- return _mount(element, Object.assign(Object.assign({}, defaultOptions), options));
201
- };
202
- };
203
- // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
204
- // by creating an explicit function/import that the user can register in their 'component.js' support file,
205
- // such as:
206
- // import 'cypress/<my-framework>/support'
207
- // or
208
- // import { registerCT } from 'cypress/<my-framework>'
209
- // registerCT()
210
- // Note: This would be a breaking change
211
- // it is required to unmount component in beforeEach hook in order to provide a clean state inside test
212
- // because `mount` can be called after some preparation that can side effect unmount
213
- // @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator.cy.tsx
214
- setupHooks(preMountCleanup);
215
-
216
- let root;
217
- const cleanup = () => {
218
- if (root) {
219
- root.unmount();
220
- root = null;
221
- return true;
222
- }
223
- return false;
224
- };
225
- /**
226
- * Mounts a React component into the DOM.
227
- * @param {import('react').JSX.Element} jsx The React component to mount.
228
- * @param {MountOptions} options Options to pass to the mount function.
229
- * @param {string} rerenderKey A key to use to force a rerender.
230
- *
231
- * @example
232
- * import { mount } from '@cypress/react'
233
- * import { Stepper } from './Stepper'
234
- *
235
- * it('mounts', () => {
236
- * mount(<StepperComponent />)
237
- * cy.get('[data-cy=increment]').click()
238
- * cy.get('[data-cy=counter]').should('have.text', '1')
239
- * }
240
- *
241
- * @see {@link https://on.cypress.io/mounting-react} for more details.
242
- *
243
- * @returns {Cypress.Chainable<MountReturn>} The mounted component.
244
- */
245
- function mount(jsx, options = {}, rerenderKey) {
246
- // Remove last mounted component if cy.mount is called more than once in a test
247
- // React by default removes the last component when calling render, but we should remove the root
248
- // to wipe away any state
249
- cleanup();
250
- const internalOptions = {
251
- reactDom: ReactDOM,
252
- render: (reactComponent, el) => {
253
- if (!root) {
254
- root = ReactDOM.createRoot(el);
255
- }
256
- return root.render(reactComponent);
257
- },
258
- unmount: internalUnmount,
259
- cleanup,
260
- };
261
- return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
262
- }
263
- function internalUnmount(options = { log: true }) {
264
- return makeUnmountFn(options);
265
- }
266
-
267
- export { createMount, getContainerEl, makeMountFn, makeUnmountFn, mount };
@@ -1,95 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- import * as React from 'react';
4
- import React__default from 'react';
5
- import * as react_dom_client from 'react-dom/client';
6
-
7
- interface UnmountArgs {
8
- log: boolean;
9
- boundComponentMessage?: string;
10
- }
11
- type MountOptions = Partial<MountReactComponentOptions>;
12
- interface MountReactComponentOptions {
13
- ReactDom: typeof react_dom_client;
14
- /**
15
- * Log the mounting command into Cypress Command Log,
16
- * true by default.
17
- */
18
- log: boolean;
19
- /**
20
- * Render component in React [strict mode](https://reactjs.org/docs/strict-mode.html)
21
- * It activates additional checks and warnings for child components.
22
- */
23
- strict: boolean;
24
- }
25
- interface InternalMountOptions {
26
- reactDom: typeof react_dom_client;
27
- render: (reactComponent: ReturnType<typeof React__default.createElement>, el: HTMLElement, reactDomToUse: typeof react_dom_client) => void;
28
- unmount: (options: UnmountArgs) => void;
29
- cleanup: () => boolean;
30
- }
31
- interface MountReturn {
32
- /**
33
- * The component that was rendered.
34
- */
35
- component: React__default.ReactNode;
36
- /**
37
- * Rerenders the specified component with new props. This allows testing of components that store state (`setState`)
38
- * or have asynchronous updates (`useEffect`, `useLayoutEffect`).
39
- */
40
- rerender: (component: React__default.ReactNode) => globalThis.Cypress.Chainable<MountReturn>;
41
- }
42
-
43
- /**
44
- * Create an `mount` function. Performs all the non-React-version specific
45
- * behavior related to mounting. The React-version-specific code
46
- * is injected. This helps us to maintain a consistent public API
47
- * and handle breaking changes in React's rendering API.
48
- *
49
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
50
- * or people writing adapters for third-party, custom adapters.
51
- */
52
- declare const makeMountFn: (type: 'mount' | 'rerender', jsx: React.ReactNode, options?: MountOptions, rerenderKey?: string, internalMountOptions?: InternalMountOptions) => globalThis.Cypress.Chainable<MountReturn>;
53
- /**
54
- * Create an `unmount` function. Performs all the non-React-version specific
55
- * behavior related to unmounting.
56
- *
57
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
58
- * or people writing adapters for third-party, custom adapters.
59
- *
60
- * @param {UnmountArgs} options used during unmounting
61
- */
62
- declare const makeUnmountFn: (options: UnmountArgs) => Cypress.Chainable<undefined>;
63
- declare const createMount: (defaultOptions: MountOptions) => (element: React.ReactElement, options?: MountOptions) => Cypress.Chainable<MountReturn>;
64
-
65
- /**
66
- * Gets the root element used to mount the component.
67
- * @returns {HTMLElement} The root element
68
- * @throws {Error} If the root element is not found
69
- */
70
- declare const getContainerEl: () => HTMLElement;
71
-
72
- /**
73
- * Mounts a React component into the DOM.
74
- * @param {import('react').JSX.Element} jsx The React component to mount.
75
- * @param {MountOptions} options Options to pass to the mount function.
76
- * @param {string} rerenderKey A key to use to force a rerender.
77
- *
78
- * @example
79
- * import { mount } from '@cypress/react'
80
- * import { Stepper } from './Stepper'
81
- *
82
- * it('mounts', () => {
83
- * mount(<StepperComponent />)
84
- * cy.get('[data-cy=increment]').click()
85
- * cy.get('[data-cy=counter]').should('have.text', '1')
86
- * }
87
- *
88
- * @see {@link https://on.cypress.io/mounting-react} for more details.
89
- *
90
- * @returns {Cypress.Chainable<MountReturn>} The mounted component.
91
- */
92
- declare function mount(jsx: React__default.ReactNode, options?: MountOptions, rerenderKey?: string): Cypress.Chainable<MountReturn>;
93
-
94
- export { createMount, getContainerEl, makeMountFn, makeUnmountFn, mount };
95
- export type { InternalMountOptions, MountOptions, MountReactComponentOptions, MountReturn, UnmountArgs };
@@ -1,93 +0,0 @@
1
- {
2
- "name": "@cypress/react",
3
- "version": "0.0.0-development",
4
- "description": "Test React components using Cypress",
5
- "keywords": [
6
- "cypress",
7
- "react",
8
- "component-testing",
9
- "react-testing",
10
- "testing",
11
- "react-component",
12
- "jsx"
13
- ],
14
- "homepage": "https://github.com/cypress-io/cypress/blob/develop/npm/react/#readme",
15
- "bugs": "https://github.com/cypress-io/cypress/issues/new?assignees=&labels=npm%3A%20%40cypress%2Freact&template=1-bug-report.md&title=",
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/cypress-io/cypress.git"
19
- },
20
- "license": "MIT",
21
- "main": "dist/cypress-react.cjs.js",
22
- "unpkg": "dist/cypress-react.browser.js",
23
- "module": "dist/cypress-react.esm-bundler.js",
24
- "types": "dist/index.d.ts",
25
- "files": [
26
- "dist"
27
- ],
28
- "scripts": {
29
- "build": "rimraf dist && rollup -c rollup.config.mjs",
30
- "postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
31
- "check-ts": "tsc --noEmit && tsc --noEmit -p cypress/tsconfig.json && tsc --noEmit -p tsconfig.cypress.json",
32
- "cy:open": "node ../../scripts/cypress.js open --component",
33
- "cy:open:debug": "node --inspect-brk ../../scripts/start.js --component-testing --run-project ${PWD}",
34
- "cy:run": "node ../../scripts/cypress.js run --component",
35
- "cy:run:debug": "node --inspect-brk ../../scripts/start.js --component-testing --run-project ${PWD}",
36
- "lint": "eslint",
37
- "test": "yarn cy:run",
38
- "watch": "yarn build --watch --watch.exclude ./dist/**/*"
39
- },
40
- "lint-staged": {
41
- "**/*.{js,jsx,ts,tsx,json}": "eslint --fix"
42
- },
43
- "devDependencies": {
44
- "@cypress/mount-utils": "0.0.0-development",
45
- "@packages/eslint-config": "0.0.0-development",
46
- "@testing-library/cypress": "10.1.3",
47
- "@vitejs/plugin-react": "4.6.0",
48
- "axios": "^1.20.0",
49
- "cypress": "0.0.0-development",
50
- "eslint": "^9.31.0",
51
- "jiti": "^2.4.2",
52
- "prop-types": "15.8.1",
53
- "react": "18.3.1",
54
- "react-dom": "18.3.1",
55
- "react-router": "6.28.0",
56
- "react-router-dom": "6.28.0",
57
- "rollup": "^4.60.2",
58
- "typescript": "~5.4.5",
59
- "vite": "^8.0.9"
60
- },
61
- "peerDependencies": {
62
- "@types/react": "^18 || ^19",
63
- "@types/react-dom": "^18 || ^19",
64
- "cypress": "*",
65
- "react": "^18 || ^19",
66
- "react-dom": "^18 || ^19"
67
- },
68
- "peerDependenciesMeta": {
69
- "@types/react": {
70
- "optional": true
71
- }
72
- },
73
- "publishConfig": {
74
- "access": "public"
75
- },
76
- "nx": {
77
- "targets": {
78
- "build": {
79
- "outputs": [
80
- "{workspaceRoot}/cli/react",
81
- "{projectRoot}/dist"
82
- ]
83
- }
84
- }
85
- },
86
- "standard": {
87
- "globals": [
88
- "Cypress",
89
- "cy",
90
- "expect"
91
- ]
92
- }
93
- }
@@ -1,19 +0,0 @@
1
- # @cypress/svelte
2
-
3
- Mount Svelte components in the open source [Cypress.io](https://www.cypress.io/) test runner
4
-
5
- > **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [Svelte Component Testing Docs](https://docs.cypress.io/guides/component-testing/svelte/overview) for mounting Svelte components. Installing and importing `mount` from `@cypress/svelte` should only be done for advanced use-cases or in the case you may require an older or non supported version of svelte.
6
-
7
- ## Requirements
8
-
9
- - Svelte 5+ (Cypress 13 and under supports Svelte 4 and under)
10
-
11
- ## Development
12
-
13
- Run `yarn build` to compile and sync packages to the `cypress` cli package.
14
-
15
- Run `yarn cy:open` to open Cypress component testing against real-world examples.
16
-
17
- Run `yarn test` to execute headless Cypress tests.
18
-
19
- ## [Changelog](./CHANGELOG.md)
@@ -1,121 +0,0 @@
1
-
2
- /**
3
- * @cypress/svelte v0.0.0-development
4
- * (c) 2026 Cypress.io
5
- * Released under the MIT License
6
- */
7
-
8
- 'use strict';
9
-
10
- var svelte = require('svelte');
11
-
12
- const ROOT_SELECTOR = '[data-cy-root]';
13
- /**
14
- * Gets the root element used to mount the component.
15
- * @returns {HTMLElement} The root element
16
- * @throws {Error} If the root element is not found
17
- */
18
- const getContainerEl = () => {
19
- const el = document.querySelector(ROOT_SELECTOR);
20
- if (el) {
21
- return el;
22
- }
23
- throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please add a root element with data-cy-root attribute to your "component-index.html" file so that Cypress can attach your component to the DOM.`);
24
- };
25
- /**
26
- * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
27
- * @param optionalCallback Callback to be called before the next test runs
28
- */
29
- function setupHooks(optionalCallback) {
30
- // We don't want CT side effects to run when e2e
31
- // testing so we early return.
32
- // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
33
- if (Cypress.testingType !== 'component') {
34
- return;
35
- }
36
- // When running component specs, we cannot allow "cy.visit"
37
- // because it will wipe out our preparation work, and does not make much sense
38
- // thus we overwrite "cy.visit" to throw an error
39
- Cypress.Commands.overwrite('visit', () => {
40
- throw new Error('cy.visit from a component spec is not allowed');
41
- });
42
- Cypress.Commands.overwrite('session', () => {
43
- throw new Error('cy.session from a component spec is not allowed');
44
- });
45
- Cypress.Commands.overwrite('origin', () => {
46
- throw new Error('cy.origin from a component spec is not allowed');
47
- });
48
- Cypress.on('test:before:after:run:async', () => {
49
- optionalCallback?.();
50
- });
51
- }
52
-
53
- const DEFAULT_COMP_NAME = 'unknown';
54
- let componentInstance;
55
- const cleanup = () => {
56
- if (componentInstance) {
57
- svelte.unmount(componentInstance);
58
- }
59
- };
60
- // Extract the component name from the object passed to mount
61
- const getComponentDisplayName = (Component) => {
62
- if (Component.name) {
63
- const [, match] = /Proxy\<(\w+)\>/.exec(Component.name) || [];
64
- return match || Component.name;
65
- }
66
- return DEFAULT_COMP_NAME;
67
- };
68
- /**
69
- * Mounts a Svelte component inside the Cypress browser
70
- *
71
- * @param {Record<string, any>} Component Svelte component being mounted
72
- * @param {MountReturn<T extends SvelteComponent>} options options to customize the component being mounted
73
- * @returns Cypress.Chainable<MountReturn>
74
- *
75
- * @example
76
- * import Counter from './Counter.svelte'
77
- * import { mount } from 'cypress/svelte'
78
- *
79
- * it('should render', () => {
80
- * mount(Counter, { props: { count: 42 } })
81
- * cy.get('button').contains(42)
82
- * })
83
- *
84
- * @see {@link https://on.cypress.io/mounting-svelte} for more details.
85
- */
86
- function mount(Component, options = {}) {
87
- // In Svelte 5, the component name is no longer easily discoverable and logs as "wrapper"
88
- // so we default the logging of it to false as it doesn't provide a lot of value
89
- options.log = options.log || false;
90
- return cy.then(() => {
91
- // Remove last mounted component if cy.mount is called more than once in a test
92
- cleanup();
93
- const target = getContainerEl();
94
- const ComponentConstructor = (Component.default || Component);
95
- // @see https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes
96
- componentInstance = svelte.mount(ComponentConstructor, Object.assign({ target }, options));
97
- // by waiting, we are delaying test execution for the next tick of event loop
98
- // and letting hooks and component lifecycle methods to execute mount
99
- return cy.wait(0, { log: false }).then(() => {
100
- if (options.log !== false) {
101
- const mountMessage = `<${getComponentDisplayName(Component)} ... />`;
102
- Cypress.log({
103
- name: 'mount',
104
- message: [mountMessage],
105
- });
106
- }
107
- })
108
- .wrap({ component: componentInstance }, { log: false });
109
- });
110
- }
111
- // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
112
- // by creating an explicit function/import that the user can register in their 'component.js' support file,
113
- // such as:
114
- // import 'cypress/<my-framework>/support'
115
- // or
116
- // import { registerCT } from 'cypress/<my-framework>'
117
- // registerCT()
118
- // Note: This would be a breaking change
119
- setupHooks(cleanup);
120
-
121
- exports.mount = mount;