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

0 commit comments

Comments
 (0)