Skip to content

Commit

Permalink
feat: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
chansee97 committed Feb 27, 2024
1 parent 48f4546 commit be56e91
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 9 deletions.
14 changes: 14 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'cypress'

export default defineConfig({
component: {
devServer: {
framework: 'vue',
bundler: 'vite',
},
},

e2e: {
baseUrl: 'http://localhost:5200',
},
})
15 changes: 15 additions & 0 deletions cypress/e2e/basic.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
context('Basic', () => {
beforeEach(() => {
cy.visit('/')
})

it('basic nav', () => {
cy.contains('[Default Layout]')
.should('exist')

cy.get('[test-id="test-input"]')
.type('Rock{Enter}')
.url()
.should('include', '/hi/Rock')
})
})
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// 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<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')
12 changes: 12 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"cypress"
]
},
"include": [
"**/*.ts"
],
"exclude": []
}
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
"url": "https://github.com/chansee97/virtuoso/issues"
},
"keywords": [
"vitailse",
"tailwindcss",
"vue",
"unocss",
"vite",
"vitesse"
],
"scripts": {
"dev": "vite --mode dev --port 5200 --open",
"dev": "vite --mode dev --port 5200",
"dev:test": "vite --mode test ",
"dev:prod": "vite --mode prod ",
"build": "vite build --mode prod",
"preview": "vite preview",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"stylelint:fix": "npx stylelint *.{css,scss,vue,less,html} --fix",
"postinstall": "npx simple-git-hooks",
"sizecheck": "npx vite-bundle-visualizer"
"test:e2e": "cypress open",
"sizecheck": "npx vite-bundle-visualizer",
"postinstall": "npx simple-git-hooks"
},
"dependencies": {
"@unocss/reset": "^0.58.5",
Expand All @@ -46,6 +46,7 @@
"@types/nprogress": "^0.2.3",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"cypress": "^13.6.6",
"eslint": "^8.57.0",
"lint-staged": "^15.2.2",
"naive-ui": "^2.38.1",
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<router-view />
</div>
<v-layout-footer>
[ Default Layout ]
[Default Layout]
</v-layout-footer>
</main>
</template>
2 changes: 1 addition & 1 deletion src/layouts/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<router-view />
</div>
<v-layout-footer>
[ Home Layout ]
[Home Layout]
</v-layout-footer>
</main>
</template>
2 changes: 1 addition & 1 deletion src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function go() {
<span>Template baseed on Vue3, Vite4, Naive-UI, Unocss</span>

<n-space>
<n-input v-model:value="name" type="text" placeholder="Enter your name" />
<n-input v-model:value="name" test-id="test-input" type="text" placeholder="Enter your name" @keydown.enter="go" />
<n-button type="primary" :disabled="!name" @click="go">
Go
</n-button>
Expand Down

0 comments on commit be56e91

Please sign in to comment.