/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { join } from 'vs/base/common/path'; import { URI } from 'vs/base/common/uri'; import { canceled } from 'vs/base/common/errors'; import { isWindows } from 'vs/base/common/platform'; export type ValueCallback = (value: T | Promise) => void; export class DeferredPromise { private completeCallback!: ValueCallback; private errorCallback!: (err: any) => void; public p: Promise; constructor() { this.p = new Promise((c, e) => { this.completeCallback = c; this.errorCallback = e; }); } public complete(value: T) { return new Promise(resolve => { this.completeCallback(value); resolve(); }); } public error(err: any) { return new Promise(resolve => { this.errorCallback(err); resolve(); }); } public cancel() { new Promise(resolve => { this.errorCallback(canceled()); resolve(); }); } } export function toResource(this: any, path: string) { if (isWindows) { return URI.file(join('C:\\', btoa(this.test.fullTitle()), path)); } return URI.file(join('/', btoa(this.test.fullTitle()), path)); } export function suiteRepeat(n: number, description: string, callback: (this: any) => void): void { for (let i = 0; i < n; i++) { suite(`${description} (iteration ${i})`, callback); } } export function testRepeat(n: number, description: string, callback: (this: any, done: MochaDone) => any): void { for (let i = 0; i < n; i++) { test(`${description} (iteration ${i})`, callback); } }