Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use vitest to make unitest #377

Merged
merged 27 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e5dde0
feat: use vitest to make unitest
CoolPlayLin Nov 12, 2023
25332c5
add getCommand unittest
CoolPlayLin Nov 12, 2023
95d644a
add unittest to workflow
CoolPlayLin Nov 12, 2023
b41d844
add verify locale(it fails I don't know why)
CoolPlayLin Nov 18, 2023
4e5284a
fix typo
CoolPlayLin Nov 18, 2023
c340af2
bugfix for key-checking
CoolPlayLin Nov 18, 2023
5d2463a
fix
CoolPlayLin Nov 18, 2023
3f9af05
Revert "fix"
CoolPlayLin Nov 18, 2023
b4e75ba
Squashed commit of the following:
CoolPlayLin Nov 18, 2023
8f0fe1f
Merge branch 'main' into CoolPlayLin/vitest
CoolPlayLin Nov 18, 2023
cc65b9d
fix lock file
CoolPlayLin Nov 18, 2023
3444b9c
🤔
CoolPlayLin Nov 18, 2023
f074859
add test for validate no unnecessary keys
CoolPlayLin Nov 18, 2023
a2f2e90
add locale validate
CoolPlayLin Nov 18, 2023
ec91736
add support for reusable locale
CoolPlayLin Nov 18, 2023
e4459e0
add test for `sortDependencies` & add snapshot
CoolPlayLin Nov 18, 2023
39e61e2
:sparkles: feat: add error message
CoolPlayLin Nov 19, 2023
e7ee1f1
:bug: fix: nothing
CoolPlayLin Nov 19, 2023
837838b
:bug: fix: nothing
CoolPlayLin Nov 19, 2023
d2aebec
:bug: fix: delete unnecessary assertions
CoolPlayLin Nov 25, 2023
431cfda
:hammer: chore: delete locale test
CoolPlayLin Nov 25, 2023
69b980d
:hammer: chore: delete schema
CoolPlayLin Nov 25, 2023
e06e995
:hammer: chore: delete 'test:update-snapshot' in package.json
CoolPlayLin Nov 25, 2023
ad687fb
:bug: fix: resolve suggestions in code reviews
CoolPlayLin Nov 25, 2023
ab7bb79
:bug: fix: delete unncessary change
CoolPlayLin Nov 25, 2023
b4ccf03
:hammer: chore: format test
CoolPlayLin Nov 25, 2023
347cbab
Merge branch 'main' into CoolPlayLin/vitest
CoolPlayLin Nov 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
env:
CYPRESS_INSTALL_BINARY: 0
- run: pnpm build
- run: pnpm test:unit

# Use cache to share the output across different jobs
# No need to cache node_modules because they are all bundled
Expand Down
22 changes: 22 additions & 0 deletions __test__/getCommand.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { it, describe, expect } from 'vitest'
import getCommand from '../utils/getCommand'

describe("should generate correct command", () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
it('for yarn', () => {
expect(getCommand('yarn', 'install')).toBe('yarn')
expect(getCommand('yarn', 'dev')).toBe('yarn dev')
expect(getCommand('yarn', 'build')).toBe('yarn build')

CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
})
it('for npm', () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
expect(getCommand('npm', 'install')).toBe('npm install')
expect(getCommand('npm', 'dev')).toBe('npm run dev')
expect(getCommand('npm', 'build')).toBe('npm run build')

CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
})
it('for pnpm', () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
expect(getCommand('pnpm', 'install')).toBe('pnpm install')
expect(getCommand('pnpm', 'dev')).toBe('pnpm dev')
expect(getCommand('pnpm', 'build')).toBe('pnpm build')
})
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
})
80 changes: 80 additions & 0 deletions __test__/sortDependencies.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { it, describe, expect } from 'vitest'
import sortDependencies from '../utils/sortDependencies'

describe('should output correct sorted value', () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
it('#1', () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
const packageJson = {
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.0",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"eslint": "^8.49.0",
"eslint-plugin-cypress": "^2.15.1",
"vite": "^4.4.11",
"vitest": "^0.34.6",
"@vue/test-utils": "^2.4.1",
"cypress": "^13.3.1",
"eslint-plugin-vue": "^9.17.0",
"jsdom": "^22.1.0",
"start-server-and-test": "^2.0.1",
}
}
expect(sortDependencies(packageJson)).toStrictEqual({
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.0",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vue/test-utils": "^2.4.1",
"cypress": "^13.3.1",
"eslint": "^8.49.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-vue": "^9.17.0",
"jsdom": "^22.1.0",
"start-server-and-test": "^2.0.1",
"vite": "^4.4.11",
"vitest": "^0.34.6"
}
}
)
})
it('#2', () => {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
const packageJson = {
"dependencies": {
"vue": "^3.3.4",
"vue-router": "^4.2.5",
"pinia": "^2.1.7",
},
"devDependencies": {
"@vitejs/plugin-vue-jsx": "^3.0.2",
"jsdom": "^22.1.0",
"start-server-and-test": "^2.0.1",
"vite": "^4.4.11",
"@vue/test-utils": "^2.4.1",
"cypress": "^13.3.1",
"eslint": "^8.49.0",
"@vitejs/plugin-vue": "^4.4.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-vue": "^9.17.0",
"vitest": "^0.34.6"
}
}
expect(sortDependencies(packageJson)).toStrictEqual({
"dependencies": {
"pinia": "^2.1.7",
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.0",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vue/test-utils": "^2.4.1",
"cypress": "^13.3.1",
"eslint": "^8.49.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-vue": "^9.17.0",
"jsdom": "^22.1.0",
"start-server-and-test": "^2.0.1",
"vite": "^4.4.11",
"vitest": "^0.34.6"
}
})
})
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"snapshot": "zx ./scripts/snapshot.mjs",
"pretest": "run-s build snapshot",
"test": "zx ./scripts/test.mjs",
"test:unit": "vitest",
"prepublishOnly": "zx ./scripts/prepublish.mjs"
},
"repository": {
Expand Down Expand Up @@ -51,6 +52,7 @@
"npm-run-all2": "^6.1.1",
"prettier": "^3.1.0",
"prompts": "^2.4.2",
"vitest": "^0.34.6",
"zx": "^7.2.3"
},
"lint-staged": {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/getLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface LanguageItem {
}
}

interface Language {
export interface Language {
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
projectName: LanguageItem
shouldOverwrite: LanguageItem
packageName: LanguageItem
Expand Down
7 changes: 7 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['__test__/**.spec.ts']
}
})