Skip to content

Commit

Permalink
Merge pull request #76061 from microsoft/octref/new-test-runner-api
Browse files Browse the repository at this point in the history
New test runner api
  • Loading branch information
octref committed Jun 25, 2019
2 parents b78d8d5 + a559a21 commit e80dd4f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/vs/workbench/api/node/extHostExtensionService.ts
Expand Up @@ -36,9 +36,15 @@ import { RemoteAuthorityResolverError, ExtensionExecutionContext } from 'vs/work
import { IURITransformer } from 'vs/base/common/uriIpc';

interface ITestRunner {
/** Old test runner API, as exported from `vscode/lib/testrunner` */
run(testsRoot: string, clb: (error: Error, failures?: number) => void): void;
}

interface INewTestRunner {
/** New test runner API, as explained in the extension test doc */
run(): Promise<void>;
}

export interface IHostUtils {
exit(code?: number): void;
exists(path: string): Promise<boolean>;
Expand Down Expand Up @@ -525,18 +531,18 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
const extensionTestsPath = originalFSPath(extensionTestsLocationURI);

// Require the test runner via node require from the provided path
let testRunner: ITestRunner | undefined;
let testRunner: ITestRunner | INewTestRunner | undefined;
let requireError: Error | undefined;
try {
testRunner = <any>require.__$__nodeRequire(extensionTestsPath);
} catch (error) {
requireError = error;
}

// Execute the runner if it follows our spec
// Execute the runner if it follows the old `run` spec
if (testRunner && typeof testRunner.run === 'function') {
return new Promise<void>((c, e) => {
testRunner!.run(extensionTestsPath, (error, failures) => {
const oldTestRunnerCallback = (error: Error, failures: number | undefined) => {
if (error) {
e(error.toString());
} else {
Expand All @@ -545,7 +551,22 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {

// after tests have run, we shutdown the host
this._gracefulExit(error || (typeof failures === 'number' && failures > 0) ? 1 /* ERROR */ : 0 /* OK */);
});
};

const runResult = testRunner!.run(extensionTestsPath, oldTestRunnerCallback);

// Using the new API `run(): Promise<void>`
if (runResult && runResult.then) {
runResult
.then(() => {
c();
this._gracefulExit(0);
})
.catch((err) => {
e(err);
this._gracefulExit(1);
});
}
});
}

Expand Down

0 comments on commit e80dd4f

Please sign in to comment.