Skip to content

Commit

Permalink
[plug-in] enable running of VS Code extension tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Feb 1, 2019
1 parent f54fc5c commit 62c51ff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { argv } from 'yargs';
import * as path from 'path';
import * as cp from 'child_process';
import { injectable, inject } from 'inversify';
Expand Down Expand Up @@ -117,6 +118,9 @@ export class HostedPluginProcess implements ServerPluginRunner {
env.PATH = process.env.PATH;
// add HOME to env since some plug-ins need to read files from user's home dir
env.HOME = process.env.HOME;
if (argv.extensionTestsPath) {
env.extensionTestsPath = argv.extensionTestsPath;
}

const forkOptions: cp.ForkOptions = {
silent: true,
Expand Down
31 changes: 30 additions & 1 deletion packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class PluginHostRPC {

// tslint:disable-next-line:no-any
createPluginManager(envExt: EnvExtImpl, preferencesManager: PreferenceRegistryExtImpl, rpc: any): PluginManagerExtImpl {
const { extensionTestsPath } = process.env;
const pluginManager = new PluginManagerExtImpl({
loadPlugin(plugin: Plugin): void {
console.log('PLUGIN_HOST(' + process.pid + '): PluginManagerExtImpl/loadPlugin(' + plugin.pluginPath + ')');
Expand Down Expand Up @@ -132,7 +133,35 @@ export class PluginHostRPC {
}
}
}
}
},
loadTests: extensionTestsPath ? async () => {
// tslint:disable:no-any
// Require the test runner via node require from the provided path
let testRunner: any;
let requireError: Error | undefined;
try {
testRunner = require(extensionTestsPath);
} catch (error) {
requireError = error;
}

// Execute the runner if it follows our spec
if (testRunner && typeof testRunner.run === 'function') {
return new Promise<void>((c, e) => {
testRunner.run(extensionTestsPath, (error: any, failures: any) => {
if (error) {
e(error.toString());
} else {
c(undefined);
}
});
});
}
throw new Error(requireError ?
requireError.toString() :
`Path ${extensionTestsPath} does not point to a valid extension test runner.`
);
} : undefined
}, envExt, preferencesManager, rpc);
return pluginManager;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface PluginHost {
init(data: PluginMetadata[]): [Plugin[], Plugin[]];

initExtApi(extApi: ExtPluginApi[]): void;

loadTests?(): Promise<void>;
}

interface StopFn {
Expand Down Expand Up @@ -120,10 +122,13 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
if (pluginMain !== undefined) {
this.startPlugin(plugin, configStorage, pluginMain);
} else {
return Promise.reject(new Error('Unable to load the given plugin'));
console.error(`Unable to load a plugin from "${plugin.pluginPath}"`);
}
}

if (this.host.loadTests) {
return this.host.loadTests();
}
return Promise.resolve();
}

Expand Down

0 comments on commit 62c51ff

Please sign in to comment.