未验证 提交 e80dd4f2 编写于 作者: P Pine 提交者: GitHub

Merge pull request #76061 from microsoft/octref/new-test-runner-api

New test runner api
......@@ -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>;
......@@ -525,7 +531,7 @@ 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);
......@@ -533,10 +539,10 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
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 {
......@@ -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);
});
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册