Skip to content

Commit e4459e0

Browse files
committed
add test for sortDependencies & add snapshot
1 parent ec91736 commit e4459e0

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

Diff for: __test__/__snapshots__/getCommand.spec.ts.snap

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should generate correct command > for npm 1`] = `"npm install"`;
4+
5+
exports[`should generate correct command > for npm 2`] = `"npm run dev"`;
6+
7+
exports[`should generate correct command > for npm 3`] = `"npm run build"`;
8+
9+
exports[`should generate correct command > for pnpm 1`] = `"pnpm install"`;
10+
11+
exports[`should generate correct command > for pnpm 2`] = `"pnpm dev"`;
12+
13+
exports[`should generate correct command > for pnpm 3`] = `"pnpm build"`;
14+
15+
exports[`should generate correct command > for yarn 1`] = `"yarn"`;
16+
17+
exports[`should generate correct command > for yarn 2`] = `"yarn dev"`;
18+
19+
exports[`should generate correct command > for yarn 3`] = `"yarn build"`;

Diff for: __test__/getCommand.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ import getCommand from '../utils/getCommand'
44
describe("should generate correct command", () => {
55
it('for yarn', () => {
66
expect(getCommand('yarn', 'install')).toBe('yarn')
7+
expect(getCommand('yarn', 'install')).toMatchSnapshot()
78
expect(getCommand('yarn', 'dev')).toBe('yarn dev')
9+
expect(getCommand('yarn', 'dev')).toMatchSnapshot()
810
expect(getCommand('yarn', 'build')).toBe('yarn build')
11+
expect(getCommand('yarn', 'build')).toMatchSnapshot()
12+
913
})
1014
it('for npm', () => {
1115
expect(getCommand('npm', 'install')).toBe('npm install')
16+
expect(getCommand('npm', 'install')).toMatchSnapshot()
1217
expect(getCommand('npm', 'dev')).toBe('npm run dev')
18+
expect(getCommand('npm', 'dev')).toMatchSnapshot()
1319
expect(getCommand('npm', 'build')).toBe('npm run build')
20+
expect(getCommand('npm', 'build')).toMatchSnapshot()
21+
1422
})
1523
it('for pnpm', () => {
1624
expect(getCommand('pnpm', 'install')).toBe('pnpm install')
25+
expect(getCommand('pnpm', 'install')).toMatchSnapshot()
1726
expect(getCommand('pnpm', 'dev')).toBe('pnpm dev')
27+
expect(getCommand('pnpm', 'dev')).toMatchSnapshot()
1828
expect(getCommand('pnpm', 'build')).toBe('pnpm build')
29+
expect(getCommand('pnpm', 'build')).toMatchSnapshot()
1930
})
2031
})

Diff for: __test__/locale.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('should match name regex', () => {
2525
})
2626

2727
describe('should include full keys', () => {
28-
const structure: Language = require('../schema/locale.json')
28+
const structure = require('../schema/locale.json') as Language
2929
locales.forEach((locale) => {
3030
it(`for ${locale}`, () => {
3131
expect(includeAllKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
@@ -34,7 +34,7 @@ describe('should include full keys', () => {
3434
})
3535

3636
describe("should not include unnecessary keys", () => {
37-
const structure: Language = require('../schema/locale.json')
37+
const structure = require('../schema/locale.json') as Language
3838
locales.forEach((locale) => {
3939
it(`for ${locale}`, () => {
4040
expect(excludeKeys(require(`../locales/${locale}`), structure)).toBeTruthy()

Diff for: __test__/sortDependencies.spec.ts

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { it, describe, expect } from 'vitest'
2+
import sortDependencies from '../utils/sortDependencies'
3+
4+
describe('should output correct sorted value', () => {
5+
it('#1', () => {
6+
const packageJson = {
7+
"devDependencies": {
8+
"@vitejs/plugin-vue": "^4.4.0",
9+
"@vitejs/plugin-vue-jsx": "^3.0.2",
10+
"eslint": "^8.49.0",
11+
"eslint-plugin-cypress": "^2.15.1",
12+
"vite": "^4.4.11",
13+
"vitest": "^0.34.6",
14+
"@vue/test-utils": "^2.4.1",
15+
"cypress": "^13.3.1",
16+
"eslint-plugin-vue": "^9.17.0",
17+
"jsdom": "^22.1.0",
18+
"start-server-and-test": "^2.0.1",
19+
}
20+
}
21+
expect(sortDependencies(packageJson)).toStrictEqual({
22+
"devDependencies": {
23+
"@vitejs/plugin-vue": "^4.4.0",
24+
"@vitejs/plugin-vue-jsx": "^3.0.2",
25+
"@vue/test-utils": "^2.4.1",
26+
"cypress": "^13.3.1",
27+
"eslint": "^8.49.0",
28+
"eslint-plugin-cypress": "^2.15.1",
29+
"eslint-plugin-vue": "^9.17.0",
30+
"jsdom": "^22.1.0",
31+
"start-server-and-test": "^2.0.1",
32+
"vite": "^4.4.11",
33+
"vitest": "^0.34.6"
34+
}
35+
}
36+
)
37+
})
38+
it('#2', () => {
39+
const packageJson = {
40+
"dependencies": {
41+
"vue": "^3.3.4",
42+
"vue-router": "^4.2.5",
43+
"pinia": "^2.1.7",
44+
},
45+
"devDependencies": {
46+
"@vitejs/plugin-vue-jsx": "^3.0.2",
47+
"jsdom": "^22.1.0",
48+
"start-server-and-test": "^2.0.1",
49+
"vite": "^4.4.11",
50+
"@vue/test-utils": "^2.4.1",
51+
"cypress": "^13.3.1",
52+
"eslint": "^8.49.0",
53+
"@vitejs/plugin-vue": "^4.4.0",
54+
"eslint-plugin-cypress": "^2.15.1",
55+
"eslint-plugin-vue": "^9.17.0",
56+
"vitest": "^0.34.6"
57+
}
58+
}
59+
expect(sortDependencies(packageJson)).toStrictEqual({
60+
"dependencies": {
61+
"pinia": "^2.1.7",
62+
"vue": "^3.3.4",
63+
"vue-router": "^4.2.5"
64+
},
65+
"devDependencies": {
66+
"@vitejs/plugin-vue": "^4.4.0",
67+
"@vitejs/plugin-vue-jsx": "^3.0.2",
68+
"@vue/test-utils": "^2.4.1",
69+
"cypress": "^13.3.1",
70+
"eslint": "^8.49.0",
71+
"eslint-plugin-cypress": "^2.15.1",
72+
"eslint-plugin-vue": "^9.17.0",
73+
"jsdom": "^22.1.0",
74+
"start-server-and-test": "^2.0.1",
75+
"vite": "^4.4.11",
76+
"vitest": "^0.34.6"
77+
}
78+
})
79+
})
80+
})

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"pretest": "run-s build snapshot",
2323
"test": "zx ./scripts/test.mjs",
2424
"test:unit": "vitest",
25+
"test:update-snapshot": "vitest run -u",
2526
"prepublishOnly": "zx ./scripts/prepublish.mjs"
2627
},
2728
"repository": {

0 commit comments

Comments
 (0)