Skip to content

Commit 4cd60f9

Browse files
committed
chore: add basic cypress test
1 parent c2fa720 commit 4cd60f9

File tree

8 files changed

+1296
-96
lines changed

8 files changed

+1296
-96
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
component: {
5+
specPattern: 'cypress/components/**/*.spec.ts',
6+
devServer: {
7+
framework: 'vue',
8+
bundler: 'vite',
9+
},
10+
},
11+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// import { mount } from '@cypress/vue'
2+
import VueFinalModal from '~/components/VueFinalModal/VueFinalModal.vue'
3+
import { createVfm } from '~/plugin'
4+
5+
const vfm = createVfm()
6+
7+
it('renders the VueFinalModal', () => {
8+
cy.mount(VueFinalModal, {
9+
props: {
10+
modelValue: true,
11+
},
12+
slots: {
13+
default: '<p>Hello World!</p>',
14+
},
15+
global: {
16+
plugins: [vfm],
17+
},
18+
})
19+
cy.contains('Hello')
20+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }
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>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ***********************************************************
2+
// This example support/component.ts 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+
// Augment the Cypress namespace to include type definitions for
25+
// your custom command.
26+
// Alternatively, can be defined in cypress/support/component.d.ts
27+
// with a <reference path="./component" /> at the top of your spec.
28+
declare global {
29+
namespace Cypress {
30+
interface Chainable {
31+
mount: typeof mount
32+
}
33+
}
34+
}
35+
36+
Cypress.Commands.add('mount', mount)
37+
38+
// Example use:
39+
// cy.mount(MyComponent)

packages/vue-final-modal/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
"build": "vue-tsc --noEmit && vite build && vue-tsc -p tsconfig.build-dts.json --declaration --emitDeclarationOnly",
2727
"test": "vitest run",
2828
"coverage": "vitest run --coverage",
29+
"cypress:open": "cypress open",
2930
"typecheck": "vue-tsc --noEmit",
3031
"release": "pnpm build && pnpm test && release-it"
3132
},
3233
"dependencies": {
34+
"@cypress/vue": "^5.0.1",
3335
"@vueuse/core": "^9.4.0",
3436
"@vueuse/integrations": "^9.4.0",
37+
"cypress": "^11.1.0",
3538
"focus-trap": "^7.0.0",
3639
"vue": "^3.2.41",
3740
"vue-router": "^4.1.6"

packages/vue-final-modal/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"types": [
77
"vite/client",
88
"vitest",
9-
"unplugin-vue-macros/macros-global"
9+
"unplugin-vue-macros/macros-global",
10+
"cypress"
1011
],
1112
"paths": {
1213
"~/*": [

0 commit comments

Comments
 (0)