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
@@ -61,6 +61,7 @@ const getContainerEl = () => {
61
61
  * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
62
62
  * @param optionalCallback Callback to be called before the next test runs
63
63
  */
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- published API; narrowing the parameter would break callers that pass a `Function`
64
65
  function setupHooks(optionalCallback) {
65
66
  // We don't want CT side effects to run when e2e
66
67
  // testing so we early return.
@@ -8580,6 +8581,7 @@ const cleanup = () => {
8580
8581
  Cypress.vueWrapper = null;
8581
8582
  Cypress.vue = null;
8582
8583
  };
8584
+ /* eslint-enable @typescript-eslint/no-empty-object-type */
8583
8585
  /**
8584
8586
  * Mounts a component and returns an object containing the component and VueWrapper
8585
8587
  * @param componentOptions
@@ -8618,6 +8620,7 @@ function mount(componentOptions, options = {}) {
8618
8620
  const wrapper = VTUmount(componentOptions, Object.assign({ attachTo: componentNode }, options));
8619
8621
  Cypress.vueWrapper = wrapper;
8620
8622
  Cypress.vue = wrapper.vm;
8623
+ // eslint-disable-next-line cypress/no-unnecessary-waiting -- yields so the component's lifecycle hooks run before the test continues
8621
8624
  return cy
8622
8625
  .wait(1, { log: false })
8623
8626
  .then(() => {
@@ -1392,11 +1392,11 @@ declare function mount<T extends DefineComponent<any, any, any, any, any>>(compo
1392
1392
  wrapper: VueWrapper<InstanceType<T>>;
1393
1393
  component: VueWrapper<InstanceType<T>>['vm'];
1394
1394
  }>;
1395
- declare function mount<Props = {}, RawBindings = {}, D extends {} = {}, C extends ComputedOptions = {}, M extends Record<string, Function> = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string>(componentOptions: ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, Mixin, Extends, EE>, options?: MountingOptions<Props & PublicProps, D>): Cypress.Chainable<{
1395
+ declare function mount<Props = {}, RawBindings = {}, D extends {} = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string>(componentOptions: ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, Mixin, Extends, EE>, options?: MountingOptions<Props & PublicProps, D>): Cypress.Chainable<{
1396
1396
  wrapper: VueWrapper<ComponentPublicInstance<Props, RawBindings, D, C, M, E, VNodeProps & Props>> & Record<string, any>;
1397
1397
  component: VueWrapper<ComponentPublicInstance<Props, RawBindings, D, C, M, E, VNodeProps & Props>> & Record<string, any>['vm'];
1398
1398
  }>;
1399
- declare function mount<PropNames extends string, RawBindings, D extends {}, C extends ComputedOptions = {}, M extends Record<string, Function> = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string, Props extends Readonly<{
1399
+ declare function mount<PropNames extends string, RawBindings, D extends {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string, Props extends Readonly<{
1400
1400
  [key in PropNames]?: any;
1401
1401
  }> = Readonly<{
1402
1402
  [key in PropNames]?: any;
@@ -1404,7 +1404,7 @@ declare function mount<PropNames extends string, RawBindings, D extends {}, C ex
1404
1404
  wrapper: VueWrapper<ComponentPublicInstance<Props, RawBindings, D, C, M, E>>;
1405
1405
  component: VueWrapper<ComponentPublicInstance<Props, RawBindings, D, C, M, E>>['vm'];
1406
1406
  }>;
1407
- declare function mount<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D extends {}, C extends ComputedOptions = {}, M extends Record<string, Function> = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string>(componentOptions: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, Mixin, Extends, EE>, options?: MountingOptions<ExtractPropTypes<PropsOptions> & PublicProps, D>): Cypress.Chainable<{
1407
+ declare function mount<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D extends {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string>(componentOptions: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, Mixin, Extends, EE>, options?: MountingOptions<ExtractPropTypes<PropsOptions> & PublicProps, D>): Cypress.Chainable<{
1408
1408
  wrapper: VueWrapper<ComponentPublicInstance<ExtractPropTypes<PropsOptions>, RawBindings, D, C, M, E, VNodeProps & ExtractPropTypes<PropsOptions>>>;
1409
1409
  component: VueWrapper<ComponentPublicInstance<ExtractPropTypes<PropsOptions>, RawBindings, D, C, M, E, VNodeProps & ExtractPropTypes<PropsOptions>>>['vm'];
1410
1410
  }>;
package/vue/package.json CHANGED
@@ -55,7 +55,7 @@
55
55
  "typescript": "~5.4.5",
56
56
  "vite": "^8.0.9",
57
57
  "vue": "3.2.47",
58
- "vue-eslint-parser": "^10.0.0",
58
+ "vue-eslint-parser": "^10.4.2",
59
59
  "vue-i18n": "9.14.5",
60
60
  "vue-router": "^4.0.0",
61
61
  "vue-tsc": "^2.0.19",
@@ -1,18 +0,0 @@
1
- # @cypress/angular
2
-
3
- Mount Angular 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 [Angular Component Testing Docs](https://docs.cypress.io/guides/component-testing/angular/overview) for mounting Angular components. Installing and importing `mount` from `@cypress/angular` should only be done for advanced use-cases.
6
-
7
- ## Requirements
8
-
9
- - Angular `>=21.0.0`
10
- - `@cypress/angular@4` supports Angular 18 - 19
11
- - `@cypress/angular@3` supports Angular 17
12
- - `@cypress/angular@2` supports Angular 13 - 16
13
-
14
- ## Development
15
-
16
- Run `yarn build` to compile and sync packages to the `cypress` cli package.
17
-
18
- ## [Changelog](./CHANGELOG.md)
@@ -1,120 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- import { InputSignal, WritableSignal, Type } from '@angular/core';
4
- import { TestComponentRenderer, TestModuleMetadata, ComponentFixture } from '@angular/core/testing';
5
-
6
- /**
7
- * Additional module configurations needed while mounting the component, like
8
- * providers, declarations, imports and even component @Inputs()
9
- *
10
- * @interface MountConfig
11
- * @see https://angular.io/api/core/testing/TestModuleMetadata
12
- */
13
- interface MountConfig<T> extends TestModuleMetadata {
14
- /**
15
- * @memberof MountConfig
16
- * @example
17
- * import { ButtonComponent } from 'button/button.component'
18
- * it('renders a button with Save text', () => {
19
- * cy.mount(ButtonComponent, { componentProperties: { text: 'Save' }})
20
- * cy.get('button').contains('Save')
21
- * })
22
- *
23
- * it('renders a button with a cy.spy() replacing EventEmitter', () => {
24
- * cy.mount(ButtonComponent, {
25
- * componentProperties: {
26
- * clicked: cy.spy().as('mySpy)
27
- * }
28
- * })
29
- * cy.get('button').click()
30
- * cy.get('@mySpy').should('have.been.called')
31
- * })
32
- */
33
- componentProperties?: Partial<{
34
- [P in keyof T]: T[P] extends InputSignal<infer V> ? InputSignal<V> | WritableSignal<V> | V : T[P];
35
- }>;
36
- }
37
- /**
38
- * Type that the `mount` function returns
39
- * @type MountResponse<T>
40
- */
41
- type MountResponse<T> = {
42
- /**
43
- * Fixture for debugging and testing a component.
44
- *
45
- * @memberof MountResponse
46
- * @see https://angular.io/api/core/testing/ComponentFixture
47
- */
48
- fixture: ComponentFixture<T>;
49
- /**
50
- * The instance of the root component class
51
- *
52
- * @memberof MountResponse
53
- * @see https://angular.io/api/core/testing/ComponentFixture#componentInstance
54
- */
55
- component: T;
56
- };
57
- declare class CypressTestComponentRenderer extends TestComponentRenderer {
58
- insertRootElement(rootElId: string): void;
59
- removeAllRootElements(): void;
60
- }
61
- /**
62
- * Mounts an Angular component inside Cypress browser
63
- *
64
- * @param component Angular component being mounted or its template
65
- * @param config configuration used to configure the TestBed
66
- * @example
67
- * import { mount } from '@cypress/angular'
68
- * import { StepperComponent } from './stepper.component'
69
- * import { MyService } from 'services/my.service'
70
- * import { SharedModule } from 'shared/shared.module';
71
- * it('mounts', () => {
72
- * mount(StepperComponent, {
73
- * providers: [MyService],
74
- * imports: [SharedModule]
75
- * })
76
- * cy.get('[data-cy=increment]').click()
77
- * cy.get('[data-cy=counter]').should('have.text', '1')
78
- * })
79
- *
80
- * // or
81
- *
82
- * it('mounts with template', () => {
83
- * mount('<app-stepper></app-stepper>', {
84
- * declarations: [StepperComponent],
85
- * })
86
- * })
87
- *
88
- * @see {@link https://on.cypress.io/mounting-angular} for more details.
89
- *
90
- * @returns A component and component fixture
91
- */
92
- declare function mount<T>(component: Type<T> | string, config?: MountConfig<T>): Cypress.Chainable<MountResponse<T>>;
93
- /**
94
- * Creates a new Event Emitter and then spies on it's `emit` method
95
- *
96
- * @param {string} alias name you want to use for your cy.spy() alias
97
- * @returns EventEmitter<T>
98
- * @example
99
- * import { StepperComponent } from './stepper.component'
100
- * import { mount, createOutputSpy } from '@cypress/angular'
101
- *
102
- * it('Has spy', () => {
103
- * mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
104
- * cy.get('[data-cy=increment]').click()
105
- * cy.get('@changeSpy').should('have.been.called')
106
- * })
107
- *
108
- * // Or for use with Angular Signals following the output nomenclature.
109
- * // see https://v17.angular.io/guide/model-inputs#differences-between-model-and-input/
110
- *
111
- * it('Has spy', () => {
112
- * mount(StepperComponent, { componentProperties: { count: signal(0), countChange: createOutputSpy('countChange') } })
113
- * cy.get('[data-cy=increment]').click()
114
- * cy.get('@countChange').should('have.been.called')
115
- * })
116
- */
117
- declare const createOutputSpy: <T>(alias: string) => any;
118
-
119
- export { CypressTestComponentRenderer, createOutputSpy, mount };
120
- export type { MountConfig, MountResponse };
@@ -1,478 +0,0 @@
1
-
2
- /**
3
- * @cypress/angular v0.0.0-development
4
- * (c) 2026 Cypress.io
5
- * Released under the MIT License
6
- */
7
-
8
- import { CommonModule } from '@angular/common';
9
- import { Injectable, Component, EventEmitter, ErrorHandler, provideZonelessChangeDetection, SimpleChange } from '@angular/core';
10
- import { toObservable } from '@angular/core/rxjs-interop';
11
- import { getTestBed, TestComponentRenderer, TestBed } from '@angular/core/testing';
12
- import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
13
-
14
- /******************************************************************************
15
- Copyright (c) Microsoft Corporation.
16
-
17
- Permission to use, copy, modify, and/or distribute this software for any
18
- purpose with or without fee is hereby granted.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
- PERFORMANCE OF THIS SOFTWARE.
27
- ***************************************************************************** */
28
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
29
-
30
-
31
- function __rest(s, e) {
32
- var t = {};
33
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
34
- t[p] = s[p];
35
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
36
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
- t[p[i]] = s[p[i]];
39
- }
40
- return t;
41
- }
42
-
43
- function __decorate(decorators, target, key, desc) {
44
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
45
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
46
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- }
49
-
50
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
51
- var e = new Error(message);
52
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
- };
54
-
55
- const ROOT_SELECTOR = '[data-cy-root]';
56
- /**
57
- * Gets the root element used to mount the component.
58
- * @returns {HTMLElement} The root element
59
- * @throws {Error} If the root element is not found
60
- */
61
- const getContainerEl = () => {
62
- const el = document.querySelector(ROOT_SELECTOR);
63
- if (el) {
64
- return el;
65
- }
66
- 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.`);
67
- };
68
- /**
69
- * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
70
- * @param optionalCallback Callback to be called before the next test runs
71
- */
72
- function setupHooks(optionalCallback) {
73
- // We don't want CT side effects to run when e2e
74
- // testing so we early return.
75
- // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
76
- if (Cypress.testingType !== 'component') {
77
- return;
78
- }
79
- // When running component specs, we cannot allow "cy.visit"
80
- // because it will wipe out our preparation work, and does not make much sense
81
- // thus we overwrite "cy.visit" to throw an error
82
- Cypress.Commands.overwrite('visit', () => {
83
- throw new Error('cy.visit from a component spec is not allowed');
84
- });
85
- Cypress.Commands.overwrite('session', () => {
86
- throw new Error('cy.session from a component spec is not allowed');
87
- });
88
- Cypress.Commands.overwrite('origin', () => {
89
- throw new Error('cy.origin from a component spec is not allowed');
90
- });
91
- Cypress.on('test:before:after:run:async', () => {
92
- optionalCallback?.();
93
- });
94
- }
95
-
96
- let activeFixture = null;
97
- let activeInternalSubscriptions = [];
98
- function cleanup() {
99
- // Not public, we need to call this to remove the last component from the DOM
100
- try {
101
- getTestBed().tearDownTestingModule();
102
- }
103
- catch (e) {
104
- const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`);
105
- notSupportedError.docsUrl = 'https://on.cypress.io/frameworks';
106
- throw notSupportedError;
107
- }
108
- // clean up internal subscriptions if any exist. We use this for two-way data binding for
109
- // signal() models
110
- activeInternalSubscriptions.forEach((subscription) => {
111
- subscription.unsubscribe();
112
- });
113
- getTestBed().resetTestingModule();
114
- activeFixture = null;
115
- activeInternalSubscriptions = [];
116
- }
117
- let CypressAngularErrorHandler = class CypressAngularErrorHandler {
118
- handleError(error) {
119
- throw error;
120
- }
121
- };
122
- CypressAngularErrorHandler = __decorate([
123
- Injectable()
124
- ], CypressAngularErrorHandler);
125
- /**
126
- * Bootstraps the TestModuleMetaData passed to the TestBed
127
- *
128
- * @param {Type<T>} component Angular component being mounted
129
- * @param {MountConfig} config TestBed configuration passed into the mount function
130
- * @returns {MountConfig} MountConfig
131
- */
132
- function bootstrapModule(component, config) {
133
- var _a;
134
- const { componentProperties } = config, testModuleMetaData = __rest(config, ["componentProperties"]);
135
- if (!testModuleMetaData.declarations) {
136
- testModuleMetaData.declarations = [];
137
- }
138
- if (!testModuleMetaData.imports) {
139
- testModuleMetaData.imports = [];
140
- }
141
- if (!testModuleMetaData.providers) {
142
- testModuleMetaData.providers = [];
143
- }
144
- // Replace default error handler since it will swallow uncaught exceptions.
145
- // We want these to be uncaught so Cypress catches it and fails the test
146
- testModuleMetaData.providers.push({
147
- provide: ErrorHandler,
148
- useClass: CypressAngularErrorHandler,
149
- });
150
- // allow for zoneless change detection inside the testing module.
151
- // @see https://angular.dev/guide/zoneless#using-zoneless-in-testbed
152
- testModuleMetaData.providers.push(provideZonelessChangeDetection());
153
- // check if the component is a standalone component
154
- if ((_a = component.ɵcmp) === null || _a === void 0 ? void 0 : _a.standalone) {
155
- testModuleMetaData.imports.push(component);
156
- }
157
- else {
158
- testModuleMetaData.declarations.push(component);
159
- }
160
- if (!testModuleMetaData.imports.includes(CommonModule)) {
161
- testModuleMetaData.imports.push(CommonModule);
162
- }
163
- return testModuleMetaData;
164
- }
165
- let CypressTestComponentRenderer = class CypressTestComponentRenderer extends TestComponentRenderer {
166
- insertRootElement(rootElId) {
167
- this.removeAllRootElements();
168
- const rootElement = getContainerEl();
169
- rootElement.setAttribute('id', rootElId);
170
- }
171
- removeAllRootElements() {
172
- getContainerEl().innerHTML = '';
173
- }
174
- };
175
- CypressTestComponentRenderer = __decorate([
176
- Injectable()
177
- ], CypressTestComponentRenderer);
178
- /**
179
- * Initializes the TestBed
180
- *
181
- * @param {Type<T> | string} component Angular component being mounted or its template
182
- * @param {MountConfig} config TestBed configuration passed into the mount function
183
- * @returns {Type<T>} componentFixture
184
- */
185
- function initTestBed(component, config) {
186
- const componentFixture = createComponentFixture(component);
187
- getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, config)));
188
- getTestBed().overrideProvider(TestComponentRenderer, { useValue: new CypressTestComponentRenderer() });
189
- return componentFixture;
190
- }
191
- // if using the Wrapper Component (template strings), the component itself cannot be
192
- // a standalone component
193
- let WrapperComponent = class WrapperComponent {
194
- };
195
- WrapperComponent = __decorate([
196
- Component({ selector: 'cy-wrapper-component', template: '', standalone: false })
197
- ], WrapperComponent);
198
- /**
199
- * Returns the Component if Type<T> or creates a WrapperComponent
200
- *
201
- * @param {Type<T> | string} component The component you want to create a fixture of
202
- * @returns {Type<T> | WrapperComponent}
203
- */
204
- function createComponentFixture(component) {
205
- if (typeof component === 'string') {
206
- // getTestBed().overrideTemplate is available in v14+
207
- // The static TestBed.overrideTemplate is available across versions
208
- TestBed.overrideTemplate(WrapperComponent, component);
209
- return WrapperComponent;
210
- }
211
- return component;
212
- }
213
- /**
214
- * Creates the ComponentFixture
215
- *
216
- * @param {Type<T>} component Angular component being mounted
217
- * @param {MountConfig<T>} config MountConfig
218
-
219
- * @returns {Promise<ComponentFixture<T>>} ComponentFixture
220
- */
221
- function setupFixture(component, config) {
222
- const fixture = getTestBed().createComponent(component);
223
- setupComponent(config, fixture);
224
- return fixture;
225
- }
226
- // Best known way to currently detect whether or not a function is a signal is if the signal symbol exists.
227
- // From there, we can take our best guess based on what exists on the object itself.
228
- // @see https://github.com/cypress-io/cypress/issues/29731.
229
- function isSignal(prop) {
230
- try {
231
- const symbol = Object.getOwnPropertySymbols(prop).find((symbol) => symbol.toString() === 'Symbol(SIGNAL)');
232
- return !!symbol;
233
- }
234
- catch (e) {
235
- // likely a primitive type, object, array, or something else (i.e. not a signal).
236
- // We can return false here.
237
- return false;
238
- }
239
- }
240
- // currently not a great way to detect if a function is an InputSignal.
241
- // @see https://github.com/cypress-io/cypress/issues/29731.
242
- function isInputSignal(prop) {
243
- return isSignal(prop) && typeof prop === 'function' && prop['name'] === 'inputValueFn';
244
- }
245
- // currently not a great way to detect if a function is a Model Signal.
246
- // @see https://github.com/cypress-io/cypress/issues/29731.
247
- function isModelSignal(prop) {
248
- return isSignal(prop) && isWritableSignal(prop) && typeof prop.subscribe === 'function';
249
- }
250
- // currently not a great way to detect if a function is a Writable Signal.
251
- // @see https://github.com/cypress-io/cypress/issues/29731.
252
- function isWritableSignal(prop) {
253
- return isSignal(prop) && typeof prop === 'function' && typeof prop.set === 'function';
254
- }
255
- function registerSignalEventsIfNeeded(propKey, propValue, componentValue, injector, fixture) {
256
- const isPropValueASignal = isSignal(propValue);
257
- if (isPropValueASignal) {
258
- // propValue -> componentValue
259
- const convertedToObservable = toObservable(propValue, {
260
- injector,
261
- });
262
- // push the subscription into an array to be cleaned up at the end of the test
263
- // to prevent a memory leak
264
- activeInternalSubscriptions.push(convertedToObservable.subscribe((value) => {
265
- // keep the component up to date as prop signal changes
266
- fixture.componentRef.setInput(propKey, value);
267
- }));
268
- }
269
- const isComponentValueAModelSignal = isModelSignal(componentValue);
270
- if (isPropValueASignal && isComponentValueAModelSignal) {
271
- // propValue <- componentValue
272
- const modelChanged$ = toObservable(componentValue, {
273
- injector,
274
- });
275
- activeInternalSubscriptions.push(modelChanged$.subscribe((value) => {
276
- propValue.set(value);
277
- }));
278
- }
279
- }
280
- // In the case of signals, if we need to create an output spy, we need to check first whether or not a user has one defined first or has it created through
281
- // autoSpyOutputs. If so, we need to subscribe to the writable signal to push updates into the event emitter. We do NOT observe input signals and output spies will not
282
- // work for input signals.
283
- function detectAndRegisterOutputSpyToSignal(config, component, key, injector) {
284
- if (config.componentProperties) {
285
- const expectedChangeKey = `${key}Change`;
286
- const changeKeyIfExists = !!Object.keys(config.componentProperties).find((componentKey) => componentKey === expectedChangeKey);
287
- if (changeKeyIfExists) {
288
- component[expectedChangeKey] =
289
- // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
290
- config.componentProperties[expectedChangeKey];
291
- }
292
- if (changeKeyIfExists) {
293
- const componentValue = component[key];
294
- // if the user passed in a change key or we created one due to config.autoSpyOutputs being set to true for a given signal,
295
- // we will create a subscriber that will emit an event every time the value inside the signal changes. We only do this
296
- // if the signal is writable and not an input signal.
297
- if (isWritableSignal(componentValue) && !isInputSignal(componentValue)) {
298
- activeInternalSubscriptions.push(toObservable(componentValue, {
299
- injector,
300
- }).subscribe((value) => {
301
- var _a;
302
- (_a = component[expectedChangeKey]) === null || _a === void 0 ? void 0 : _a.emit(value);
303
- }));
304
- }
305
- }
306
- }
307
- }
308
- /**
309
- * Gets the componentInstance and Object.assigns any componentProperties() passed in the MountConfig
310
- *
311
- * @param {MountConfig} config TestBed configuration passed into the mount function
312
- * @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
313
- * @returns {T} Component being mounted
314
- */
315
- function setupComponent(config, fixture) {
316
- let component = fixture.componentInstance;
317
- const injector = fixture.componentRef.injector;
318
- if (config === null || config === void 0 ? void 0 : config.componentProperties) {
319
- if (component instanceof WrapperComponent) {
320
- component = Object.assign(component, config.componentProperties);
321
- }
322
- getComponentInputs(fixture.componentRef.componentType).forEach((key) => {
323
- var _a;
324
- // only assign props if they are passed into the component
325
- if ((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) {
326
- // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
327
- const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
328
- registerSignalEventsIfNeeded(key, passedInValue, component[key], injector, fixture);
329
- detectAndRegisterOutputSpyToSignal(config, component, key, injector);
330
- fixture.componentRef.setInput(key, isSignal(passedInValue) ? passedInValue() : passedInValue);
331
- }
332
- });
333
- getComponentOutputs(fixture.componentRef.componentType).forEach((key) => {
334
- var _a, _b;
335
- const property = component[key];
336
- // With the introduction of https://github.com/cypress-io/cypress/pull/31993, we want to make sure that component inputs are reference safe inside cy.mount().
337
- // However, the exception to this is if the user passes in a Cypress output spy as a property in order to maintain backwards compatibility.
338
- // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
339
- if (property instanceof EventEmitter || (((_a = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(key)) && (config === null || config === void 0 ? void 0 : config.componentProperties[key]) instanceof EventEmitter)) {
340
- // only assign props if they are passed into the component
341
- if ((_b = config === null || config === void 0 ? void 0 : config.componentProperties) === null || _b === void 0 ? void 0 : _b.hasOwnProperty(key)) {
342
- // @ts-expect-error key is a string, not keyof T, so it can't index componentProperties
343
- const passedInValue = config === null || config === void 0 ? void 0 : config.componentProperties[key];
344
- component[key] = passedInValue;
345
- }
346
- }
347
- });
348
- }
349
- // Manually call ngOnChanges when mounting components using the class syntax.
350
- // This is necessary because we are assigning input values to the class directly
351
- // on mount and therefore the ngOnChanges() lifecycle is not triggered.
352
- if (component.ngOnChanges && config.componentProperties) {
353
- const { componentProperties } = config;
354
- const simpleChanges = Object.entries(componentProperties).reduce((acc, [key, value]) => {
355
- acc[key] = new SimpleChange(null, value, true);
356
- return acc;
357
- }, {});
358
- if (Object.keys(componentProperties).length > 0) {
359
- component.ngOnChanges(simpleChanges);
360
- }
361
- }
362
- }
363
- /**
364
- * Gets the input properties of a component - cannot rely on Object.keys() because inclusion of optional properties depends on useDefineForClassFields=true
365
- * Since Angular 15, useDefineForClassFields=false
366
- * @param componentType
367
- * @returns array of input property names
368
- */
369
- function getComponentInputs(componentType) {
370
- var _a;
371
- // Access Angular's metadata to get input properties
372
- const propMetadata = ((_a = componentType.ɵcmp) === null || _a === void 0 ? void 0 : _a.inputs) || {};
373
- return Object.keys(propMetadata);
374
- }
375
- function getComponentOutputs(componentType) {
376
- var _a;
377
- // Access Angular's metadata to get output properties
378
- const propMetadata = ((_a = componentType.ɵcmp) === null || _a === void 0 ? void 0 : _a.outputs) || {};
379
- return Object.keys(propMetadata);
380
- }
381
- /**
382
- * Mounts an Angular component inside Cypress browser
383
- *
384
- * @param component Angular component being mounted or its template
385
- * @param config configuration used to configure the TestBed
386
- * @example
387
- * import { mount } from '@cypress/angular'
388
- * import { StepperComponent } from './stepper.component'
389
- * import { MyService } from 'services/my.service'
390
- * import { SharedModule } from 'shared/shared.module';
391
- * it('mounts', () => {
392
- * mount(StepperComponent, {
393
- * providers: [MyService],
394
- * imports: [SharedModule]
395
- * })
396
- * cy.get('[data-cy=increment]').click()
397
- * cy.get('[data-cy=counter]').should('have.text', '1')
398
- * })
399
- *
400
- * // or
401
- *
402
- * it('mounts with template', () => {
403
- * mount('<app-stepper></app-stepper>', {
404
- * declarations: [StepperComponent],
405
- * })
406
- * })
407
- *
408
- * @see {@link https://on.cypress.io/mounting-angular} for more details.
409
- *
410
- * @returns A component and component fixture
411
- */
412
- function mount(component, config = {}) {
413
- // Remove last mounted component if cy.mount is called more than once in a test
414
- if (activeFixture) {
415
- cleanup();
416
- }
417
- const componentFixture = initTestBed(component, config);
418
- let mountResponsePromiseResolver;
419
- let mountResponsePromiseRejector;
420
- const mountResponsePromise = new Promise((resolve, reject) => {
421
- mountResponsePromiseResolver = resolve;
422
- mountResponsePromiseRejector = reject;
423
- });
424
- const fixture = setupFixture(componentFixture, config);
425
- activeFixture = fixture;
426
- fixture.whenStable().then(() => {
427
- const mountResponse = {
428
- fixture,
429
- component: fixture.componentInstance,
430
- };
431
- const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name;
432
- Cypress.log({
433
- name: 'mount',
434
- message: logMessage,
435
- consoleProps: () => ({ result: mountResponse }),
436
- });
437
- mountResponsePromiseResolver(mountResponse);
438
- }).catch((error) => {
439
- mountResponsePromiseRejector(error);
440
- });
441
- return cy.wrap(mountResponsePromise, { log: false });
442
- }
443
- /**
444
- * Creates a new Event Emitter and then spies on it's `emit` method
445
- *
446
- * @param {string} alias name you want to use for your cy.spy() alias
447
- * @returns EventEmitter<T>
448
- * @example
449
- * import { StepperComponent } from './stepper.component'
450
- * import { mount, createOutputSpy } from '@cypress/angular'
451
- *
452
- * it('Has spy', () => {
453
- * mount(StepperComponent, { componentProperties: { change: createOutputSpy('changeSpy') } })
454
- * cy.get('[data-cy=increment]').click()
455
- * cy.get('@changeSpy').should('have.been.called')
456
- * })
457
- *
458
- * // Or for use with Angular Signals following the output nomenclature.
459
- * // see https://v17.angular.io/guide/model-inputs#differences-between-model-and-input/
460
- *
461
- * it('Has spy', () => {
462
- * mount(StepperComponent, { componentProperties: { count: signal(0), countChange: createOutputSpy('countChange') } })
463
- * cy.get('[data-cy=increment]').click()
464
- * cy.get('@countChange').should('have.been.called')
465
- * })
466
- */
467
- const createOutputSpy = (alias) => {
468
- const emitter = new EventEmitter();
469
- cy.spy(emitter, 'emit').as(alias);
470
- return emitter;
471
- };
472
- // Only needs to run once, we reset before each test
473
- getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {
474
- teardown: { destroyAfterEach: false },
475
- });
476
- setupHooks(cleanup);
477
-
478
- export { CypressTestComponentRenderer, createOutputSpy, mount };