Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f04aaf

Browse files
authoredAug 26, 2024
tests - depend on a test preload.js (microsoft#226588)
1 parent 8be3fa2 commit 9f04aaf

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed
 

‎src/vs/base/parts/sandbox/test/electron-sandbox/globals.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import assert from 'assert';
7-
import { context, ipcRenderer, process, webFrame, webUtils } from 'vs/base/parts/sandbox/electron-sandbox/globals';
7+
import { ipcRenderer, process, webFrame, webUtils } from 'vs/base/parts/sandbox/electron-sandbox/globals';
88
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
99

1010
suite('Sandbox', () => {
@@ -14,10 +14,6 @@ suite('Sandbox', () => {
1414
assert.ok(typeof webFrame.setZoomLevel === 'function');
1515
assert.ok(typeof process.platform === 'string');
1616
assert.ok(typeof webUtils.getPathForFile === 'function');
17-
18-
const config = await context.resolveConfiguration();
19-
assert.ok(config);
20-
assert.ok(context.configuration());
2117
});
2218

2319
ensureNoDisposablesAreLeakedInTestSuite();

‎test/unit/electron/index.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ app.on('ready', () => {
255255
width: 800,
256256
show: false,
257257
webPreferences: {
258-
preload: path.join(__dirname, '..', '..', '..', 'src', 'vs', 'base', 'parts', 'sandbox', 'electron-sandbox', 'preload.js'), // ensure similar environment as VSCode as tests may depend on this
258+
preload: path.join(__dirname, 'preload.js'), // ensure similar environment as VSCode as tests may depend on this
259259
additionalArguments: [`--vscode-window-config=vscode:test-vscode-window-config`],
260260
nodeIntegration: true,
261261
contextIsolation: false,

‎test/unit/electron/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ app.on('ready', () => {
249249
width: 800,
250250
show: false,
251251
webPreferences: {
252-
preload: path.join(__dirname, '..', '..', '..', 'src', 'vs', 'base', 'parts', 'sandbox', 'electron-sandbox', 'preload.js'), // ensure similar environment as VSCode as tests may depend on this
252+
preload: path.join(__dirname, 'preload.js'),
253253
additionalArguments: [`--vscode-window-config=vscode:test-vscode-window-config`],
254254
nodeIntegration: true,
255255
contextIsolation: false,

‎test/unit/electron/preload.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// @ts-check
7+
(function () {
8+
'use strict';
9+
10+
const { ipcRenderer, webFrame, contextBridge, webUtils } = require('electron');
11+
12+
const globals = {
13+
14+
ipcRenderer: {
15+
16+
send(channel, ...args) {
17+
ipcRenderer.send(channel, ...args);
18+
},
19+
20+
invoke(channel, ...args) {
21+
return ipcRenderer.invoke(channel, ...args);
22+
},
23+
24+
on(channel, listener) {
25+
ipcRenderer.on(channel, listener);
26+
27+
return this;
28+
},
29+
30+
once(channel, listener) {
31+
ipcRenderer.once(channel, listener);
32+
33+
return this;
34+
},
35+
36+
removeListener(channel, listener) {
37+
ipcRenderer.removeListener(channel, listener);
38+
39+
return this;
40+
}
41+
},
42+
43+
webFrame: {
44+
45+
setZoomLevel(level) {
46+
if (typeof level === 'number') {
47+
webFrame.setZoomLevel(level);
48+
}
49+
}
50+
},
51+
52+
webUtils: {
53+
54+
getPathForFile(file) {
55+
return webUtils.getPathForFile(file);
56+
}
57+
},
58+
59+
process: {
60+
get platform() { return process.platform; },
61+
get arch() { return process.arch; },
62+
get env() { return { ...process.env }; },
63+
get versions() { return process.versions; },
64+
get type() { return 'renderer'; },
65+
get execPath() { return process.execPath; },
66+
67+
cwd() {
68+
return process.env['VSCODE_CWD'] || process.execPath.substr(0, process.execPath.lastIndexOf(process.platform === 'win32' ? '\\' : '/'));
69+
},
70+
71+
getProcessMemoryInfo() {
72+
return process.getProcessMemoryInfo();
73+
},
74+
75+
on(type, callback) {
76+
// @ts-ignore
77+
process.on(type, callback);
78+
}
79+
},
80+
};
81+
82+
if (process.contextIsolated) {
83+
try {
84+
contextBridge.exposeInMainWorld('vscode', globals);
85+
} catch (error) {
86+
console.error(error);
87+
}
88+
} else {
89+
// @ts-ignore
90+
window.vscode = globals;
91+
}
92+
}());

0 commit comments

Comments
 (0)
Please sign in to comment.