cypress 10.11.0 → 11.0.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 (74) hide show
  1. package/angular/CHANGELOG.md +20 -0
  2. package/angular/dist/index.d.ts +124 -1
  3. package/angular/dist/index.js +59 -59
  4. package/lib/cli.js +15 -1
  5. package/lib/tasks/download.js +3 -7
  6. package/lib/util.js +2 -2
  7. package/mount-utils/CHANGELOG.md +14 -0
  8. package/mount-utils/README.md +5 -23
  9. package/mount-utils/dist/index.d.ts +25 -39
  10. package/mount-utils/dist/index.js +33 -112
  11. package/mount-utils/package.json +1 -0
  12. package/package.json +3 -3
  13. package/react/CHANGELOG.md +27 -0
  14. package/react/README.md +2 -22
  15. package/react/dist/cypress-react.cjs.js +92 -219
  16. package/react/dist/cypress-react.esm-bundler.js +92 -220
  17. package/react/dist/index.d.ts +111 -4
  18. package/react18/CHANGELOG.md +13 -0
  19. package/react18/dist/cypress-react.cjs.js +117 -180
  20. package/react18/dist/cypress-react.esm-bundler.js +103 -167
  21. package/react18/dist/index.d.ts +78 -6
  22. package/react18/package.json +1 -0
  23. package/svelte/CHANGELOG.md +20 -0
  24. package/svelte/dist/cypress-svelte.cjs.js +19 -114
  25. package/svelte/dist/cypress-svelte.esm-bundler.js +19 -114
  26. package/svelte/dist/index.d.ts +201 -1
  27. package/types/cypress.d.ts +18 -10
  28. package/vue/CHANGELOG.md +34 -0
  29. package/vue/README.md +4 -8
  30. package/vue/dist/cypress-vue.cjs.js +68 -151
  31. package/vue/dist/cypress-vue.esm-bundler.js +68 -151
  32. package/vue/dist/index.d.ts +1352 -104
  33. package/vue/package.json +1 -1
  34. package/vue2/CHANGELOG.md +27 -0
  35. package/vue2/README.md +3 -7
  36. package/vue2/dist/cypress-vue2.cjs.js +87 -211
  37. package/vue2/dist/cypress-vue2.esm-bundler.js +86 -210
  38. package/vue2/dist/index.d.ts +341 -172
  39. package/vue2/package.json +1 -3
  40. package/angular/dist/mount.d.ts +0 -112
  41. package/react/dist/createMount.d.ts +0 -31
  42. package/react/dist/getDisplayName.d.ts +0 -8
  43. package/react/dist/mount.d.ts +0 -8
  44. package/react/dist/mountHook.d.ts +0 -12
  45. package/react/dist/types.d.ts +0 -45
  46. package/svelte/dist/mount.d.ts +0 -30
  47. package/vue/dist/@vue/test-utils/baseWrapper.d.ts +0 -63
  48. package/vue/dist/@vue/test-utils/components/RouterLinkStub.d.ts +0 -21
  49. package/vue/dist/@vue/test-utils/config.d.ts +0 -30
  50. package/vue/dist/@vue/test-utils/constants/dom-events.d.ts +0 -900
  51. package/vue/dist/@vue/test-utils/createDomEvent.d.ts +0 -9
  52. package/vue/dist/@vue/test-utils/domWrapper.d.ts +0 -18
  53. package/vue/dist/@vue/test-utils/emit.d.ts +0 -5
  54. package/vue/dist/@vue/test-utils/errorWrapper.d.ts +0 -1
  55. package/vue/dist/@vue/test-utils/index.d.ts +0 -11
  56. package/vue/dist/@vue/test-utils/interfaces/wrapperLike.d.ts +0 -56
  57. package/vue/dist/@vue/test-utils/mount.d.ts +0 -35
  58. package/vue/dist/@vue/test-utils/stubs.d.ts +0 -22
  59. package/vue/dist/@vue/test-utils/types.d.ts +0 -125
  60. package/vue/dist/@vue/test-utils/utils/autoUnmount.d.ts +0 -5
  61. package/vue/dist/@vue/test-utils/utils/compileSlots.d.ts +0 -2
  62. package/vue/dist/@vue/test-utils/utils/componentName.d.ts +0 -4
  63. package/vue/dist/@vue/test-utils/utils/find.d.ts +0 -10
  64. package/vue/dist/@vue/test-utils/utils/flushPromises.d.ts +0 -1
  65. package/vue/dist/@vue/test-utils/utils/getRootNodes.d.ts +0 -2
  66. package/vue/dist/@vue/test-utils/utils/isElement.d.ts +0 -1
  67. package/vue/dist/@vue/test-utils/utils/isElementVisible.d.ts +0 -6
  68. package/vue/dist/@vue/test-utils/utils/matchName.d.ts +0 -1
  69. package/vue/dist/@vue/test-utils/utils/stringifyNode.d.ts +0 -1
  70. package/vue/dist/@vue/test-utils/utils/vueCompatSupport.d.ts +0 -8
  71. package/vue/dist/@vue/test-utils/utils/vueShared.d.ts +0 -3
  72. package/vue/dist/@vue/test-utils/utils.d.ts +0 -13
  73. package/vue/dist/@vue/test-utils/vueWrapper.d.ts +0 -35
  74. package/vue/dist/@vue/test-utils/wrapperFactory.d.ts +0 -14
@@ -1,3 +1,23 @@
1
+ # [@cypress/angular-v2.0.1](https://github.com/cypress-io/cypress/compare/@cypress/angular-v2.0.0...@cypress/angular-v2.0.1) (2022-11-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * make component derived info not throw ([#24571](https://github.com/cypress-io/cypress/issues/24571)) ([838dd4f](https://github.com/cypress-io/cypress/commit/838dd4fa2e0ec56633d0af2faf10a47d190b5594))
7
+
8
+ # [@cypress/angular-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.2...@cypress/angular-v2.0.0) (2022-11-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * possibility to override global services in Angular component tests ([#24394](https://github.com/cypress-io/cypress/issues/24394)) ([54d2853](https://github.com/cypress-io/cypress/commit/54d285321723450920e0f1d50374c4bd0590e72a))
14
+ * remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54))
15
+
16
+
17
+ ### BREAKING CHANGES
18
+
19
+ * remove last mounted component upon subsequent mount calls of mount
20
+
1
21
  # [@cypress/angular-v1.1.2](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.1...@cypress/angular-v1.1.2) (2022-10-11)
2
22
 
3
23
 
@@ -1 +1,124 @@
1
- export * from './mount';
1
+ /// <reference types="cypress" />
2
+
3
+ import { Type } from '@angular/core';
4
+ import { 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
+ *
11
+ * @interface MountConfig
12
+ * @see https://angular.io/api/core/testing/TestModuleMetadata
13
+ */
14
+ interface MountConfig<T> extends TestModuleMetadata {
15
+ /**
16
+ * @memberof MountConfig
17
+ * @description flag to automatically create a cy.spy() for every component @Output() property
18
+ * @example
19
+ * export class ButtonComponent {
20
+ * @Output clicked = new EventEmitter()
21
+ * }
22
+ *
23
+ * cy.mount(ButtonComponent, { autoSpyOutputs: true })
24
+ * cy.get('@clickedSpy).should('have.been.called')
25
+ */
26
+ autoSpyOutputs?: boolean;
27
+ /**
28
+ * @memberof MountConfig
29
+ * @description flag defaulted to true to automatically detect changes in your components
30
+ */
31
+ autoDetectChanges?: boolean;
32
+ /**
33
+ * @memberof MountConfig
34
+ * @example
35
+ * import { ButtonComponent } from 'button/button.component'
36
+ * it('renders a button with Save text', () => {
37
+ * cy.mount(ButtonComponent, { componentProperties: { text: 'Save' }})
38
+ * cy.get('button').contains('Save')
39
+ * })
40
+ *
41
+ * it('renders a button with a cy.spy() replacing EventEmitter', () => {
42
+ * cy.mount(ButtonComponent, {
43
+ * componentProperties: {
44
+ * clicked: cy.spy().as('mySpy)
45
+ * }
46
+ * })
47
+ * cy.get('button').click()
48
+ * cy.get('@mySpy').should('have.been.called')
49
+ * })
50
+ */
51
+ componentProperties?: Partial<{
52
+ [P in keyof T]: T[P];
53
+ }>;
54
+ }
55
+ /**
56
+ * Type that the `mount` function returns
57
+ * @type MountResponse<T>
58
+ */
59
+ declare type MountResponse<T> = {
60
+ /**
61
+ * Fixture for debugging and testing a component.
62
+ *
63
+ * @memberof MountResponse
64
+ * @see https://angular.io/api/core/testing/ComponentFixture
65
+ */
66
+ fixture: ComponentFixture<T>;
67
+ /**
68
+ * The instance of the root component class
69
+ *
70
+ * @memberof MountResponse
71
+ * @see https://angular.io/api/core/testing/ComponentFixture#componentInstance
72
+ */
73
+ component: T;
74
+ };
75
+ /**
76
+ * Mounts an Angular component inside Cypress browser
77
+ *
78
+ * @param component Angular component being mounted or its template
79
+ * @param config configuration used to configure the TestBed
80
+ * @example
81
+ * import { mount } from '@cypress/angular'
82
+ * import { StepperComponent } from './stepper.component'
83
+ * import { MyService } from 'services/my.service'
84
+ * import { SharedModule } from 'shared/shared.module';
85
+ * it('mounts', () => {
86
+ * mount(StepperComponent, {
87
+ * providers: [MyService],
88
+ * imports: [SharedModule]
89
+ * })
90
+ * cy.get('[data-cy=increment]').click()
91
+ * cy.get('[data-cy=counter]').should('have.text', '1')
92
+ * })
93
+ *
94
+ * // or
95
+ *
96
+ * it('mounts with template', () => {
97
+ * mount('<app-stepper></app-stepper>', {
98
+ * declarations: [StepperComponent],
99
+ * })
100
+ * })
101
+ *
102
+ * @see {@link https://on.cypress.io/mounting-angular} for more details.
103
+ *
104
+ * @returns A component and component fixture
105
+ */
106
+ declare function mount<T>(component: Type<T> | string, config?: MountConfig<T>): Cypress.Chainable<MountResponse<T>>;
107
+ /**
108
+ * Creates a new Event Emitter and then spies on it's `emit` method
109
+ *
110
+ * @param {string} alias name you want to use for your cy.spy() alias
111
+ * @returns EventEmitter<T>
112
+ * @example
113
+ * import { StepperComponent } from './stepper.component'
114
+ * import { mount, createOutputSpy } from '@cypress/angular'
115
+ *
116
+ * it('Has spy', () => {
117
+ * mount(StepperComponent, { change: createOutputSpy('changeSpy') })
118
+ * cy.get('[data-cy=increment]').click()
119
+ * cy.get('@changeSpy').should('have.been.called')
120
+ * })
121
+ */
122
+ declare const createOutputSpy: <T>(alias: string) => any;
123
+
124
+ export { MountConfig, MountResponse, createOutputSpy, mount };
@@ -47,27 +47,11 @@ function __decorate(decorators, target, key, desc) {
47
47
  }
48
48
 
49
49
  /**
50
- * Remove any style or extra link elements from the iframe placeholder
51
- * left from any previous test
52
- *
50
+ * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
51
+ * @param optionalCallback Callback to be called before the next test runs
53
52
  */
54
- function cleanupStyles() {
55
- const styles = document.body.querySelectorAll('[data-cy=injected-style-tag]');
56
- styles.forEach((styleElement) => {
57
- if (styleElement.parentElement) {
58
- styleElement.parentElement.removeChild(styleElement);
59
- }
60
- });
61
- const links = document.body.querySelectorAll('[data-cy=injected-stylesheet]');
62
- links.forEach((link) => {
63
- if (link.parentElement) {
64
- link.parentElement.removeChild(link);
65
- }
66
- });
67
- }
68
53
  function setupHooks(optionalCallback) {
69
- // Consumed by the framework "mount" libs. A user might register their own mount in the scaffolded 'commands.js'
70
- // file that is imported by e2e and component support files by default. We don't want CT side effects to run when e2e
54
+ // We don't want CT side effects to run when e2e
71
55
  // testing so we early return.
72
56
  // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
73
57
  if (Cypress.testingType !== 'component') {
@@ -82,7 +66,6 @@ function setupHooks(optionalCallback) {
82
66
  // @ts-ignore
83
67
  Cypress.on('test:before:run', () => {
84
68
  optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
85
- cleanupStyles();
86
69
  });
87
70
  }
88
71
 
@@ -91,6 +74,20 @@ function setupHooks(optionalCallback) {
91
74
  */
92
75
  // @ts-ignore
93
76
  window.Mocha['__zone_patch__'] = false;
77
+ let activeFixture = null;
78
+ function cleanup() {
79
+ // Not public, we need to call this to remove the last component from the DOM
80
+ try {
81
+ getTestBed().tearDownTestingModule();
82
+ }
83
+ catch (e) {
84
+ const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`);
85
+ notSupportedError.docsUrl = 'https://on.cypress.io/component-framework-configuration';
86
+ throw notSupportedError;
87
+ }
88
+ getTestBed().resetTestingModule();
89
+ activeFixture = null;
90
+ }
94
91
  // 'zone.js/testing' is not properly aliasing `it.skip` but it does provide `xit`/`xspecify`
95
92
  // Written up under https://github.com/angular/angular/issues/46297 but is not seeing movement
96
93
  // so we'll patch here pending a fix in that library
@@ -111,6 +108,7 @@ CypressAngularErrorHandler = __decorate([
111
108
  * @returns {MountConfig} MountConfig
112
109
  */
113
110
  function bootstrapModule(component, config) {
111
+ var _a;
114
112
  const testModuleMetaData = __rest(config, ["componentProperties"]);
115
113
  if (!testModuleMetaData.declarations) {
116
114
  testModuleMetaData.declarations = [];
@@ -128,7 +126,7 @@ function bootstrapModule(component, config) {
128
126
  useClass: CypressAngularErrorHandler,
129
127
  });
130
128
  // check if the component is a standalone component
131
- if (component.ɵcmp.standalone) {
129
+ if ((_a = component.ɵcmp) === null || _a === void 0 ? void 0 : _a.standalone) {
132
130
  testModuleMetaData.imports.push(component);
133
131
  }
134
132
  else {
@@ -147,16 +145,8 @@ function bootstrapModule(component, config) {
147
145
  * @returns {Type<T>} componentFixture
148
146
  */
149
147
  function initTestBed(component, config) {
150
- const { providers } = config, configRest = __rest(config, ["providers"]);
151
148
  const componentFixture = createComponentFixture(component);
152
- getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, configRest)));
153
- if (providers != null) {
154
- getTestBed().overrideComponent(componentFixture, {
155
- add: {
156
- providers,
157
- },
158
- });
159
- }
149
+ getTestBed().configureTestingModule(Object.assign({}, bootstrapModule(componentFixture, config)));
160
150
  return componentFixture;
161
151
  }
162
152
  let WrapperComponent = class WrapperComponent {
@@ -189,6 +179,7 @@ function createComponentFixture(component) {
189
179
  */
190
180
  function setupFixture(component, config) {
191
181
  const fixture = getTestBed().createComponent(component);
182
+ setupComponent(config, fixture);
192
183
  fixture.whenStable().then(() => {
193
184
  var _a;
194
185
  fixture.autoDetectChanges((_a = config.autoDetectChanges) !== null && _a !== void 0 ? _a : true);
@@ -208,7 +199,7 @@ function setupComponent(config, fixture) {
208
199
  component = Object.assign(component, config.componentProperties);
209
200
  }
210
201
  if (config.autoSpyOutputs) {
211
- Object.keys(component).forEach((key, index, keys) => {
202
+ Object.keys(component).forEach((key) => {
212
203
  const property = component[key];
213
204
  if (property instanceof EventEmitter) {
214
205
  component[key] = createOutputSpy(`${key}Spy`);
@@ -228,44 +219,48 @@ function setupComponent(config, fixture) {
228
219
  component.ngOnChanges(simpleChanges);
229
220
  }
230
221
  }
231
- return component;
232
222
  }
233
223
  /**
234
224
  * Mounts an Angular component inside Cypress browser
235
225
  *
236
- * @param {Type<T> | string} component Angular component being mounted or its template
237
- * @param {MountConfig<T>} config configuration used to configure the TestBed
226
+ * @param component Angular component being mounted or its template
227
+ * @param config configuration used to configure the TestBed
238
228
  * @example
239
- * import { HelloWorldComponent } from 'hello-world/hello-world.component'
229
+ * import { mount } from '@cypress/angular'
230
+ * import { StepperComponent } from './stepper.component'
240
231
  * import { MyService } from 'services/my.service'
241
232
  * import { SharedModule } from 'shared/shared.module';
242
- * import { mount } from '@cypress/angular'
243
- * it('can mount', () => {
244
- * mount(HelloWorldComponent, {
245
- * providers: [MyService],
246
- * imports: [SharedModule]
247
- * })
248
- * cy.get('h1').contains('Hello World')
233
+ * it('mounts', () => {
234
+ * mount(StepperComponent, {
235
+ * providers: [MyService],
236
+ * imports: [SharedModule]
237
+ * })
238
+ * cy.get('[data-cy=increment]').click()
239
+ * cy.get('[data-cy=counter]').should('have.text', '1')
249
240
  * })
250
241
  *
251
- * or
242
+ * // or
252
243
  *
253
- * it('can mount with template', () => {
254
- * mount('<app-hello-world></app-hello-world>', {
255
- * declarations: [HelloWorldComponent],
256
- * providers: [MyService],
257
- * imports: [SharedModule]
258
- * })
244
+ * it('mounts with template', () => {
245
+ * mount('<app-stepper></app-stepper>', {
246
+ * declarations: [StepperComponent],
247
+ * })
259
248
  * })
260
- * @returns Cypress.Chainable<MountResponse<T>>
249
+ *
250
+ * @see {@link https://on.cypress.io/mounting-angular} for more details.
251
+ *
252
+ * @returns A component and component fixture
261
253
  */
262
254
  function mount(component, config = {}) {
255
+ // Remove last mounted component if cy.mount is called more than once in a test
256
+ if (activeFixture) {
257
+ cleanup();
258
+ }
263
259
  const componentFixture = initTestBed(component, config);
264
- const fixture = setupFixture(componentFixture, config);
265
- const componentInstance = setupComponent(config, fixture);
260
+ activeFixture = setupFixture(componentFixture, config);
266
261
  const mountResponse = {
267
- fixture,
268
- component: componentInstance,
262
+ fixture: activeFixture,
263
+ component: activeFixture.componentInstance,
269
264
  };
270
265
  const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name;
271
266
  Cypress.log({
@@ -280,6 +275,15 @@ function mount(component, config = {}) {
280
275
  *
281
276
  * @param {string} alias name you want to use for your cy.spy() alias
282
277
  * @returns EventEmitter<T>
278
+ * @example
279
+ * import { StepperComponent } from './stepper.component'
280
+ * import { mount, createOutputSpy } from '@cypress/angular'
281
+ *
282
+ * it('Has spy', () => {
283
+ * mount(StepperComponent, { change: createOutputSpy('changeSpy') })
284
+ * cy.get('[data-cy=increment]').click()
285
+ * cy.get('@changeSpy').should('have.been.called')
286
+ * })
283
287
  */
284
288
  const createOutputSpy = (alias) => {
285
289
  const emitter = new EventEmitter();
@@ -290,10 +294,6 @@ const createOutputSpy = (alias) => {
290
294
  getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
291
295
  teardown: { destroyAfterEach: false },
292
296
  });
293
- setupHooks(() => {
294
- // Not public, we need to call this to remove the last component from the DOM
295
- getTestBed()['tearDownTestingModule']();
296
- getTestBed().resetTestingModule();
297
- });
297
+ setupHooks(cleanup);
298
298
 
299
299
  export { createOutputSpy, mount };
package/lib/cli.js CHANGED
@@ -331,9 +331,23 @@ module.exports = {
331
331
  }
332
332
 
333
333
  const {
334
- CYPRESS_INTERNAL_ENV
334
+ CYPRESS_INTERNAL_ENV,
335
+ CYPRESS_DOWNLOAD_USE_CA
335
336
  } = process.env;
336
337
 
338
+ if (process.env.CYPRESS_DOWNLOAD_USE_CA) {
339
+ let msg = `
340
+ ${logSymbols.warning} Warning: It looks like you're setting CYPRESS_DOWNLOAD_USE_CA=${CYPRESS_DOWNLOAD_USE_CA}
341
+
342
+ The environment variable "CYPRESS_DOWNLOAD_USE_CA" is no longer required to be set.
343
+
344
+ You can safely unset this environment variable.
345
+ `;
346
+ logger.log();
347
+ logger.warn(stripIndent(msg));
348
+ logger.log();
349
+ }
350
+
337
351
  if (!util.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
338
352
  debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV);
339
353
  return errors.exitWithError(errors.errors.invalidCypressEnv)(`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`);
@@ -56,18 +56,14 @@ const getBaseUrl = () => {
56
56
 
57
57
  const getCA = () => {
58
58
  return new Promise(resolve => {
59
- if (!util.getEnv('CYPRESS_DOWNLOAD_USE_CA')) {
60
- resolve();
61
- }
62
-
63
- if (process.env.npm_config_ca) {
64
- resolve(process.env.npm_config_ca);
65
- } else if (process.env.npm_config_cafile) {
59
+ if (process.env.npm_config_cafile) {
66
60
  fs.readFile(process.env.npm_config_cafile, 'utf8').then(cafileContent => {
67
61
  resolve(cafileContent);
68
62
  }).catch(() => {
69
63
  resolve();
70
64
  });
65
+ } else if (process.env.npm_config_ca) {
66
+ resolve(process.env.npm_config_ca);
71
67
  } else {
72
68
  resolve();
73
69
  }
package/lib/util.js CHANGED
@@ -151,7 +151,7 @@ function isValidCypressInternalEnvValue(value) {
151
151
  if (_.isUndefined(value)) {
152
152
  // will get default value
153
153
  return true;
154
- } // names of config environments, see "packages/server/config/app.yml"
154
+ } // names of config environments, see "packages/server/config/app.json"
155
155
 
156
156
 
157
157
  const names = ['development', 'test', 'staging', 'production'];
@@ -245,7 +245,7 @@ const getApplicationDataFolder = (...paths) => {
245
245
  env
246
246
  } = process; // allow overriding the app_data folder
247
247
 
248
- let folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
248
+ let folder = env.CYPRESS_CONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
249
249
  const PRODUCT_NAME = pkg.productName || pkg.name;
250
250
  const OS_DATA_PATH = ospath.data();
251
251
  const ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME);
@@ -1,3 +1,17 @@
1
+ # [@cypress/mount-utils-v3.0.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.1.0...@cypress/mount-utils-v3.0.0) (2022-11-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove dependence on @cypress/<dep> types ([#24415](https://github.com/cypress-io/cypress/issues/24415)) ([58e0ab9](https://github.com/cypress-io/cypress/commit/58e0ab91604618ea6f75932622f7e66e419270e6))
7
+ * remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54))
8
+ * remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074))
9
+
10
+
11
+ ### BREAKING CHANGES
12
+
13
+ * remove last mounted component upon subsequent mount calls of mount
14
+
1
15
  # [@cypress/mount-utils-v2.1.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.0.1...@cypress/mount-utils-v2.1.0) (2022-08-30)
2
16
 
3
17
 
@@ -25,11 +25,7 @@ All the functionality used to create the first party Mount adapters is available
25
25
 
26
26
  In addition, we recommend that Mount Adapters:
27
27
 
28
- - receive a second argument that extends `StyleOptions` from `@cypress/mount-utils`
29
- - calls `injectStylesBeforeElement` from `@cypress/mount-utils` before mounting the component
30
- - calls `setupHooks` to register the required lifecycle hooks for `@cypress/mount-utils` to work
31
-
32
- This will let the user inject styles `<style>...</style>` and stylesheets `<link rel="stylesheet">`, which is very useful for developing components.
28
+ - call `setupHooks` to register the required lifecycle hooks for `@cypress/mount-utils` to work
33
29
 
34
30
  ### Example Mount Adapter: Web Components
35
31
 
@@ -39,9 +35,7 @@ Here's a simple yet realistic example of Mount Adapter targeting Web Components.
39
35
  import {
40
36
  ROOT_SELECTOR,
41
37
  setupHooks,
42
- injectStylesBeforeElement,
43
- getContainerEl,
44
- StyleOptions
38
+ getContainerEl
45
39
  } from "@cypress/mount-utils";
46
40
 
47
41
  Cypress.on("run:start", () => {
@@ -69,8 +63,7 @@ function maybeRegisterComponent<T extends CustomElementConstructor>(
69
63
  }
70
64
 
71
65
  export function mount(
72
- webComponent: CustomElementConstructor,
73
- options?: Partial<StyleOptions>
66
+ webComponent: CustomElementConstructor
74
67
  ): Cypress.Chainable {
75
68
  // Get root selector defined in `cypress/support.component-index.html
76
69
  const $root = document.querySelector(ROOT_SELECTOR)!;
@@ -83,9 +76,6 @@ export function mount(
83
76
  /// Register Web Component
84
77
  maybeRegisterComponent(name, webComponent);
85
78
 
86
- // Inject user styles before mounting the component
87
- injectStylesBeforeElement(options ?? {}, document, getContainerEl())
88
-
89
79
  // Render HTML containing component.
90
80
  $root.innerHTML = `<${name} id="root"></${name}>`;
91
81
 
@@ -100,8 +90,7 @@ export function mount(
100
90
  return cy.wrap(document.querySelector("#root"), { log: false });
101
91
  }
102
92
 
103
- // Setup Cypress lifecycle hooks. This tears down any styles
104
- // injected by injectStylesBeforeElement, etc.
93
+ // Setup Cypress lifecycle hooks.
105
94
  setupHooks();
106
95
  ```
107
96
 
@@ -131,14 +120,7 @@ export class WebCounter extends HTMLElement {
131
120
 
132
121
  describe('web-component.cy.ts', () => {
133
122
  it('playground', () => {
134
- cy.mount(WebCounter, {
135
- styles: `
136
- button {
137
- background: lightblue;
138
- color: white;
139
- }
140
- `
141
- })
123
+ cy.mount(WebCounter)
142
124
  })
143
125
  })
144
126
  ```
@@ -1,54 +1,40 @@
1
+ export declare const ROOT_SELECTOR = "[data-cy-root]";
1
2
  /**
2
- * Additional styles to inject into the document.
3
- * A component might need 3rd party libraries from CDN,
4
- * local CSS files and custom styles.
3
+ * Gets the root element used to mount the component.
4
+ * @returns {HTMLElement} The root element
5
+ * @throws {Error} If the root element is not found
5
6
  */
6
- export interface StyleOptions {
7
- /**
8
- * Creates <link href="..." /> element for each stylesheet
9
- * @alias stylesheet
10
- */
11
- stylesheets: string | string[];
12
- /**
13
- * Creates <link href="..." /> element for each stylesheet
14
- * @alias stylesheets
15
- */
16
- stylesheet: string | string[];
17
- /**
18
- * Creates <style>...</style> element and inserts given CSS.
19
- * @alias styles
20
- */
21
- style: string | string[];
22
- /**
23
- * Creates <style>...</style> element for each given CSS text.
24
- * @alias style
25
- */
26
- styles: string | string[];
27
- /**
28
- * Loads each file and creates a <style>...</style> element
29
- * with the loaded CSS
30
- * @alias cssFile
31
- */
32
- cssFiles: string | string[];
33
- /**
34
- * Single CSS file to load into a <style></style> element
35
- * @alias cssFile
36
- */
37
- cssFile: string | string[];
38
- }
39
- export declare const ROOT_SELECTOR = "[data-cy-root]";
40
7
  export declare const getContainerEl: () => HTMLElement;
8
+ export declare function checkForRemovedStyleOptions(mountingOptions: Record<string, any>): void;
9
+ /**
10
+ * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
11
+ * @param optionalCallback Callback to be called before the next test runs
12
+ */
13
+ export declare function setupHooks(optionalCallback?: Function): void;
41
14
  /**
42
15
  * Remove any style or extra link elements from the iframe placeholder
43
16
  * left from any previous test
44
17
  *
18
+ * Removed as of Cypress 11.0.0
19
+ * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
45
20
  */
46
21
  export declare function cleanupStyles(): void;
22
+ /**
23
+ * Additional styles to inject into the document.
24
+ * A component might need 3rd party libraries from CDN,
25
+ * local CSS files and custom styles.
26
+ *
27
+ * Removed as of Cypress 11.0.0.
28
+ * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
29
+ */
30
+ export declare type StyleOptions = unknown;
47
31
  /**
48
32
  * Injects custom style text or CSS file or 3rd party style resources
49
33
  * into the given document.
34
+ *
35
+ * Removed as of Cypress 11.0.0.
36
+ * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
50
37
  */
51
38
  export declare const injectStylesBeforeElement: (options: Partial<StyleOptions & {
52
39
  log: boolean;
53
- }>, document: Document, el: HTMLElement | null) => HTMLElement;
54
- export declare function setupHooks(optionalCallback?: Function): void;
40
+ }>, document: Document, el: HTMLElement | null) => void;