Skip to content

Commit 9771614

Browse files
committed
Update for use with cypress 7
1 parent 54d7d4c commit 9771614

File tree

11 files changed

+2802
-2968
lines changed

11 files changed

+2802
-2968
lines changed

README.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,17 @@ npm install --save-dev cypress-svelte-unit-test
2828
npx install --save-dev cypress
2929
```
3030

31-
1. Tell Cypress to use your `rollup.config.js` to bundle specs using [cypress/plugins/index.js](cypress/plugins/index.js):
31+
1. Tell Cypress to use your webpack.config.js` to bundle specs using [cypress/plugins/index.js](cypress/plugins/index.js):
3232

3333
```js
34-
module.exports = (on) => {
35-
// @bahmutov/cy-rollup is already a dependency of cypress-svelte-unit-test
36-
const filePreprocessor = require('@bahmutov/cy-rollup')
37-
on('file:preprocessor', filePreprocessor())
38-
}
39-
```
40-
41-
2. ⚠️ Turn the experimental component support on in your `cypress.json`. You can also specify where component spec files are located. For example, to have them located in `src` folder use:
34+
const { startDevServer } = require('@cypress/webpack-dev-server')
35+
const webpackConfig = require('../../webpack.config.js')
4236

43-
```json
44-
{
45-
"experimentalComponentTesting": true,
46-
"componentFolder": "src",
47-
"testFiles": "**/*spec.js"
37+
module.exports = (on, config) => {
38+
on('dev-server:start', (options) => startDevServer({ options, webpackConfig }))
4839
}
4940
```
5041

51-
See [cypress.json](cypress.json) in this project.
52-
5342
3. Write a test!
5443

5544
```js
@@ -109,10 +98,13 @@ import '@cypress/code-coverage/support'
10998
Add the plugin to your [cypress/plugins/index.js](cypress/plugins/index.js) file
11099

111100
```js
101+
const { startDevServer } = require('@cypress/webpack-dev-server')
102+
const webpackConfig = require('../../webpack.config.js')
103+
112104
module.exports = (on, config) => {
113-
const filePreprocessor = require('@bahmutov/cy-rollup')
114-
on('file:preprocessor', filePreprocessor())
105+
on('dev-server:start', (options) => startDevServer({ options, webpackConfig }))
115106

107+
// https://github.com/cypress-io/code-coverage
116108
require('@cypress/code-coverage/task')(on, config)
117109
// IMPORTANT to return the config object
118110
// with the any changed environment variables

cypress.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"viewportHeight": 300,
44
"viewportWidth": 300,
55
"testFiles": "**/*spec.js",
6-
"experimentalComponentTesting": true,
76
"experimentalFetchPolyfill": true,
87
"componentFolder": "cypress/components",
98
"nodeVersion": "system"

cypress/components/styles/styles-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe('Styles', () => {
2424

2525
it('adds stylesheet', () => {
2626
mount(Component, null, {
27-
stylesheet: '/__root/cypress/components/styles/app.css',
27+
stylesheet: '/cypress/components/styles/app.css',
2828
})
2929
cy.get('body').should('have.css', 'background-color', 'rgb(0, 255, 255)')
3030
})
31-
31+
3232
it('adds CSS file and resolves a svelte component', () => {
3333
// Regression test for https://github.com/bahmutov/cypress-svelte-unit-test/issues/250.
3434
// Basically, `mount` was not returning the promise that returns the svelte component instance if using `cssFile` option.

cypress/plugins/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
module.exports = (on, config) => {
2-
// https://github.com/bahmutov/cy-rollup
3-
const filePreprocessor = require('@bahmutov/cy-rollup')
4-
on('file:preprocessor', filePreprocessor())
1+
const { startDevServer } = require('@cypress/webpack-dev-server')
2+
const webpackConfig = require('../../webpack.config.js')
53

6-
// https://github.com/cypress-io/code-coverage
7-
require('@cypress/code-coverage/task')(on, config)
8-
// IMPORTANT to return the config object
9-
// with the any changed environment variables
4+
module.exports = (on, config) => {
5+
on('dev-server:start', async (options) => {
6+
return startDevServer({ options, webpackConfig })
7+
})
108
return config
119
}

cypress/plugins/using-webpack.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
checkMountModeEnabled,
32
cleanupStyles,
43
injectStylesBeforeElement,
54
polyfillFetchIfNeeded,
@@ -96,7 +95,6 @@ export function mount(
9695
styleOptions: Partial<StyleOptions> = {},
9796
) {
9897
options = options || {}
99-
checkMountModeEnabled()
10098

10199
return cy.then(() => {
102100
// @ts-ignore

lib/utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { StyleOptions } from '.'
22
import unfetch from 'unfetch'
33

4-
export function checkMountModeEnabled() {
5-
// @ts-ignore
6-
if (Cypress.spec.specType !== 'component') {
7-
throw new Error(
8-
`In order to use mount or unmount functions please place the spec in component folder`,
9-
)
10-
}
11-
}
12-
134
/**
145
* Remove any style or extra link elements from the iframe placeholder
156
* left from any previous test

0 commit comments

Comments
 (0)