Skip to content

Commit b41d844

Browse files
committed
add verify locale(it fails I don't know why)
1 parent 95d644a commit b41d844

File tree

6 files changed

+115
-18
lines changed

6 files changed

+115
-18
lines changed

Diff for: __test__/getCommand.spec.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import { it, describe, expect } from 'vitest'
22
import getCommand from '../utils/getCommand'
33

44
describe("should generate correct command", () => {
5-
const template = {
6-
packageManager: ["pnpm", "yarn", "npm"],
7-
commands: ["install", "dev", "build"],
8-
correct: ["pnpm install", "pnpm dev", "pnpm build", "yarn", "yarn dev", "yarn build", "npm install", "npm run dev", "npm run build"]
9-
}
10-
template.packageManager.forEach((manager) => {
11-
template.commands.forEach((command) => {
12-
it(`packageManager: ${manager}, command: ${command}`, () => {
13-
expect(getCommand(manager, command)).satisfy((generatedCommand) => {
14-
return template.correct.includes(generatedCommand)
15-
})
16-
})
17-
})
5+
it('for yarn', () => {
6+
expect(getCommand('yarn', 'install')).toBe('yarn')
7+
expect(getCommand('yarn', 'dev')).toBe('yarn dev')
8+
expect(getCommand('yarn', 'build')).toBe('yarn build')
9+
})
10+
it('for npm', () => {
11+
expect(getCommand('npm', 'install')).toBe('npm install')
12+
expect(getCommand('npm', 'dev')).toBe('npm run dev')
13+
expect(getCommand('npm', 'build')).toBe('npm run build')
14+
})
15+
it('for pnpm', () => {
16+
expect(getCommand('pnpm', 'install')).toBe('pnpm install')
17+
expect(getCommand('pnpm', 'dev')).toBe('pnpm dev')
18+
expect(getCommand('pnpm', 'build')).toBe('pnpm build')
1819
})
1920
})

Diff for: __test__/locale.spec.ts

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { resolve } from 'node:path'
3+
import { readdirSync } from 'node:fs'
4+
import { Language } from '../utils/getLanguage'
5+
import { isValid } from './untils'
6+
7+
const locales = readdirSync(resolve(__dirname, '../locales'))
8+
9+
describe('should include full keys', () => {
10+
const structure: Language = {
11+
"projectName": {
12+
"message": "string",
13+
},
14+
"shouldOverwrite": {
15+
"dirForPrompts": {
16+
"current": "string",
17+
"target": "string"
18+
},
19+
"message": "string"
20+
},
21+
"packageName": {
22+
"message": "string",
23+
"invalidMessage": "string",
24+
},
25+
"needsTypeScript": {
26+
"message": "string",
27+
},
28+
"needsJsx": {
29+
"message": "string",
30+
},
31+
"needsRouter": {
32+
"message": "string",
33+
},
34+
"needsPinia": {
35+
"message": "string",
36+
},
37+
"needsVitest": {
38+
"message": "string",
39+
},
40+
"needsE2eTesting": {
41+
"message": "string",
42+
"hint": "string",
43+
"selectOptions": {
44+
"negative": {
45+
"title": "string",
46+
},
47+
"cypress": {
48+
"title": "string",
49+
"desc": "string",
50+
},
51+
"nightwatch": {
52+
"title": "string",
53+
"desc": "string",
54+
},
55+
"playwright": {
56+
"title": "string",
57+
}
58+
}
59+
},
60+
"needsEslint": {
61+
"message": "string",
62+
},
63+
"needsPrettier": {
64+
"message": "string",
65+
},
66+
"errors": {
67+
"operationCancelled": "string",
68+
},
69+
"defaultToggleOptions": {
70+
"active": "string",
71+
"inactive": "string",
72+
},
73+
"infos": {
74+
"scaffolding": "string",
75+
"done": "string",
76+
}
77+
}
78+
locales.forEach((locale) => {
79+
it(`for ${locale}`, () => {
80+
expect(isValid(require(`../locales/${locale}`), structure)).toBeTruthy()
81+
})
82+
})
83+
})

Diff for: __test__/untils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function isValid(obj: Object, schema: Object) {
2+
for (let key in schema) {
3+
if (!obj.hasOwnProperty(key)) {
4+
return false
5+
}
6+
if (typeof schema[key] === 'object' && schema[key] !== null) {
7+
if (!isValid(obj[key], schema[key])) {
8+
return false
9+
} else if (typeof obj[key] !== schema[key]) {
10+
return false
11+
}
12+
}
13+
}
14+
return true
15+
}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"snapshot": "zx ./scripts/snapshot.mjs",
2222
"pretest": "run-s build snapshot",
2323
"test": "zx ./scripts/test.mjs",
24-
"test:unit": "vitest run -u",
24+
"test:unit": "vitest",
2525
"prepublishOnly": "zx ./scripts/prepublish.mjs"
2626
},
2727
"repository": {

Diff for: utils/getLanguage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface LanguageItem {
1818
}
1919
}
2020

21-
interface Language {
21+
export interface Language {
2222
projectName: LanguageItem
2323
shouldOverwrite: LanguageItem
2424
packageName: LanguageItem

Diff for: vitest.config.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { defineConfig } from 'vitest/config'
22

33
export default defineConfig({
44
test: {
5-
include: ['__test__/**.spec.ts'],
6-
reporters: 'default',
7-
environment: 'jsdom'
5+
include: ['__test__/**.spec.ts']
86
}
97
})

0 commit comments

Comments
 (0)