|
2 | 2 | * Copyright (c) Microsoft Corporation. All rights reserved.
|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
| 5 | +import * as fs from 'fs'; |
| 6 | +import * as path from 'path'; |
5 | 7 | import { describe, expect, it } from 'vitest';
|
6 | 8 | import { Config, ConfigKey } from '../../../platform/configuration/common/configurationService';
|
7 | 9 | import { packageJson } from '../../../platform/env/common/packagejson';
|
@@ -76,4 +78,28 @@ describe('Configurations', () => {
|
76 | 78 | expect(publicKeys, 'Setting in package.json is not defined in code').toContain(key);
|
77 | 79 | });
|
78 | 80 | });
|
| 81 | + |
| 82 | + it('all localization strings in package.json are present in package.nls.json', async () => { |
| 83 | + // Get all keys from package.nls.json |
| 84 | + const packageJsonPath = path.join(__dirname, '../../../../package.json'); |
| 85 | + const packageNlsPath = path.join(__dirname, '../../../../package.nls.json'); |
| 86 | + const [packageJsonFileContents, packageNlsFileContents] = await Promise.all( |
| 87 | + [ |
| 88 | + fs.promises.readFile(packageJsonPath, 'utf-8'), |
| 89 | + fs.promises.readFile(packageNlsPath, 'utf-8'), |
| 90 | + ] |
| 91 | + ); |
| 92 | + |
| 93 | + const packageNls = JSON.parse(packageNlsFileContents); |
| 94 | + const nlsKeys = Object.keys(packageNls); |
| 95 | + |
| 96 | + // Find all %key% references in package.json |
| 97 | + const nlsReferences = Array.from(packageJsonFileContents.matchAll(/"%([^"]+)%"/g)).map(match => match[1]); |
| 98 | + |
| 99 | + // Validate all references exist in package.nls.json |
| 100 | + const missingKeys = nlsReferences.filter(key => !nlsKeys.includes(key)); |
| 101 | + if (missingKeys.length > 0) { |
| 102 | + throw new Error(`Missing localization keys in package.nls.json but present in package.json: ${missingKeys.map(key => `'%${key}%'`).join(', ')}`); |
| 103 | + } |
| 104 | + }); |
79 | 105 | });
|
0 commit comments