Skip to content

Commit 39cc1e1

Browse files
authored
native modules tests (microsoft#143505)
1 parent 0e8fceb commit 39cc1e1

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

src/vs/platform/environment/test/node/nativeModules.test.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as assert from 'assert';
77
import { isLinux, isWindows } from 'vs/base/common/platform';
88
import { flakySuite } from 'vs/base/test/common/testUtils';
9+
import { Encryption } from 'vs/platform/encryption/node/encryptionMainService';
910

1011
function testErrorMessage(module: string): string {
1112
return `Unable to load "${module}" dependency. It was probably not compiled for the right operating system architecture or had missing build tools.`;
@@ -16,11 +17,17 @@ flakySuite('Native Modules (all platforms)', () => {
1617
test('native-is-elevated', async () => {
1718
const isElevated = await import('native-is-elevated');
1819
assert.ok(typeof isElevated === 'function', testErrorMessage('native-is-elevated '));
20+
21+
const result = isElevated();
22+
assert.ok(typeof result === 'boolean', testErrorMessage('native-is-elevated'));
1923
});
2024

2125
test('native-keymap', async () => {
2226
const keyMap = await import('native-keymap');
2327
assert.ok(typeof keyMap.getCurrentKeyboardLayout === 'function', testErrorMessage('native-keymap'));
28+
29+
const result = keyMap.getCurrentKeyboardLayout();
30+
assert.ok(result, testErrorMessage('native-keymap'));
2431
});
2532

2633
test('native-watchdog', async () => {
@@ -36,17 +43,46 @@ flakySuite('Native Modules (all platforms)', () => {
3643
(process.type === 'renderer' ? test.skip /* TODO@electron module is not context aware yet and thus cannot load in Electron renderer used by tests */ : test)('spdlog', async () => {
3744
const spdlog = await import('spdlog');
3845
assert.ok(typeof spdlog.createRotatingLogger === 'function', testErrorMessage('spdlog'));
46+
assert.ok(typeof spdlog.version === 'number', testErrorMessage('spdlog'));
3947
});
4048

4149
test('@parcel/watcher', async () => {
4250
const parcelWatcher = await import('@parcel/watcher');
43-
assert.ok(typeof parcelWatcher.subscribe === 'function', testErrorMessage('parcel'));
51+
assert.ok(typeof parcelWatcher.subscribe === 'function', testErrorMessage('@parcel/watcher'));
4452
});
4553

4654
test('@vscode/sqlite3', async () => {
4755
const sqlite3 = await import('@vscode/sqlite3');
4856
assert.ok(typeof sqlite3.Database === 'function', testErrorMessage('@vscode/sqlite3'));
4957
});
58+
59+
test('vscode-encrypt', async () => {
60+
try {
61+
const vscodeEncrypt: Encryption = require.__$__nodeRequire('vscode-encrypt');
62+
const encrypted = await vscodeEncrypt.encrypt('salt', 'value');
63+
const decrypted = await vscodeEncrypt.decrypt('salt', encrypted);
64+
65+
assert.ok(typeof encrypted === 'string', testErrorMessage('vscode-encrypt'));
66+
assert.ok(typeof decrypted === 'string', testErrorMessage('vscode-encrypt'));
67+
} catch (error) {
68+
if (error.code !== 'MODULE_NOT_FOUND') {
69+
throw error;
70+
}
71+
}
72+
});
73+
74+
test('vsda', async () => {
75+
try {
76+
const vsda: any = require.__$__nodeRequire('vsda');
77+
const signer = new vsda.signer();
78+
const signed = await signer.sign('value');
79+
assert.ok(typeof signed === 'string', testErrorMessage('vsda'));
80+
} catch (error) {
81+
if (error.code !== 'MODULE_NOT_FOUND') {
82+
throw error;
83+
}
84+
}
85+
});
5086
});
5187

5288
(isLinux ? suite.skip : suite)('Native Modules (Windows, macOS)', () => {
@@ -82,16 +118,32 @@ flakySuite('Native Modules (all platforms)', () => {
82118
test('windows-foreground-love', async () => {
83119
const foregroundLove = await import('windows-foreground-love');
84120
assert.ok(typeof foregroundLove.allowSetForegroundWindow === 'function', testErrorMessage('windows-foreground-love'));
121+
122+
const result = foregroundLove.allowSetForegroundWindow(process.pid);
123+
assert.ok(typeof result === 'boolean', testErrorMessage('windows-foreground-love'));
85124
});
86125

87126
test('windows-process-tree', async () => {
88127
const processTree = await import('windows-process-tree');
89128
assert.ok(typeof processTree.getProcessTree === 'function', testErrorMessage('windows-process-tree'));
129+
130+
return new Promise((resolve, reject) => {
131+
processTree.getProcessTree(process.pid, tree => {
132+
if (tree) {
133+
resolve();
134+
} else {
135+
reject(new Error(testErrorMessage('windows-process-tree')));
136+
}
137+
});
138+
});
90139
});
91140

92141
test('@vscode/windows-registry', async () => {
93142
const windowsRegistry = await import('@vscode/windows-registry');
94143
assert.ok(typeof windowsRegistry.GetStringRegKey === 'function', testErrorMessage('@vscode/windows-registry'));
144+
145+
const result = windowsRegistry.GetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID');
146+
assert.ok(typeof result === 'string' || typeof result === 'undefined', testErrorMessage('@vscode/windows-registry'));
95147
});
96148

97149
test('vscode-windows-ca-certs', async () => {

0 commit comments

Comments
 (0)