Skip to content

Commit 7e081da

Browse files
CopilotBlankll
andcommitted
fix: replace hardcoded lang strings with lang values in tests for cross-platform compatibility
Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
1 parent cb05411 commit 7e081da

File tree

4 files changed

+46
-30
lines changed

4 files changed

+46
-30
lines changed

tests/common/iacHelper.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const location = 'tests/fixtures/artifacts/artifact.zip';
1414
describe('Unit test for iacHelper', () => {
1515
beforeAll(() => {
1616
// Set locale to English for consistent test messages
17-
lang.setLocale('en');
17+
lang.setLocale('en-US');
1818
});
1919

2020
beforeEach(() => {
@@ -158,7 +158,7 @@ describe('Unit test for iacHelper', () => {
158158

159159
expect(value).toEqual('');
160160
expect(warnSpy).toHaveBeenCalledWith(
161-
"Variable 'nonExistentVar' not found in vars or parameters, using empty string",
161+
lang.__('VARIABLE_NOT_FOUND', { key: 'nonExistentVar' }),
162162
);
163163
warnSpy.mockRestore();
164164
});
@@ -169,7 +169,7 @@ describe('Unit test for iacHelper', () => {
169169

170170
expect(value).toEqual('');
171171
expect(warnSpy).toHaveBeenCalledWith(
172-
"Stage variable 'nonExistentStage' not found in stage 'test', using empty string",
172+
lang.__('STAGE_VARIABLE_NOT_FOUND', { key: 'nonExistentStage', stage: 'test' }),
173173
);
174174
warnSpy.mockRestore();
175175
});
@@ -188,12 +188,8 @@ describe('Unit test for iacHelper', () => {
188188

189189
expect(value).toEqual('--exists');
190190
expect(warnSpy).toHaveBeenCalledTimes(2);
191-
expect(warnSpy).toHaveBeenCalledWith(
192-
"Variable 'missing1' not found in vars or parameters, using empty string",
193-
);
194-
expect(warnSpy).toHaveBeenCalledWith(
195-
"Variable 'missing2' not found in vars or parameters, using empty string",
196-
);
191+
expect(warnSpy).toHaveBeenCalledWith(lang.__('VARIABLE_NOT_FOUND', { key: 'missing1' }));
192+
expect(warnSpy).toHaveBeenCalledWith(lang.__('VARIABLE_NOT_FOUND', { key: 'missing2' }));
197193
warnSpy.mockRestore();
198194
});
199195
});

tests/common/rosAssets.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jest.mock('../../src/common/context', () => ({
8787
describe('Unit test for rosAssets', () => {
8888
beforeAll(() => {
8989
// Set locale to English for consistent test messages
90-
lang.setLocale('en');
90+
lang.setLocale('en-US');
9191
});
9292

9393
beforeEach(() => {
@@ -165,15 +165,18 @@ describe('Unit test for rosAssets', () => {
165165
]);
166166
expect(mockedInfoLogger.mock.calls).toEqual([
167167
[
168-
'Folder compressed to: path&#x2F;to&#x2F;asset.55d1d2dd5d6c1b083a04c15431f70da1f2840b9de06383411cbf7eda2a512efe.zip',
168+
lang.__('FOLDER_COMPRESSED_TO', {
169+
zipPath:
170+
'path/to/asset.55d1d2dd5d6c1b083a04c15431f70da1f2840b9de06383411cbf7eda2a512efe.zip',
171+
}),
169172
],
170173
]);
171174
});
172175

173176
it('should log and skip if no assets to publish', async () => {
174177
await publishAssets([]);
175178

176-
expect(mockedInfoLogger).toHaveBeenCalledWith('No assets to publish, skipped!');
179+
expect(mockedInfoLogger).toHaveBeenCalledWith(lang.__('NO_ASSETS_TO_PUBLISH'));
177180
});
178181
});
179182

@@ -200,7 +203,7 @@ describe('Unit test for rosAssets', () => {
200203
it('should skip the cleanupAssets when there is no assets', async () => {
201204
await cleanupAssets([]);
202205

203-
expect(mockedInfoLogger).toHaveBeenCalledWith('No assets to cleanup, skipped!');
206+
expect(mockedInfoLogger).toHaveBeenCalledWith(lang.__('NO_ASSETS_TO_CLEANUP'));
204207
});
205208
});
206209
});

tests/common/rosClient.test.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jest.mock('../../src/common/context', () => ({
4848
describe('Unit test for rosClient', () => {
4949
beforeAll(() => {
5050
// Set locale to English for consistent test messages
51-
lang.setLocale('en');
51+
lang.setLocale('en-US');
5252
});
5353

5454
beforeEach(() => {
@@ -62,12 +62,16 @@ describe('Unit test for rosClient', () => {
6262
mockedGetStore.mockReturnValue({ stackName });
6363
mockedListStacks.mockResolvedValue({ statusCode: 200, body: { stacks: [] } });
6464
mockedCreateStack.mockResolvedValue({ body: { stackId: 'newStackId' } });
65-
mockedGetStack.mockResolvedValue({ body: { status: 'CREATE_COMPLETE' } });
65+
mockedGetStack.mockResolvedValue({
66+
body: { status: 'CREATE_COMPLETE', stackName: 'newStack', stackId: 'newStackId' },
67+
});
6668

6769
await rosStackDeploy(stackName, {});
6870

6971
expect(mockedCreateStack).toHaveBeenCalled();
70-
expect(mockedLoggerInfo).toHaveBeenCalledWith(expect.stringContaining('createStack success'));
72+
expect(mockedLoggerInfo).toHaveBeenCalledWith(
73+
lang.__('CREATE_STACK_SUCCESS', { stackName: 'newStack', stackId: 'newStackId' }),
74+
);
7175
});
7276

7377
it('should update an existing stack if it exists', async () => {
@@ -78,12 +82,16 @@ describe('Unit test for rosClient', () => {
7882
body: { stacks: [{ stackId: 'existingStackId', Status: 'CREATE_COMPLETE' }] },
7983
});
8084
mockedUpdateStack.mockResolvedValue({ body: { stackId: 'existingStackId' } });
81-
mockedGetStack.mockResolvedValue({ body: { status: 'UPDATE_COMPLETE' } });
85+
mockedGetStack.mockResolvedValue({
86+
body: { status: 'UPDATE_COMPLETE', stackName: 'existingStack', stackId: 'existingStackId' },
87+
});
8288

8389
await rosStackDeploy(stackName, {});
8490

8591
expect(mockedUpdateStack).toHaveBeenCalled();
86-
expect(mockedLoggerInfo).toHaveBeenCalledWith(expect.stringContaining('stackUpdate success'));
92+
expect(mockedLoggerInfo).toHaveBeenCalledWith(
93+
lang.__('STACK_UPDATE_SUCCESS', { stackName: 'existingStack', stackId: 'existingStackId' }),
94+
);
8795
});
8896

8997
it('should throw an error if the stack is in progress', async () => {
@@ -142,15 +150,21 @@ describe('Unit test for rosClient', () => {
142150

143151
await rosStackDelete(context);
144152

145-
expect(mockedLoggerInfo).toHaveBeenCalledWith('stack status: DELETE_COMPLETE');
146-
expect(mockedLoggerInfo).toHaveBeenCalledWith('Stack: testStack deleted!🗑 ');
153+
expect(mockedLoggerInfo).toHaveBeenCalledWith(
154+
lang.__('STACK_STATUS', { status: 'DELETE_COMPLETE' }),
155+
);
156+
expect(mockedLoggerInfo).toHaveBeenCalledWith(
157+
lang.__('STACK_DELETED', { stackName: 'testStack' }),
158+
);
147159
});
148160

149161
it('should throw an error when the stack does not exist', async () => {
150162
mockedListStacks.mockResolvedValue({ statusCode: 404, body: { stacks: [] } });
151163
await rosStackDelete(context);
152164

153-
expect(mockedLoggerWarn).toHaveBeenCalledWith('Stack: testStack not exists, skipped! 🚫');
165+
expect(mockedLoggerWarn).toHaveBeenCalledWith(
166+
lang.__('STACK_NOT_EXISTS_SKIPPED', { stackName: 'testStack' }),
167+
);
154168
});
155169

156170
it('should throw error when delete stack failed', async () => {
@@ -164,7 +178,10 @@ describe('Unit test for rosClient', () => {
164178
JSON.stringify({ statusCode: 400, Message: 'DELETE_FAILED' }),
165179
);
166180
expect(mockedLoggerError).toHaveBeenCalledWith(
167-
expect.stringContaining('Stack: testStack delete failed! ❌'),
181+
lang.__('STACK_DELETE_FAILED', {
182+
stackName: 'testStack',
183+
error: JSON.stringify({ data: { statusCode: 400, Message: 'DELETE_FAILED' } }),
184+
}),
168185
);
169186
});
170187
});

tests/lang/i18n.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { lang } from '../../src/lang';
33
describe('i18n Language Support', () => {
44
describe('Translation Keys', () => {
55
it('should have English translations', () => {
6-
lang.setLocale('en');
6+
lang.setLocale('en-US');
77
expect(lang.__('YAML_VALID')).toBe('Yaml is valid! 🎉');
88
expect(lang.__('VALIDATING_YAML')).toBe('Validating yaml...');
99
expect(lang.__('DEPLOYING_STACK')).toBe('Deploying stack...');
@@ -19,7 +19,7 @@ describe('i18n Language Support', () => {
1919
});
2020

2121
it('should support parameterized translations in English', () => {
22-
lang.setLocale('en');
22+
lang.setLocale('en-US');
2323
const result = lang.__('CREATING_STACK_ID', { stackId: 'stack-123' });
2424
expect(result).toBe('Creating, Stack ID: stack-123');
2525
});
@@ -31,7 +31,7 @@ describe('i18n Language Support', () => {
3131
});
3232

3333
it('should translate error messages in English', () => {
34-
lang.setLocale('en');
34+
lang.setLocale('en-US');
3535
const result = lang.__('FUNCTION_EXECUTION_ERROR', { error: 'Test error' });
3636
expect(result).toBe('Function execution error: Test error');
3737
});
@@ -43,7 +43,7 @@ describe('i18n Language Support', () => {
4343
});
4444

4545
it('should translate complex parameterized messages in English', () => {
46-
lang.setLocale('en');
46+
lang.setLocale('en-US');
4747
const result = lang.__('DESTROYING_STACK', {
4848
stackName: 'my-stack',
4949
provider: 'aliyun',
@@ -65,8 +65,8 @@ describe('i18n Language Support', () => {
6565

6666
describe('Locale Support', () => {
6767
it('should support English locale', () => {
68-
lang.setLocale('en');
69-
expect(lang.getLocale()).toBe('en');
68+
lang.setLocale('en-US');
69+
expect(lang.getLocale()).toBe('en-US');
7070
});
7171

7272
it('should support Chinese Simplified locale', () => {
@@ -76,7 +76,7 @@ describe('i18n Language Support', () => {
7676

7777
it('should have both locales available', () => {
7878
const locales = lang.getLocales();
79-
expect(locales).toContain('en');
79+
expect(locales).toContain('en-US');
8080
expect(locales).toContain('zh-CN');
8181
});
8282
});
@@ -106,7 +106,7 @@ describe('i18n Language Support', () => {
106106
];
107107

108108
it('should have all critical keys in English', () => {
109-
lang.setLocale('en');
109+
lang.setLocale('en-US');
110110
criticalKeys.forEach((key) => {
111111
const translation = lang.__(key);
112112
expect(translation).toBeTruthy();

0 commit comments

Comments
 (0)