Skip to content

Commit a03a17d

Browse files
committed
feat: make plugin Cypress 10 compatible
downgrade to moveFile@2 due to better cjs support add example of usage create test suite add a bit more visual space between on hover and diff panels Signed-off-by: Jakub Freisler <[email protected]>
1 parent b26beb3 commit a03a17d

30 files changed

+8001
-31
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
~/.cache/Cypress
3232
.yarn
3333
node_modules
34+
example/node_modules
3435
- name: Install dependencies
3536
if: ${{ github.actor != 'dependabot[bot]' || github.ref == 'refs/heads/main' }}
3637
run: yarn --immutable
@@ -62,13 +63,45 @@ jobs:
6263
~/.cache/Cypress
6364
.yarn
6465
node_modules
66+
example/node_modules
6567
- name: Install dependencies
6668
run: yarn --immutable
6769
- name: Lint
6870
run: yarn lint:ci
6971
- name: Prettify
7072
run: yarn prettify:ci
7173

74+
test:
75+
name: test
76+
runs-on: ubuntu-latest
77+
needs: cache
78+
steps:
79+
- uses: actions/checkout@v3
80+
- uses: actions/setup-node@v3
81+
with:
82+
node-version: '16.x'
83+
- name: remove git auth
84+
run: git config --unset http.https://github.com/.extraheader
85+
- name: Configure Yarn cache
86+
uses: actions/cache@v3
87+
with:
88+
key: ${{ needs.cache.outputs.yarn-cache-key }}
89+
path: |
90+
~/.cache/Cypress
91+
.yarn
92+
node_modules
93+
example/node_modules
94+
- name: Install dependencies
95+
run: yarn --immutable
96+
- name: Build plugin
97+
run: yarn build
98+
- name: Install example dependencies
99+
run: cd example && yarn --immutable
100+
- name: Test e2e
101+
run: yarn test:e2e:ci
102+
- name: Test component-testing
103+
run: yarn test:ct:ci
104+
72105
build-and-release:
73106
name: build and release
74107
runs-on: ubuntu-latest
@@ -96,6 +129,7 @@ jobs:
96129
~/.cache/Cypress
97130
.yarn
98131
node_modules
132+
example/node_modules
99133
- name: Install dependencies
100134
run: yarn --immutable
101135
- name: Authenticate with Registry

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</p>
1616

1717
<h1 align="center">Plugin for Cypress - Visual Regression Diff</h1>
18-
<p align="center">Perform visual regression test with a nice GUI as help. 💅 <i>Only&nbsp;for&nbsp;Cypress!</i></p>
18+
<p align="center">Perform visual regression test with a nice GUI as help. 💅 <i>Only&nbsp;for&nbsp;Cypress!</i> Both e2e and component-testing compatible 💪</p>
1919

2020
<p align="center">
2121
<a href="#getting-started">Getting Started</a>
@@ -61,7 +61,7 @@ Next, you need to import the library:
6161

6262
- first, in your support file (located by default in `cypress/support/index.js`):
6363
```ts
64-
// typescript
64+
// typescript / ES6
6565
import '@frsource/cypress-plugin-visual-regression-diff/dist/support';
6666

6767
// javascript
@@ -71,7 +71,7 @@ require('@frsource/cypress-plugin-visual-regression-diff/dist/support');
7171
- secondly:
7272
- (for Cypress 10.0+) in `cypress.config.js` (or `cypress.config.ts`):
7373
```ts
74-
// typescript
74+
// typescript / ES6
7575
import { defineConfig } from 'cypress';
7676
import { initPlugin } from '@frsource/cypress-plugin-visual-regression-diff/dist/plugins';
7777

@@ -85,9 +85,9 @@ export default defineConfig({
8585
}
8686
});
8787
```
88-
- (for Cypress >10.0) in your plugins file (located by default in `cypress/plugins/index.js`):
88+
- (for Cypress <10.0) in your plugins file (located by default in `cypress/plugins/index.js`):
8989
```ts
90-
// typescript
90+
// typescript / ES6
9191
import { initPlugin } from '@frsource/cypress-plugin-visual-regression-diff/dist/plugins';
9292

9393
export default function (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) {
@@ -124,6 +124,10 @@ cy.matchImage();
124124

125125
`matchImage` command will do a screenshot and compare it with image from a previous run. In case of regression the test will fail and you'll get a "Compare images" button to see what's a root of a problem.
126126

127+
## Example
128+
129+
Still got troubles with installation? Have a look at [example directory of this repo](./example) to see how this plugin can be used in e2e or component-testing Cypress within your project.
130+
127131
## Configuration
128132

129133
This plugin can be configured either:

example/.browserslistrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> 1%
2+
last 2 versions
3+
not dead
4+
not ie 11

example/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
/tests/e2e/videos/
6+
/tests/e2e/screenshots/
7+
8+
# we do not want to commit local screenshot files
9+
# as they might be different on different OSes
10+
**/__image_snapshots_local__
11+
12+
13+
# local env files
14+
.env.local
15+
.env.*.local
16+
17+
# Log files
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
pnpm-debug.log*
22+
23+
# Editor directories and files
24+
.idea
25+
.vscode
26+
*.suo
27+
*.ntvs*
28+
*.njsproj
29+
*.sln
30+
*.sw?

example/.yarnrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nodeLinker: node-modules
2+
3+
yarnPath: ../.yarn/releases/yarn-3.2.1.cjs

example/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Example for @frsource/cypress-plugin-visual-regression-diff
2+
3+
## Project setup
4+
5+
```bash
6+
yarn install
7+
```
8+
9+
### Run your end-to-end tests
10+
11+
> Important - remember to run `yarn && yarn build` command in this repo's root directory before starting e2e tests.
12+
13+
```bash
14+
yarn test:e2e
15+
```
16+
17+
### Compiles and hot-reloads for development
18+
19+
```bash
20+
yarn serve
21+
```
22+
23+
### Compiles and minifies for production
24+
25+
```bash
26+
yarn build
27+
```
28+
29+
### Customize configuration
30+
31+
See [Configuration Reference](https://cli.vuejs.org/config/).

example/cypress.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const { defineConfig } = require("cypress");
3+
// eslint-disable-next-line @typescript-eslint/no-var-requires
4+
const { initPlugin } = require("@frsource/cypress-plugin-visual-regression-diff/dist/plugins");
5+
6+
module.exports = defineConfig({
7+
e2e: {
8+
setupNodeEvents(on, config) {
9+
initPlugin(on, config);
10+
},
11+
specPattern: "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"
12+
},
13+
14+
component: {
15+
setupNodeEvents(on, config) {
16+
initPlugin(on, config);
17+
},
18+
devServer: {
19+
framework: "vue-cli",
20+
bundler: "webpack",
21+
},
22+
},
23+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import HelloWorld from '../../src/components/HelloWorld.vue';
2+
3+
const msg = 'Some random test message';
4+
5+
describe('HelloWorld.cy.js', () => {
6+
it('playground', () => {
7+
cy.mount(HelloWorld, {
8+
propsData: { msg },
9+
})
10+
.then(() => {
11+
cy.contains('h1', msg);
12+
cy.matchImage();
13+
cy.get('[data-testid="description"]').matchImage();
14+
})
15+
})
16+
})
Loading
Loading
Loading

example/cypress/e2e/spec.cy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('My First Test', () => {
2+
it('Visits the app root url', () => {
3+
cy.visit('/')
4+
cy.contains('h1', 'Welcome to Your Vue.js App')
5+
cy.matchImage()
6+
})
7+
})

example/cypress/support/commands.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
import '@frsource/cypress-plugin-visual-regression-diff/dist/support';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>

example/cypress/support/component.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ***********************************************************
2+
// This example support/component.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
21+
22+
import { mount } from 'cypress/vue'
23+
24+
Cypress.Commands.add('mount', mount);
25+
26+
// Example use:
27+
// cy.mount(MyComponent)

example/cypress/support/e2e.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/component.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

example/jsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "esnext",
5+
"baseUrl": "./",
6+
"moduleResolution": "node",
7+
"paths": {
8+
"@/*": [
9+
"src/*"
10+
]
11+
},
12+
"lib": [
13+
"esnext",
14+
"dom",
15+
"dom.iterable",
16+
"scripthost"
17+
]
18+
}
19+
}

example/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "example",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"test:open": "vue-cli-service test:e2e --env \"pluginVisualRegressionImagesDir=__image_snapshots_local__\"",
9+
"test:run": "vue-cli-service test:e2e",
10+
"test:ct": "yarn test:open --component",
11+
"test:ct:ci": "yarn test:run --component --headless",
12+
"test:e2e": "yarn test:open --e2e",
13+
"test:e2e:ci": "yarn test:run --e2e --headless"
14+
},
15+
"dependencies": {
16+
"vue": "^3.2.13"
17+
},
18+
"devDependencies": {
19+
"@frsource/cypress-plugin-visual-regression-diff": "portal:..",
20+
"@vue/cli-plugin-e2e-cypress": "~5.0.0",
21+
"@vue/cli-service": "~5.0.0",
22+
"cypress": "^10.2.0"
23+
}
24+
}

example/public/favicon.ico

4.19 KB
Binary file not shown.

example/public/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title><%= htmlWebpackPlugin.options.title %></title>
9+
</head>
10+
<body>
11+
<noscript>
12+
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
13+
</noscript>
14+
<div id="app"></div>
15+
<!-- built files will be auto injected -->
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)