/*--------------------------------------------------------- * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ import * as path from 'path'; import * as mockery from 'mockery'; export function setupUnhandledRejectionListener(): void { process.addListener('unhandledRejection', unhandledRejectionListener); } export function removeUnhandledRejectionListener(): void { process.removeListener('unhandledRejection', unhandledRejectionListener); } function unhandledRejectionListener(reason: any, p: Promise) { console.log('*'); console.log('**'); console.log('***'); console.log('****'); console.log('*****'); console.log(`ERROR!! Unhandled promise rejection, a previous test may have failed but reported success.`); console.log(reason.toString()); console.log('*****'); console.log('****'); console.log('***'); console.log('**'); console.log('*'); } /** * path.resolve + fixing the drive letter to match what VS Code does. Basically tests can use this when they * want to force a path to native slashes and the correct letter case, but maybe can't use un-mocked utils. */ export function pathResolve(...segments: string[]): string { let aPath = path.resolve.apply(null, segments); if (aPath.match(/^[A-Za-z]:/)) { aPath = aPath[0].toLowerCase() + aPath.substr(1); } return aPath; } export function registerLocMocks(): void { mockery.registerMock('vscode-nls', { config: () => () => dummyLocalize, loadMessageBundle: () => dummyLocalize }); } function dummyLocalize(id: string, englishString: string): string { return englishString; }