Skip to content

Commit

Permalink
feat: support git hooks and style lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 committed Dec 29, 2022
1 parent a663437 commit 1c47bb6
Show file tree
Hide file tree
Showing 29 changed files with 3,732 additions and 673 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
indent_size = 2
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.associations": {
"*.css": "postcss"
},
"editor.formatOnSave": false
}
18 changes: 9 additions & 9 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { defineConfig } from "cypress";
import { defineConfig } from 'cypress'

const baseUrl =
process.env.NODE_ENV === "developer"
? "http://127.0.0.1:5174/#/"
: "http://127.0.0.1:4173/#/";
const baseUrl
= process.env.NODE_ENV === 'developer'
? 'http://127.0.0.1:5174/#/'
: 'http://127.0.0.1:4173/#/'

export default defineConfig({
e2e: {
baseUrl,
setupNodeEvents(on, config) {
setupNodeEvents(_on, _config) {
// implement node event listeners here
},
},
component: {
devServer: {
framework: "vue",
bundler: "vite",
framework: 'vue',
bundler: 'vite',
},
},
});
})
14 changes: 7 additions & 7 deletions cypress/e2e/1-getting-started/todo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
// please read our getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe("example to-do app", () => {
describe('example to-do app', () => {
beforeEach(() => {
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
// we include it in our beforeEach function so that it runs before each test
// todo
// todo
// 后面需要基于环境来区分不同的 host
cy.visit("/");
});
cy.visit('/')
})

it('should be show one-step', () => {
cy.contains("欢迎来到 one-step")
});
});
cy.contains('欢迎来到 one-step')
})
})
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
// }
// }
// }
export {}
export {}
32 changes: 16 additions & 16 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";
import "cypress-promise/register";
import './commands'
import 'cypress-promise/register'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from "cypress/vue";
import { createMemoryHistory, createRouter } from "vue-router";
import { routes } from "../../src/router";
import { Router } from 'vue-router'
import { mount } from 'cypress/vue'
import type { Router } from 'vue-router'
import { createMemoryHistory, createRouter } from 'vue-router'
import { routes } from '../../src/router'

type MountParams = Parameters<typeof mount>
type OptionsParam = MountParams[1] & { router?: Router }
Expand All @@ -39,33 +39,33 @@ declare global {
* @param component Vue Component or JSX Element to mount
* @param options Options passed to Vue Test Utils
*/
mount(component: any, options?: OptionsParam): Chainable<any>;
mount(component: any, options?: OptionsParam): Chainable<any>
}
}
}

Cypress.Commands.add("mount", (component: any, options = {}) => {
Cypress.Commands.add('mount', (component: any, options = {}) => {
// Setup options object
options.global = options.global || {};
options.global.plugins = options.global.plugins || [];
options.global = options.global || {}
options.global.plugins = options.global.plugins || []

// create router if one is not provided
if (!options.router) {
options.router = createRouter({
routes: routes,
routes,
history: createMemoryHistory(),
});
})
}

// Add router plugin
options.global.plugins.push({
install(app: any) {
app.use(options.router);
app.use(options.router)
},
});
})

return mount(component, options);
});
return mount(component, options)
})

// Example use:
// cy.mount(MyComponent)
2 changes: 1 addition & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
35 changes: 31 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "vue3-todo-list",
"private": true,
"version": "0.0.0",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
Expand All @@ -13,7 +13,9 @@
"test-e2e": "cross-env NODE_ENV=developer cypress open --e2e",
"test-unit-run": "vitest --run",
"test-component-run": "cypress run --component",
"test-e2e-run": "cross-env NODE_ENV=developer cypress run --e2e"
"test-e2e-run": "cross-env NODE_ENV=developer cypress run --e2e",
"prepare": "simple-git-hooks",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@imengyu/vue3-context-menu": "^1.1.7",
Expand All @@ -25,8 +27,12 @@
"vue-router": "4"
},
"devDependencies": {
"@antfu/eslint-config": "^0.34.0",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@iconify-json/carbon": "^1.1.11",
"@iconify-json/mdi": "^1.1.40",
"@types/node": "^18.11.18",
"@unocss/reset": "^0.48.0",
"@vitejs/plugin-vue": "^3.0.0",
"@vitejs/plugin-vue-jsx": "^2.0.0",
Expand All @@ -35,12 +41,33 @@
"cross-env": "^7.0.3",
"cypress": "^10.4.0",
"cypress-promise": "^1.1.0",
"eslint": "^8.30.0",
"jsdom": "^20.0.0",
"lint-staged": "^13.1.0",
"path": "^0.12.7",
"simple-git-hooks": "^2.8.1",
"typescript": "^4.6.4",
"unocss": "^0.48.0",
"vite": "^3.0.0",
"vitest": "^0.20.3",
"vue-tsc": "^0.38.4"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged",
"commit-msg": "pnpm exec commitlint --edit \"${1}\""
},
"lint-staged": {
"*.{js,ts,json,md}": [
"eslint --fix"
]
},
"eslintConfig": {
"extends": "@antfu",
"ignorePatterns": ["**/*.cy.js"]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}
}
}
Loading

0 comments on commit 1c47bb6

Please sign in to comment.