Path: blob/main/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { isMacintosh, isWindows } from '../../../../base/common/platform.js';7import { flakySuite } from '../../../../base/test/common/testUtils.js';89function testErrorMessage(module: string): string {10return `Unable to load "${module}" dependency. It was probably not compiled for the right operating system architecture or had missing build tools.`;11}1213flakySuite('Native Modules (all platforms)', () => {1415(isMacintosh ? test.skip : test)('kerberos', async () => { // Somehow fails on macOS ARM?16const { default: kerberos } = await import('kerberos');17assert.ok(typeof kerberos.initializeClient === 'function', testErrorMessage('kerberos'));18});1920test('yauzl', async () => {21const { default: yauzl } = await import('yauzl');22assert.ok(typeof yauzl.ZipFile === 'function', testErrorMessage('yauzl'));23});2425test('yazl', async () => {26const { default: yazl } = await import('yazl');27assert.ok(typeof yazl.ZipFile === 'function', testErrorMessage('yazl'));28});2930test('v8-inspect-profiler', async () => {31const { default: profiler } = await import('v8-inspect-profiler');32assert.ok(typeof profiler.startProfiling === 'function', testErrorMessage('v8-inspect-profiler'));33});3435test('native-is-elevated', async () => {36const { default: isElevated } = await import('native-is-elevated');37assert.ok(typeof isElevated === 'function', testErrorMessage('native-is-elevated '));3839const result = isElevated();40assert.ok(typeof result === 'boolean', testErrorMessage('native-is-elevated'));41});4243test('native-keymap', async () => {44const keyMap = await import('native-keymap');45assert.ok(typeof keyMap.onDidChangeKeyboardLayout === 'function', testErrorMessage('native-keymap'));46assert.ok(typeof keyMap.getCurrentKeyboardLayout === 'function', testErrorMessage('native-keymap'));4748const result = keyMap.getCurrentKeyboardLayout();49assert.ok(result, testErrorMessage('native-keymap'));50});5152test('native-watchdog', async () => {53const watchDog = await import('native-watchdog');54assert.ok(typeof watchDog.start === 'function', testErrorMessage('native-watchdog'));55});5657test('@vscode/sudo-prompt', async () => {58const prompt = await import('@vscode/sudo-prompt');59assert.ok(typeof prompt.exec === 'function', testErrorMessage('@vscode/sudo-prompt'));60});6162test('@vscode/policy-watcher', async () => {63const watcher = await import('@vscode/policy-watcher');64assert.ok(typeof watcher.createWatcher === 'function', testErrorMessage('@vscode/policy-watcher'));65});6667test('node-pty', async () => {68const nodePty = await import('node-pty');69assert.ok(typeof nodePty.spawn === 'function', testErrorMessage('node-pty'));70});7172test('@vscode/spdlog', async () => {73const spdlog = await import('@vscode/spdlog');74assert.ok(typeof spdlog.createRotatingLogger === 'function', testErrorMessage('@vscode/spdlog'));75assert.ok(typeof spdlog.version === 'number', testErrorMessage('@vscode/spdlog'));76});7778test('@parcel/watcher', async () => {79const parcelWatcher = await import('@parcel/watcher');80assert.ok(typeof parcelWatcher.subscribe === 'function', testErrorMessage('@parcel/watcher'));81});8283test('@vscode/deviceid', async () => {84const deviceIdPackage = await import('@vscode/deviceid');85assert.ok(typeof deviceIdPackage.getDeviceId === 'function', testErrorMessage('@vscode/deviceid'));86});8788test('@vscode/ripgrep', async () => {89const ripgrep = await import('@vscode/ripgrep');90assert.ok(typeof ripgrep.rgPath === 'string', testErrorMessage('@vscode/ripgrep'));91});9293test('vscode-regexpp', async () => {94const regexpp = await import('vscode-regexpp');95assert.ok(typeof regexpp.RegExpParser === 'function', testErrorMessage('vscode-regexpp'));96});9798test('@vscode/sqlite3', async () => {99const { default: sqlite3 } = await import('@vscode/sqlite3');100assert.ok(typeof sqlite3.Database === 'function', testErrorMessage('@vscode/sqlite3'));101});102103test('http-proxy-agent', async () => {104const { default: mod } = await import('http-proxy-agent');105assert.ok(typeof mod.HttpProxyAgent === 'function', testErrorMessage('http-proxy-agent'));106});107108test('https-proxy-agent', async () => {109const { default: mod } = await import('https-proxy-agent');110assert.ok(typeof mod.HttpsProxyAgent === 'function', testErrorMessage('https-proxy-agent'));111});112113test('@vscode/proxy-agent', async () => {114const proxyAgent = await import('@vscode/proxy-agent');115// This call will load `@vscode/proxy-agent` which is a native module that we want to test on Windows116const windowsCerts = await proxyAgent.loadSystemCertificates({117log: {118trace: () => { },119debug: () => { },120info: () => { },121warn: () => { },122error: () => { }123}124});125assert.ok(windowsCerts.length > 0, testErrorMessage('@vscode/proxy-agent'));126});127});128129(!isWindows ? suite.skip : suite)('Native Modules (Windows)', () => {130131test('@vscode/windows-mutex', async () => {132const mutex = await import('@vscode/windows-mutex');133assert.ok(mutex && typeof mutex.isActive === 'function', testErrorMessage('@vscode/windows-mutex'));134assert.ok(typeof mutex.isActive === 'function', testErrorMessage('@vscode/windows-mutex'));135assert.ok(typeof mutex.Mutex === 'function', testErrorMessage('@vscode/windows-mutex'));136});137138test('windows-foreground-love', async () => {139const foregroundLove = await import('windows-foreground-love');140assert.ok(typeof foregroundLove.allowSetForegroundWindow === 'function', testErrorMessage('windows-foreground-love'));141142const result = foregroundLove.allowSetForegroundWindow(process.pid);143assert.ok(typeof result === 'boolean', testErrorMessage('windows-foreground-love'));144});145146test('@vscode/windows-process-tree', async () => {147const processTree = await import('@vscode/windows-process-tree');148assert.ok(typeof processTree.getProcessTree === 'function', testErrorMessage('@vscode/windows-process-tree'));149150return new Promise((resolve, reject) => {151processTree.getProcessTree(process.pid, tree => {152if (tree) {153resolve();154} else {155reject(new Error(testErrorMessage('@vscode/windows-process-tree')));156}157});158});159});160161test('@vscode/windows-registry', async () => {162const windowsRegistry = await import('@vscode/windows-registry');163assert.ok(typeof windowsRegistry.GetStringRegKey === 'function', testErrorMessage('@vscode/windows-registry'));164165const result = windowsRegistry.GetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID');166assert.ok(typeof result === 'string' || typeof result === 'undefined', testErrorMessage('@vscode/windows-registry'));167});168});169170171