-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-locales.test.js
More file actions
92 lines (77 loc) · 3.85 KB
/
generate-locales.test.js
File metadata and controls
92 lines (77 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
/**
* Tests for generate-locales.js --app, --out-dir, --ts-out CLI args.
* Run: node packages/design-system/content/scripts/generate-locales.test.js
*/
import { strict as assert } from 'assert'
import { execFileSync } from 'child_process'
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
import { join } from 'path'
import { fileURLToPath } from 'url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const script = join(__dirname, 'generate-locales.js')
const tmpDir = join(__dirname, '__test_tmp__')
function setup() {
rmSync(tmpDir, { recursive: true, force: true })
mkdirSync(join(tmpDir, 'states'), { recursive: true })
mkdirSync(join(tmpDir, 'locales'), { recursive: true })
mkdirSync(join(tmpDir, 'ts-out'), { recursive: true })
// Minimal fixture CSV with portal-only and shared content
const csv = [
'Content,English,Español',
'GLOBAL - Button Continue,Continue,Continuar',
'S1 - Landing Page - Title,Portal Landing,Portal Landing ES',
'S7 - Portal Dashboard - Heading,Dashboard,Panel',
].join('\n')
writeFileSync(join(tmpDir, 'states', 'co.csv'), csv)
}
function teardown() {
rmSync(tmpDir, { recursive: true, force: true })
}
setup()
// Test: --app portal includes landing and dashboard, generates to --out-dir and --ts-out
execFileSync('node', [
script,
'--csv-dir', join(tmpDir, 'states'),
'--out-dir', join(tmpDir, 'locales'),
'--ts-out', join(tmpDir, 'ts-out', 'portal-resources.ts'),
'--app', 'portal',
], { stdio: 'inherit' })
const portalContent = readFileSync(join(tmpDir, 'ts-out', 'portal-resources.ts'), 'utf8')
assert.ok(portalContent.includes('landing'), 'portal barrel must include landing namespace')
assert.ok(portalContent.includes('dashboard'), 'portal barrel must include dashboard namespace')
assert.ok(portalContent.includes('common'), 'portal barrel must include common namespace')
// Test: --app enrollment includes common but excludes dashboard
execFileSync('node', [
script,
'--csv-dir', join(tmpDir, 'states'),
'--out-dir', join(tmpDir, 'locales'),
'--ts-out', join(tmpDir, 'ts-out', 'enrollment-resources.ts'),
'--app', 'enrollment',
], { stdio: 'inherit' })
const enrollmentContent = readFileSync(join(tmpDir, 'ts-out', 'enrollment-resources.ts'), 'utf8')
assert.ok(enrollmentContent.includes('common'), 'enrollment barrel must include common namespace')
assert.ok(!enrollmentContent.includes('dashboard'), 'enrollment barrel must NOT include dashboard namespace')
// Test: locale JSON was written to --out-dir (not to script's own directory)
assert.ok(existsSync(join(tmpDir, 'locales', 'en', 'co', 'landing.json')), 'locale JSON must be written to --out-dir')
// Test: new CSV column headers ("Variable Name/Key", "🟢 CO English", "🟢 CO Español")
setup()
const csvNewHeaders = [
'Variable Name/Key,🟢 CO English,⚪ SOURCE English,🟢 CO Español,⚪ SOURCE Español,Notes',
'GLOBAL - Button Continue,Continue,,Continuar,,',
'S1 - Landing Page - Title,New Header Landing,,New Header Landing ES,,',
].join('\n')
writeFileSync(join(tmpDir, 'states', 'co.csv'), csvNewHeaders)
execFileSync('node', [
script,
'--csv-dir', join(tmpDir, 'states'),
'--out-dir', join(tmpDir, 'locales'),
'--ts-out', join(tmpDir, 'ts-out', 'new-header-resources.ts'),
'--app', 'portal',
], { stdio: 'inherit' })
const newHeaderLanding = JSON.parse(readFileSync(join(tmpDir, 'locales', 'en', 'co', 'landing.json'), 'utf8'))
assert.equal(newHeaderLanding.title, 'New Header Landing', 'must parse content from "Variable Name/Key" column header')
const newHeaderCommon = JSON.parse(readFileSync(join(tmpDir, 'locales', 'es', 'co', 'common.json'), 'utf8'))
assert.equal(newHeaderCommon.buttonContinue, 'Continuar', 'must parse Spanish from state-prefixed Español column')
console.log('✅ All generate-locales CLI arg tests passed')
teardown()