From d6060c58123fd2a4a69e14c8fb9ff1c81544b2da Mon Sep 17 00:00:00 2001 From: Naily Date: Sat, 26 Oct 2024 18:19:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=93=83cypress=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress.config.ts | 7 +++++ cypress/fixtures/example.json | 5 ++++ cypress/support/commands.ts | 37 ++++++++++++++++++++++++++ cypress/support/component-index.html | 12 +++++++++ cypress/support/component.ts | 39 ++++++++++++++++++++++++++++ eslint.config.js | 1 + 6 files changed, 101 insertions(+) create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.ts create mode 100644 cypress/support/component-index.html create mode 100644 cypress/support/component.ts diff --git a/cypress.config.ts b/cypress.config.ts index e61db9a..8d7d509 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -11,4 +11,11 @@ export default defineConfig({ on('file:preprocessor', vitePreprocessor()) }, }, + + component: { + devServer: { + framework: 'vue', + bundler: 'vite', + }, + }, }) diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 0000000..95857ae --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,37 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +// +// declare global { +// namespace Cypress { +// interface Chainable { +// login(email: string, password: string): Chainable +// drag(subject: string, options?: Partial): Chainable +// dismiss(subject: string, options?: Partial): Chainable +// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable +// } +// } +// } diff --git a/cypress/support/component-index.html b/cypress/support/component-index.html new file mode 100644 index 0000000..faf3b5f --- /dev/null +++ b/cypress/support/component-index.html @@ -0,0 +1,12 @@ + + + + + + + Components App + + +
+ + diff --git a/cypress/support/component.ts b/cypress/support/component.ts new file mode 100644 index 0000000..74ae3ea --- /dev/null +++ b/cypress/support/component.ts @@ -0,0 +1,39 @@ +// *********************************************************** +// This example support/component.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') + +import { mount } from 'cypress/vue' + +// Augment the Cypress namespace to include type definitions for +// your custom command. +// Alternatively, can be defined in cypress/support/component.d.ts +// with a at the top of your spec. +declare global { + namespace Cypress { + interface Chainable { + mount: typeof mount + } + } +} + +Cypress.Commands.add('mount', mount) + +// Example use: +// cy.mount(MyComponent) diff --git a/eslint.config.js b/eslint.config.js index 08f33f6..518de77 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,6 +8,7 @@ export default antfu( rules: { 'ts/no-redeclare': 'off', 'ts/method-signature-style': 'off', + 'ts/no-namespace': 'off', }, }, )