@jjlmoya/utils-games-development 1.65.0 → 1.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +67 -67
- package/scripts/postinstall.mjs +27 -27
- package/src/category/GamesCategorySEO.astro +19 -19
- package/src/category/i18n/de.ts +15 -15
- package/src/category/i18n/en.ts +15 -15
- package/src/category/i18n/es.ts +15 -15
- package/src/category/i18n/fr.ts +15 -15
- package/src/category/i18n/id.ts +10 -10
- package/src/category/i18n/it.ts +10 -10
- package/src/category/i18n/ja.ts +10 -10
- package/src/category/i18n/ko.ts +10 -10
- package/src/category/i18n/nl.ts +10 -10
- package/src/category/i18n/pl.ts +10 -10
- package/src/category/i18n/pt.ts +10 -10
- package/src/category/i18n/ru.ts +10 -10
- package/src/category/i18n/sv.ts +10 -10
- package/src/category/i18n/tr.ts +10 -10
- package/src/category/i18n/zh.ts +10 -10
- package/src/category/seo.astro +15 -15
- package/src/components/PreviewNavSidebar.astro +116 -116
- package/src/components/PreviewToolbar.astro +143 -143
- package/src/data.ts +11 -11
- package/src/env.d.ts +5 -5
- package/src/index.ts +20 -20
- package/src/layouts/PreviewLayout.astro +122 -122
- package/src/pages/[locale]/[slug].astro +165 -165
- package/src/pages/[locale].astro +250 -250
- package/src/pages/index.astro +4 -4
- package/src/tests/bibliography_wellformed_export.test.ts +46 -0
- package/src/tests/category_seo_quality.test.ts +74 -0
- package/src/tests/diacritics_density.test.ts +118 -118
- package/src/tests/faq_count.test.ts +19 -19
- package/src/tests/i18n_coverage.test.ts +36 -36
- package/src/tests/inverted_punctuation.test.ts +84 -84
- package/src/tests/mocks/astro_mock.js +2 -2
- package/src/tests/no_en_dash.test.ts +70 -70
- package/src/tests/no_h1_in_components.test.ts +48 -48
- package/src/tests/pagespeed_best_practices.test.ts +198 -198
- package/src/tests/qa-test-helpers.ts +32 -32
- package/src/tests/qa_bibliography_links.test.ts +41 -41
- package/src/tests/qa_claim_evidence.test.ts +69 -69
- package/src/tests/qa_logic_reference_coverage.test.ts +46 -46
- package/src/tests/qa_runtime_i18n.test.ts +100 -100
- package/src/tests/schemas_fulfillment.test.ts +23 -23
- package/src/tests/script_density.test.ts +94 -94
- package/src/tests/seo_length.test.ts +23 -23
- package/src/tests/seo_wellformed_export.test.ts +65 -0
- package/src/tests/slug_language_code_format.test.ts +23 -23
- package/src/tests/slug_uniqueness.test.ts +80 -80
- package/src/tests/title_quality.test.ts +56 -56
- package/src/tool/audioLoopPointFinder/audio-loop-point-finder.css +322 -322
- package/src/tool/audioLoopPointFinder/client.ts +262 -262
- package/src/tool/damageFormulaLab/bibliography.astro +3 -21
- package/src/tool/damageFormulaLab/seo.astro +7 -5
- package/src/tool/gameDeltaTimeFixedTimestepLab/bibliography.astro +3 -19
- package/src/tool/hitboxHurtboxAnimator/hitbox-hurtbox-animator.css +614 -614
- package/src/tool/hitboxHurtboxAnimator/seo.astro +7 -5
- package/src/tool/saveFileEditor/component.astro +351 -351
- package/src/tool/saveFileEditor/game-save-file-editor.css +250 -250
- package/src/tool/spriteSheetPacker/app-client.ts +248 -248
- package/src/tool/spriteSheetPacker/bibliography.ts +12 -12
- package/src/tool/spriteSheetPacker/component.astro +229 -229
- package/src/tool/spriteSheetPacker/dropzone-client.ts +55 -55
- package/src/tool/spriteSheetPacker/entry.ts +28 -28
- package/src/tool/spriteSheetPacker/exporter.ts +116 -116
- package/src/tool/spriteSheetPacker/extractor-client.ts +127 -127
- package/src/tool/spriteSheetPacker/flipbook-client.ts +60 -60
- package/src/tool/spriteSheetPacker/logic.test.ts +155 -155
- package/src/tool/spriteSheetPacker/logic.ts +32 -32
- package/src/tool/spriteSheetPacker/packer-core.ts +121 -121
- package/src/tool/spriteSheetPacker/packer-ui.ts +86 -86
- package/src/tool/spriteSheetPacker/sprite-sheet-packer.css +578 -578
- package/src/tool/spriteSheetPacker/types.ts +89 -89
- package/src/tool/spriteSheetPacker/ui.ts +42 -42
- package/src/tool/steamCapsuleGenerator/index.ts +9 -9
- package/src/tool/steamCapsuleGenerator/validation.ts +14 -14
- package/src/types.ts +72 -72
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { displayPath, listToolDirectories, read } from './qa-test-helpers';
|
|
5
|
-
|
|
6
|
-
const evidenceClaims = [
|
|
7
|
-
/\bofficial algorithm\b/i,
|
|
8
|
-
/\balgoritmo oficial\b/i,
|
|
9
|
-
/\b(?:records|data|rates|tables) updated(?:\s+(?:to|through)\s+20\d{2})?\b/i,
|
|
10
|
-
/\b(?:registros|datos|tasas|tablas) actualizad[oa]s?(?:\s+(?:a|hasta)\s+20\d{2})?\b/i,
|
|
11
|
-
/\b(?:validated|verified) (?:method|algorithm|calculation)\b/i,
|
|
12
|
-
/\b(?:método|algoritmo|cálculo) (?:validado|verificado)\b/i,
|
|
13
|
-
/\b(?:guarantees|ensures)\b/i,
|
|
14
|
-
/\bgarantiza\b/i,
|
|
15
|
-
/\bofficial (?:data|rate|calculation)\b/i,
|
|
16
|
-
/\b(?:datos|tasa|cálculo) oficial(?:es)?\b/i,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const requiredEvidenceFields = [
|
|
20
|
-
'reviewedAt',
|
|
21
|
-
'methodology',
|
|
22
|
-
'sources',
|
|
23
|
-
'referenceCases',
|
|
24
|
-
'limitations',
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
describe('QA: strong factual claims are traceable', () => {
|
|
28
|
-
it('requires machine-readable validation evidence beside tools making strong claims', () => {
|
|
29
|
-
const failures: string[] = [];
|
|
30
|
-
|
|
31
|
-
for (const directory of listToolDirectories()) {
|
|
32
|
-
const localePaths = ['en', 'es']
|
|
33
|
-
.map((locale) => join(directory, 'i18n', `${locale}.ts`))
|
|
34
|
-
.filter(existsSync);
|
|
35
|
-
const claims = localePaths.flatMap((path) => {
|
|
36
|
-
const source = read(path);
|
|
37
|
-
return evidenceClaims
|
|
38
|
-
.filter((pattern) => pattern.test(source))
|
|
39
|
-
.map((pattern) => `${displayPath(path)} matches ${pattern.source}`);
|
|
40
|
-
});
|
|
41
|
-
if (claims.length === 0) continue;
|
|
42
|
-
|
|
43
|
-
const evidencePath = join(directory, 'validation.ts');
|
|
44
|
-
if (!existsSync(evidencePath)) {
|
|
45
|
-
failures.push(`${displayPath(evidencePath)} missing; claims: ${claims.join(' | ')}`);
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const evidence = read(evidencePath);
|
|
50
|
-
const missingFields = requiredEvidenceFields.filter(
|
|
51
|
-
(field) => !new RegExp(`\\b${field}\\s*:`).test(evidence),
|
|
52
|
-
);
|
|
53
|
-
if (missingFields.length > 0) {
|
|
54
|
-
failures.push(`${displayPath(evidencePath)} missing fields: ${missingFields.join(', ')}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
expect(
|
|
59
|
-
failures,
|
|
60
|
-
[
|
|
61
|
-
'Claims such as official, validated, guaranteed or updated need inspectable evidence.',
|
|
62
|
-
'Add validation.ts with reviewedAt, methodology, sources, referenceCases and limitations,',
|
|
63
|
-
'or weaken/remove the unsupported claim.',
|
|
64
|
-
...failures,
|
|
65
|
-
].join('\n'),
|
|
66
|
-
).toEqual([]);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { displayPath, listToolDirectories, read } from './qa-test-helpers';
|
|
5
|
+
|
|
6
|
+
const evidenceClaims = [
|
|
7
|
+
/\bofficial algorithm\b/i,
|
|
8
|
+
/\balgoritmo oficial\b/i,
|
|
9
|
+
/\b(?:records|data|rates|tables) updated(?:\s+(?:to|through)\s+20\d{2})?\b/i,
|
|
10
|
+
/\b(?:registros|datos|tasas|tablas) actualizad[oa]s?(?:\s+(?:a|hasta)\s+20\d{2})?\b/i,
|
|
11
|
+
/\b(?:validated|verified) (?:method|algorithm|calculation)\b/i,
|
|
12
|
+
/\b(?:método|algoritmo|cálculo) (?:validado|verificado)\b/i,
|
|
13
|
+
/\b(?:guarantees|ensures)\b/i,
|
|
14
|
+
/\bgarantiza\b/i,
|
|
15
|
+
/\bofficial (?:data|rate|calculation)\b/i,
|
|
16
|
+
/\b(?:datos|tasa|cálculo) oficial(?:es)?\b/i,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const requiredEvidenceFields = [
|
|
20
|
+
'reviewedAt',
|
|
21
|
+
'methodology',
|
|
22
|
+
'sources',
|
|
23
|
+
'referenceCases',
|
|
24
|
+
'limitations',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
describe('QA: strong factual claims are traceable', () => {
|
|
28
|
+
it('requires machine-readable validation evidence beside tools making strong claims', () => {
|
|
29
|
+
const failures: string[] = [];
|
|
30
|
+
|
|
31
|
+
for (const directory of listToolDirectories()) {
|
|
32
|
+
const localePaths = ['en', 'es']
|
|
33
|
+
.map((locale) => join(directory, 'i18n', `${locale}.ts`))
|
|
34
|
+
.filter(existsSync);
|
|
35
|
+
const claims = localePaths.flatMap((path) => {
|
|
36
|
+
const source = read(path);
|
|
37
|
+
return evidenceClaims
|
|
38
|
+
.filter((pattern) => pattern.test(source))
|
|
39
|
+
.map((pattern) => `${displayPath(path)} matches ${pattern.source}`);
|
|
40
|
+
});
|
|
41
|
+
if (claims.length === 0) continue;
|
|
42
|
+
|
|
43
|
+
const evidencePath = join(directory, 'validation.ts');
|
|
44
|
+
if (!existsSync(evidencePath)) {
|
|
45
|
+
failures.push(`${displayPath(evidencePath)} missing; claims: ${claims.join(' | ')}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const evidence = read(evidencePath);
|
|
50
|
+
const missingFields = requiredEvidenceFields.filter(
|
|
51
|
+
(field) => !new RegExp(`\\b${field}\\s*:`).test(evidence),
|
|
52
|
+
);
|
|
53
|
+
if (missingFields.length > 0) {
|
|
54
|
+
failures.push(`${displayPath(evidencePath)} missing fields: ${missingFields.join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
expect(
|
|
59
|
+
failures,
|
|
60
|
+
[
|
|
61
|
+
'Claims such as official, validated, guaranteed or updated need inspectable evidence.',
|
|
62
|
+
'Add validation.ts with reviewedAt, methodology, sources, referenceCases and limitations,',
|
|
63
|
+
'or weaken/remove the unsupported claim.',
|
|
64
|
+
...failures,
|
|
65
|
+
].join('\n'),
|
|
66
|
+
).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { basename, join } from 'node:path';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import {
|
|
5
|
-
displayPath,
|
|
6
|
-
findFiles,
|
|
7
|
-
listToolDirectories,
|
|
8
|
-
read,
|
|
9
|
-
repositoryRoot,
|
|
10
|
-
} from './qa-test-helpers';
|
|
11
|
-
|
|
12
|
-
function hasDedicatedLogicTest(toolDirectory: string): boolean {
|
|
13
|
-
const localCandidates = [
|
|
14
|
-
join(toolDirectory, 'logic.test.ts'),
|
|
15
|
-
join(toolDirectory, 'logic.spec.ts'),
|
|
16
|
-
join(toolDirectory, '__tests__', 'logic.test.ts'),
|
|
17
|
-
join(toolDirectory, '__tests__', 'logic.spec.ts'),
|
|
18
|
-
];
|
|
19
|
-
if (localCandidates.some(existsSync)) return true;
|
|
20
|
-
|
|
21
|
-
const toolName = basename(toolDirectory);
|
|
22
|
-
const centralTests = findFiles(join(repositoryRoot, 'src', 'tests'), ['.test.ts', '.spec.ts']);
|
|
23
|
-
return centralTests.some((testPath) => {
|
|
24
|
-
const source = read(testPath).replace(/\\/g, '/');
|
|
25
|
-
return source.includes(`/tool/${toolName}/logic`) || source.includes(`../tool/${toolName}/logic`);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('QA: calculation logic has reference tests', () => {
|
|
30
|
-
it('gives every public calculator logic module its own behavioral test suite', () => {
|
|
31
|
-
const failures = listToolDirectories()
|
|
32
|
-
.filter((directory) => existsSync(join(directory, 'logic.ts')))
|
|
33
|
-
.filter((directory) => !hasDedicatedLogicTest(directory))
|
|
34
|
-
.map((directory) => `${displayPath(join(directory, 'logic.ts'))} -> no test imports this module`);
|
|
35
|
-
|
|
36
|
-
expect(
|
|
37
|
-
failures,
|
|
38
|
-
[
|
|
39
|
-
'Add behavioral tests through each logic module public API.',
|
|
40
|
-
'At minimum cover a documented reference case, boundaries, invalid input and invariants.',
|
|
41
|
-
...failures,
|
|
42
|
-
].join('\n'),
|
|
43
|
-
).toEqual([]);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import {
|
|
5
|
+
displayPath,
|
|
6
|
+
findFiles,
|
|
7
|
+
listToolDirectories,
|
|
8
|
+
read,
|
|
9
|
+
repositoryRoot,
|
|
10
|
+
} from './qa-test-helpers';
|
|
11
|
+
|
|
12
|
+
function hasDedicatedLogicTest(toolDirectory: string): boolean {
|
|
13
|
+
const localCandidates = [
|
|
14
|
+
join(toolDirectory, 'logic.test.ts'),
|
|
15
|
+
join(toolDirectory, 'logic.spec.ts'),
|
|
16
|
+
join(toolDirectory, '__tests__', 'logic.test.ts'),
|
|
17
|
+
join(toolDirectory, '__tests__', 'logic.spec.ts'),
|
|
18
|
+
];
|
|
19
|
+
if (localCandidates.some(existsSync)) return true;
|
|
20
|
+
|
|
21
|
+
const toolName = basename(toolDirectory);
|
|
22
|
+
const centralTests = findFiles(join(repositoryRoot, 'src', 'tests'), ['.test.ts', '.spec.ts']);
|
|
23
|
+
return centralTests.some((testPath) => {
|
|
24
|
+
const source = read(testPath).replace(/\\/g, '/');
|
|
25
|
+
return source.includes(`/tool/${toolName}/logic`) || source.includes(`../tool/${toolName}/logic`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('QA: calculation logic has reference tests', () => {
|
|
30
|
+
it('gives every public calculator logic module its own behavioral test suite', () => {
|
|
31
|
+
const failures = listToolDirectories()
|
|
32
|
+
.filter((directory) => existsSync(join(directory, 'logic.ts')))
|
|
33
|
+
.filter((directory) => !hasDedicatedLogicTest(directory))
|
|
34
|
+
.map((directory) => `${displayPath(join(directory, 'logic.ts'))} -> no test imports this module`);
|
|
35
|
+
|
|
36
|
+
expect(
|
|
37
|
+
failures,
|
|
38
|
+
[
|
|
39
|
+
'Add behavioral tests through each logic module public API.',
|
|
40
|
+
'At minimum cover a documented reference case, boundaries, invalid input and invariants.',
|
|
41
|
+
...failures,
|
|
42
|
+
].join('\n'),
|
|
43
|
+
).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { basename, join } from 'node:path';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import {
|
|
5
|
-
displayPath,
|
|
6
|
-
findFiles,
|
|
7
|
-
listToolDirectories,
|
|
8
|
-
read,
|
|
9
|
-
repositoryRoot,
|
|
10
|
-
} from './qa-test-helpers';
|
|
11
|
-
|
|
12
|
-
interface VisibleLiteral {
|
|
13
|
-
line: number;
|
|
14
|
-
value: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const domTextAssignment = /\.(?:innerText|textContent|innerHTML)\s*=/;
|
|
18
|
-
const quotedLiteral = /(['"`])((?:\\.|(?!\1).)*)\1/g;
|
|
19
|
-
|
|
20
|
-
function visibleWords(value: string): string {
|
|
21
|
-
return value
|
|
22
|
-
.replace(/\$\{[^}]*\}/g, ' ')
|
|
23
|
-
.replace(/<[^>]+>/g, ' ')
|
|
24
|
-
.replace(/&[a-z]+;/gi, ' ')
|
|
25
|
-
.replace(/[\d\p{P}\p{S}_]+/gu, ' ')
|
|
26
|
-
.replace(/\s+/g, ' ')
|
|
27
|
-
.trim();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isTechnicalLiteral(value: string): boolean {
|
|
31
|
-
return ['.', '#', '['].some((prefix) => value.startsWith(prefix))
|
|
32
|
-
|| /^data-[a-z0-9-]+$/i.test(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function hardcodedVisibleLiterals(source: string): VisibleLiteral[] {
|
|
36
|
-
const failures: VisibleLiteral[] = [];
|
|
37
|
-
|
|
38
|
-
source.split(/\r?\n/).forEach((line, index) => {
|
|
39
|
-
if (!domTextAssignment.test(line)) return;
|
|
40
|
-
|
|
41
|
-
const assignment = line.slice(line.search(domTextAssignment));
|
|
42
|
-
for (const match of assignment.matchAll(quotedLiteral)) {
|
|
43
|
-
const literal = match[2] ?? '';
|
|
44
|
-
if (isTechnicalLiteral(literal)) continue;
|
|
45
|
-
const words = visibleWords(literal);
|
|
46
|
-
if (words && /\p{L}/u.test(words)) {
|
|
47
|
-
failures.push({ line: index + 1, value: literal });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return failures;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function runtimeSources(toolDirectory: string): string {
|
|
56
|
-
return findFiles(toolDirectory, ['.astro', '.ts', '.js'])
|
|
57
|
-
.filter((path) => !path.includes(`${join(toolDirectory, 'i18n')}`))
|
|
58
|
-
.filter((path) => basename(path) !== 'ui.ts')
|
|
59
|
-
.map(read)
|
|
60
|
-
.join('\n');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe('QA: runtime copy is localized', () => {
|
|
64
|
-
const componentFiles = findFiles(join(repositoryRoot, 'src', 'tool'), ['.astro']);
|
|
65
|
-
|
|
66
|
-
it('does not write user-facing string literals directly into the DOM', () => {
|
|
67
|
-
const failures = componentFiles.flatMap((path) =>
|
|
68
|
-
hardcodedVisibleLiterals(read(path)).map(
|
|
69
|
-
({ line, value }) => `${displayPath(path)}:${line} -> ${JSON.stringify(value)}`,
|
|
70
|
-
),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect(
|
|
74
|
-
failures,
|
|
75
|
-
`Move visible browser copy to the tool UI locale contract:\n${failures.join('\n')}`,
|
|
76
|
-
).toEqual([]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('uses every string declared by each UI locale contract', () => {
|
|
80
|
-
const failures: string[] = [];
|
|
81
|
-
|
|
82
|
-
for (const directory of listToolDirectories()) {
|
|
83
|
-
const uiPath = join(directory, 'ui.ts');
|
|
84
|
-
if (!existsSync(uiPath)) continue;
|
|
85
|
-
|
|
86
|
-
const keys = Array.from(read(uiPath).matchAll(/^\s*(\w+)\??:\s*string\s*;/gm), (match) => match[1]);
|
|
87
|
-
const runtime = runtimeSources(directory);
|
|
88
|
-
const unused = keys.filter((key) => !new RegExp(`\\b${key}\\b`).test(runtime));
|
|
89
|
-
|
|
90
|
-
if (unused.length > 0) {
|
|
91
|
-
failures.push(`${displayPath(uiPath)} -> unused: ${unused.join(', ')}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
expect(
|
|
96
|
-
failures,
|
|
97
|
-
`Unused locale keys are dead copy or may mean the browser bypasses translations:\n${failures.join('\n')}`,
|
|
98
|
-
).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import {
|
|
5
|
+
displayPath,
|
|
6
|
+
findFiles,
|
|
7
|
+
listToolDirectories,
|
|
8
|
+
read,
|
|
9
|
+
repositoryRoot,
|
|
10
|
+
} from './qa-test-helpers';
|
|
11
|
+
|
|
12
|
+
interface VisibleLiteral {
|
|
13
|
+
line: number;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const domTextAssignment = /\.(?:innerText|textContent|innerHTML)\s*=/;
|
|
18
|
+
const quotedLiteral = /(['"`])((?:\\.|(?!\1).)*)\1/g;
|
|
19
|
+
|
|
20
|
+
function visibleWords(value: string): string {
|
|
21
|
+
return value
|
|
22
|
+
.replace(/\$\{[^}]*\}/g, ' ')
|
|
23
|
+
.replace(/<[^>]+>/g, ' ')
|
|
24
|
+
.replace(/&[a-z]+;/gi, ' ')
|
|
25
|
+
.replace(/[\d\p{P}\p{S}_]+/gu, ' ')
|
|
26
|
+
.replace(/\s+/g, ' ')
|
|
27
|
+
.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isTechnicalLiteral(value: string): boolean {
|
|
31
|
+
return ['.', '#', '['].some((prefix) => value.startsWith(prefix))
|
|
32
|
+
|| /^data-[a-z0-9-]+$/i.test(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function hardcodedVisibleLiterals(source: string): VisibleLiteral[] {
|
|
36
|
+
const failures: VisibleLiteral[] = [];
|
|
37
|
+
|
|
38
|
+
source.split(/\r?\n/).forEach((line, index) => {
|
|
39
|
+
if (!domTextAssignment.test(line)) return;
|
|
40
|
+
|
|
41
|
+
const assignment = line.slice(line.search(domTextAssignment));
|
|
42
|
+
for (const match of assignment.matchAll(quotedLiteral)) {
|
|
43
|
+
const literal = match[2] ?? '';
|
|
44
|
+
if (isTechnicalLiteral(literal)) continue;
|
|
45
|
+
const words = visibleWords(literal);
|
|
46
|
+
if (words && /\p{L}/u.test(words)) {
|
|
47
|
+
failures.push({ line: index + 1, value: literal });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return failures;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function runtimeSources(toolDirectory: string): string {
|
|
56
|
+
return findFiles(toolDirectory, ['.astro', '.ts', '.js'])
|
|
57
|
+
.filter((path) => !path.includes(`${join(toolDirectory, 'i18n')}`))
|
|
58
|
+
.filter((path) => basename(path) !== 'ui.ts')
|
|
59
|
+
.map(read)
|
|
60
|
+
.join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('QA: runtime copy is localized', () => {
|
|
64
|
+
const componentFiles = findFiles(join(repositoryRoot, 'src', 'tool'), ['.astro']);
|
|
65
|
+
|
|
66
|
+
it('does not write user-facing string literals directly into the DOM', () => {
|
|
67
|
+
const failures = componentFiles.flatMap((path) =>
|
|
68
|
+
hardcodedVisibleLiterals(read(path)).map(
|
|
69
|
+
({ line, value }) => `${displayPath(path)}:${line} -> ${JSON.stringify(value)}`,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(
|
|
74
|
+
failures,
|
|
75
|
+
`Move visible browser copy to the tool UI locale contract:\n${failures.join('\n')}`,
|
|
76
|
+
).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('uses every string declared by each UI locale contract', () => {
|
|
80
|
+
const failures: string[] = [];
|
|
81
|
+
|
|
82
|
+
for (const directory of listToolDirectories()) {
|
|
83
|
+
const uiPath = join(directory, 'ui.ts');
|
|
84
|
+
if (!existsSync(uiPath)) continue;
|
|
85
|
+
|
|
86
|
+
const keys = Array.from(read(uiPath).matchAll(/^\s*(\w+)\??:\s*string\s*;/gm), (match) => match[1]);
|
|
87
|
+
const runtime = runtimeSources(directory);
|
|
88
|
+
const unused = keys.filter((key) => !new RegExp(`\\b${key}\\b`).test(runtime));
|
|
89
|
+
|
|
90
|
+
if (unused.length > 0) {
|
|
91
|
+
failures.push(`${displayPath(uiPath)} -> unused: ${unused.join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
failures,
|
|
97
|
+
`Unused locale keys are dead copy or may mean the browser bypasses translations:\n${failures.join('\n')}`,
|
|
98
|
+
).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { ALL_TOOLS } from '../tools';
|
|
3
|
-
import type { ToolLocaleContent } from '../types';
|
|
4
|
-
|
|
5
|
-
describe('Schemas Fulfillment Validation', () => {
|
|
6
|
-
ALL_TOOLS.forEach((tool) => {
|
|
7
|
-
describe(`Tool: ${tool.entry.id}`, () => {
|
|
8
|
-
Object.keys(tool.entry.i18n).forEach((locale) => {
|
|
9
|
-
it(`Locale: ${locale} should have faqSchema, appSchema and howToSchema`, async () => {
|
|
10
|
-
const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
|
|
11
|
-
if (!loader) return;
|
|
12
|
-
const content = (await loader()) as ToolLocaleContent;
|
|
13
|
-
|
|
14
|
-
const schemaTypes = content.schemas.map((s: any) => s['@type']);
|
|
15
|
-
|
|
16
|
-
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing FAQPage schema`).toContain('FAQPage');
|
|
17
|
-
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing SoftwareApplication schema`).toContain('SoftwareApplication');
|
|
18
|
-
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing HowTo schema`).toContain('HowTo');
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { ALL_TOOLS } from '../tools';
|
|
3
|
+
import type { ToolLocaleContent } from '../types';
|
|
4
|
+
|
|
5
|
+
describe('Schemas Fulfillment Validation', () => {
|
|
6
|
+
ALL_TOOLS.forEach((tool) => {
|
|
7
|
+
describe(`Tool: ${tool.entry.id}`, () => {
|
|
8
|
+
Object.keys(tool.entry.i18n).forEach((locale) => {
|
|
9
|
+
it(`Locale: ${locale} should have faqSchema, appSchema and howToSchema`, async () => {
|
|
10
|
+
const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
|
|
11
|
+
if (!loader) return;
|
|
12
|
+
const content = (await loader()) as ToolLocaleContent;
|
|
13
|
+
|
|
14
|
+
const schemaTypes = content.schemas.map((s: any) => s['@type']);
|
|
15
|
+
|
|
16
|
+
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing FAQPage schema`).toContain('FAQPage');
|
|
17
|
+
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing SoftwareApplication schema`).toContain('SoftwareApplication');
|
|
18
|
+
expect(schemaTypes, `Tool "${tool.entry.id}" locale "${locale}" is missing HowTo schema`).toContain('HowTo');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|