Skip to content

Commit 8f06ad7

Browse files
committed
feat: Add tests for SageMaker UI Dark Theme extension
**Description** - Adding tests for SageMaker UI Dark Theme extension **Testing Done** - Tested locally with `yarn test-extension -l sagemaker-ui-dark-theme`
1 parent 3cd6872 commit 8f06ad7

File tree

4 files changed

+343
-0
lines changed

4 files changed

+343
-0
lines changed

patched-vscode/.vscode-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const extensions = [
4545
label: 'github-authentication',
4646
workspaceFolder: path.join(os.tmpdir(), `msft-auth-${Math.floor(Math.random() * 100000)}`),
4747
mocha: { timeout: 60_000 }
48+
},
49+
{
50+
label: 'sagemaker-ui-dark-theme',
51+
workspaceFolder: `extensions/sagemaker-ui-dark-theme/test-workspace`,
52+
mocha: { timeout: 60_000 }
4853
}
4954
];
5055

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import * as assert from 'assert';
2+
import * as vscode from 'vscode';
3+
4+
const DEFAULT_DARK_MODERN = 'Default Dark Modern';
5+
const DEFAULT_LIGHT_MODERN = 'Default Light Modern';
6+
7+
async function waitForThemeChange(expectedTheme: string | undefined, timeoutMs: number): Promise<void> {
8+
const startTime = Date.now();
9+
10+
while (Date.now() - startTime < timeoutMs) {
11+
const currentTheme = vscode.workspace.getConfiguration('workbench').inspect('colorTheme');
12+
13+
if (currentTheme?.globalValue === expectedTheme) {
14+
return;
15+
}
16+
await new Promise(resolve => setTimeout(resolve, 100));
17+
}
18+
throw new Error(`Theme did not change to ${expectedTheme} at the global level within ${timeoutMs}ms`);
19+
}
20+
21+
suite('SageMaker UI Dark Theme Extension Tests - In SageMaker Unified Studio Environment', () => {
22+
// Store original ENV variable value
23+
const originalEnv = process.env.SERVICE_NAME;
24+
25+
suiteSetup(() => {
26+
// Clear the theme configurations
27+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
28+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
29+
30+
// Set ENV variable value for SageMaker Unified Studio environment
31+
process.env.SERVICE_NAME = 'SageMakerUnifiedStudio';
32+
});
33+
34+
suiteTeardown(() => {
35+
// Clear the theme configurations
36+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
37+
38+
// Restore ENV variable value to original
39+
originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
40+
});
41+
42+
test('Theme is set when global and workspace theme configurations are unset', async () => {
43+
// Poll for theme update
44+
await waitForThemeChange(DEFAULT_DARK_MODERN, 10000);
45+
46+
const config = vscode.workspace.getConfiguration();
47+
const theme = config.inspect('workbench.colorTheme');
48+
49+
assert.strictEqual(theme?.globalValue, DEFAULT_DARK_MODERN, `Global theme should be set to ${DEFAULT_DARK_MODERN}`);
50+
});
51+
});
52+
53+
suite('SageMaker UI Dark Theme Extension Tests - In SageMaker Unified Studio Environment', () => {
54+
// Store original ENV variable value
55+
const originalEnv = process.env.SERVICE_NAME;
56+
57+
suiteSetup(() => {
58+
// Set the global theme configuration to Default Light Modern
59+
vscode.workspace.getConfiguration('workbench').update('colorTheme', DEFAULT_LIGHT_MODERN, vscode.ConfigurationTarget.Global);
60+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
61+
62+
// Set ENV variable value for SageMaker Unified Studio environment
63+
process.env.SERVICE_NAME = 'SageMakerUnifiedStudio';
64+
});
65+
66+
suiteTeardown(() => {
67+
// Clear the theme configurations
68+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
69+
70+
// Restore ENV variable value to original
71+
originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
72+
});
73+
74+
test('Theme is not set when global theme configuration is set', async () => {
75+
// Poll for theme update
76+
await waitForThemeChange(DEFAULT_LIGHT_MODERN, 10000);
77+
78+
// Poll for Default Dark Modern theme update (expected to fail)
79+
try {
80+
await waitForThemeChange(DEFAULT_DARK_MODERN, 10000);
81+
assert.fail(`Global theme should be kept as ${DEFAULT_LIGHT_MODERN}`);
82+
} catch (error) {
83+
// Expected behavior: Theme should not be set
84+
}
85+
86+
const config = vscode.workspace.getConfiguration();
87+
const theme = config.inspect('workbench.colorTheme');
88+
89+
assert.strictEqual(theme?.globalValue, DEFAULT_LIGHT_MODERN, `Global theme should be kept as ${DEFAULT_LIGHT_MODERN}`);
90+
});
91+
});
92+
93+
suite('SageMaker UI Dark Theme Extension Tests - In SageMaker AI Environment', () => {
94+
// Store original ENV variable value
95+
const originalEnv = process.env.SERVICE_NAME;
96+
97+
suiteSetup(() => {
98+
// Clear the global theme configuration
99+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
100+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
101+
102+
// Ensure ENV variable value for SageMaker Unified Studio environment is NOT set
103+
delete process.env.SERVICE_NAME;
104+
});
105+
106+
suiteTeardown(() => {
107+
// Clear the global theme configuration
108+
vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
109+
110+
// Restore ENV variable value to original
111+
originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
112+
});
113+
114+
test('Theme is not set', async () => {
115+
// Poll for theme update
116+
await waitForThemeChange(undefined, 10000);
117+
118+
const config = vscode.workspace.getConfiguration();
119+
const theme = config.inspect('workbench.colorTheme');
120+
121+
assert.strictEqual(theme?.globalValue, undefined, 'Global theme should not be set');
122+
});
123+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as path from 'path';
2+
import * as testRunner from '../../../../test/integration/electron/testrunner';
3+
4+
const options: import('mocha').MochaOptions = {
5+
ui: 'tdd',
6+
color: true,
7+
timeout: 60000
8+
};
9+
10+
// Set the suite name
11+
let suite = '';
12+
if (process.env.VSCODE_BROWSER) {
13+
suite = `${process.env.VSCODE_BROWSER} Browser Integration SageMaker UI Dark Theme Tests`;
14+
} else if (process.env.REMOTE_VSCODE) {
15+
suite = 'Remote Integration SageMaker UI Dark Theme Tests';
16+
} else {
17+
suite = 'Integration SageMaker UI Dark Theme Tests';
18+
}
19+
20+
if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
21+
options.reporter = 'mocha-multi-reporters';
22+
options.reporterOptions = {
23+
reporterEnabled: 'spec, mocha-junit-reporter',
24+
mochaJunitReporterReporterOptions: {
25+
testsuitesTitle: `${suite} ${process.platform}`,
26+
mochaFile: path.join(process.env.BUILD_ARTIFACTSTAGINGDIRECTORY, `test-results/${process.platform}-${process.arch}-${suite.toLowerCase().replace(/[^\w]/g, '-')}-results.xml`)
27+
}
28+
};
29+
}
30+
31+
testRunner.configure(options);
32+
33+
export = testRunner;

patches/sagemaker-ui-dark-theme.patch

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,185 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-ui-dark-theme/package.j
236236
+ "repository": {
237237
+ }
238238
+}
239+
Index: sagemaker-code-editor/vscode/.vscode-test.js
240+
===================================================================
241+
--- sagemaker-code-editor.orig/vscode/.vscode-test.js
242+
+++ sagemaker-code-editor/vscode/.vscode-test.js
243+
@@ -45,6 +45,11 @@ const extensions = [
244+
label: 'github-authentication',
245+
workspaceFolder: path.join(os.tmpdir(), `msft-auth-${Math.floor(Math.random() * 100000)}`),
246+
mocha: { timeout: 60_000 }
247+
+ },
248+
+ {
249+
+ label: 'sagemaker-ui-dark-theme',
250+
+ workspaceFolder: `extensions/sagemaker-ui-dark-theme/test-workspace`,
251+
+ mocha: { timeout: 60_000 }
252+
}
253+
];
254+
255+
Index: sagemaker-code-editor/vscode/extensions/sagemaker-ui-dark-theme/src/test/extension.test.ts
256+
===================================================================
257+
--- /dev/null
258+
+++ sagemaker-code-editor/vscode/extensions/sagemaker-ui-dark-theme/src/test/extension.test.ts
259+
@@ -0,0 +1,123 @@
260+
+import * as assert from 'assert';
261+
+import * as vscode from 'vscode';
262+
+
263+
+const DEFAULT_DARK_MODERN = 'Default Dark Modern';
264+
+const DEFAULT_LIGHT_MODERN = 'Default Light Modern';
265+
+
266+
+async function waitForThemeChange(expectedTheme: string | undefined, timeoutMs: number): Promise<void> {
267+
+ const startTime = Date.now();
268+
+
269+
+ while (Date.now() - startTime < timeoutMs) {
270+
+ const currentTheme = vscode.workspace.getConfiguration('workbench').inspect('colorTheme');
271+
+
272+
+ if (currentTheme?.globalValue === expectedTheme) {
273+
+ return;
274+
+ }
275+
+ await new Promise(resolve => setTimeout(resolve, 100));
276+
+ }
277+
+ throw new Error(`Theme did not change to ${expectedTheme} at the global level within ${timeoutMs}ms`);
278+
+}
279+
+
280+
+suite('SageMaker UI Dark Theme Extension Tests - In SageMaker Unified Studio Environment', () => {
281+
+ // Store original ENV variable value
282+
+ const originalEnv = process.env.SERVICE_NAME;
283+
+
284+
+ suiteSetup(() => {
285+
+ // Clear the theme configurations
286+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
287+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
288+
+
289+
+ // Set ENV variable value for SageMaker Unified Studio environment
290+
+ process.env.SERVICE_NAME = 'SageMakerUnifiedStudio';
291+
+ });
292+
+
293+
+ suiteTeardown(() => {
294+
+ // Clear the theme configurations
295+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
296+
+
297+
+ // Restore ENV variable value to original
298+
+ originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
299+
+ });
300+
+
301+
+ test('Theme is set when global and workspace theme configurations are unset', async () => {
302+
+ // Poll for theme update
303+
+ await waitForThemeChange(DEFAULT_DARK_MODERN, 10000);
304+
+
305+
+ const config = vscode.workspace.getConfiguration();
306+
+ const theme = config.inspect('workbench.colorTheme');
307+
+
308+
+ assert.strictEqual(theme?.globalValue, DEFAULT_DARK_MODERN, `Global theme should be set to ${DEFAULT_DARK_MODERN}`);
309+
+ });
310+
+});
311+
+
312+
+suite('SageMaker UI Dark Theme Extension Tests - In SageMaker Unified Studio Environment', () => {
313+
+ // Store original ENV variable value
314+
+ const originalEnv = process.env.SERVICE_NAME;
315+
+
316+
+ suiteSetup(() => {
317+
+ // Set the global theme configuration to Default Light Modern
318+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', DEFAULT_LIGHT_MODERN, vscode.ConfigurationTarget.Global);
319+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
320+
+
321+
+ // Set ENV variable value for SageMaker Unified Studio environment
322+
+ process.env.SERVICE_NAME = 'SageMakerUnifiedStudio';
323+
+ });
324+
+
325+
+ suiteTeardown(() => {
326+
+ // Clear the theme configurations
327+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
328+
+
329+
+ // Restore ENV variable value to original
330+
+ originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
331+
+ });
332+
+
333+
+ test('Theme is not set when global theme configuration is set', async () => {
334+
+ // Poll for theme update
335+
+ await waitForThemeChange(DEFAULT_LIGHT_MODERN, 10000);
336+
+
337+
+ // Poll for Default Dark Modern theme update (expected to fail)
338+
+ try {
339+
+ await waitForThemeChange(DEFAULT_DARK_MODERN, 10000);
340+
+ assert.fail(`Global theme should be kept as ${DEFAULT_LIGHT_MODERN}`);
341+
+ } catch (error) {
342+
+ // Expected behavior: Theme should not be set
343+
+ }
344+
+
345+
+ const config = vscode.workspace.getConfiguration();
346+
+ const theme = config.inspect('workbench.colorTheme');
347+
+
348+
+ assert.strictEqual(theme?.globalValue, DEFAULT_LIGHT_MODERN, `Global theme should be kept as ${DEFAULT_LIGHT_MODERN}`);
349+
+ });
350+
+});
351+
+
352+
+suite('SageMaker UI Dark Theme Extension Tests - In SageMaker AI Environment', () => {
353+
+ // Store original ENV variable value
354+
+ const originalEnv = process.env.SERVICE_NAME;
355+
+
356+
+ suiteSetup(() => {
357+
+ // Clear the global theme configuration
358+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
359+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Workspace);
360+
+
361+
+ // Ensure ENV variable value for SageMaker Unified Studio environment is NOT set
362+
+ delete process.env.SERVICE_NAME;
363+
+ });
364+
+
365+
+ suiteTeardown(() => {
366+
+ // Clear the global theme configuration
367+
+ vscode.workspace.getConfiguration('workbench').update('colorTheme', undefined, vscode.ConfigurationTarget.Global);
368+
+
369+
+ // Restore ENV variable value to original
370+
+ originalEnv ? (process.env.SERVICE_NAME = originalEnv) : delete process.env.SERVICE_NAME;
371+
+ });
372+
+
373+
+ test('Theme is not set', async () => {
374+
+ // Poll for theme update
375+
+ await waitForThemeChange(undefined, 10000);
376+
+
377+
+ const config = vscode.workspace.getConfiguration();
378+
+ const theme = config.inspect('workbench.colorTheme');
379+
+
380+
+ assert.strictEqual(theme?.globalValue, undefined, 'Global theme should not be set');
381+
+ });
382+
+});
383+
Index: sagemaker-code-editor/vscode/extensions/sagemaker-ui-dark-theme/src/test/index.ts
384+
===================================================================
385+
--- /dev/null
386+
+++ sagemaker-code-editor/vscode/extensions/sagemaker-ui-dark-theme/src/test/index.ts
387+
@@ -0,0 +1,33 @@
388+
+import * as path from 'path';
389+
+import * as testRunner from '../../../../test/integration/electron/testrunner';
390+
+
391+
+const options: import('mocha').MochaOptions = {
392+
+ ui: 'tdd',
393+
+ color: true,
394+
+ timeout: 60000
395+
+};
396+
+
397+
+// Set the suite name
398+
+let suite = '';
399+
+if (process.env.VSCODE_BROWSER) {
400+
+ suite = `${process.env.VSCODE_BROWSER} Browser Integration SageMaker UI Dark Theme Tests`;
401+
+} else if (process.env.REMOTE_VSCODE) {
402+
+ suite = 'Remote Integration SageMaker UI Dark Theme Tests';
403+
+} else {
404+
+ suite = 'Integration SageMaker UI Dark Theme Tests';
405+
+}
406+
+
407+
+if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
408+
+ options.reporter = 'mocha-multi-reporters';
409+
+ options.reporterOptions = {
410+
+ reporterEnabled: 'spec, mocha-junit-reporter',
411+
+ mochaJunitReporterReporterOptions: {
412+
+ testsuitesTitle: `${suite} ${process.platform}`,
413+
+ mochaFile: path.join(process.env.BUILD_ARTIFACTSTAGINGDIRECTORY, `test-results/${process.platform}-${process.arch}-${suite.toLowerCase().replace(/[^\w]/g, '-')}-results.xml`)
414+
+ }
415+
+ };
416+
+}
417+
+
418+
+testRunner.configure(options);
419+
+
420+
+export = testRunner;

0 commit comments

Comments
 (0)