Skip to main content

plugins

Overview

With the plugins section, you can connect external plugins to Testplane, which will expand the available functionality.

For example, plugins like html-reporter or @testplane/safari-commands.

A plugin is a module that exports a single function, which takes the following arguments:

  • Testplane instance
  • Plugin options from the Testplane config

All plugins will be loaded before Testplane starts running tests.

tip

When choosing a name for a plugin, add the prefix testplane- to it. This will make it easier to find such a plugin.

If the plugin name starts with the prefix testplane-, this prefix can be omitted when adding the plugin to the plugins section. If there are modules with both names on the file system: testplane-some-module and some-module, preference will be given to the module with the testplane- prefix.

Schematic Example

testplane.config.ts
import type { ConfigInput } from "testplane";

export default {
// ...
plugins: {
"my-cool-plugin": {
param: "some-value",
},
},
} satisfies ConfigInput;
testplane-my-cool-plugin/index.ts
exports = function (testplane, opts) {
testplane.on(testplane.events.RUNNER_START, function (runner) {
console.info(opts.param); // some-value

return setUp(testplane.config, opts.param);
});

testplane.on(testplane.events.RUNNER_END, function () {
return tearDown();
});
};

Testplane Instance Properties

configThe config used in the test runner. Can be modified.
eventsList of events that can be subscribed to.

You can learn more about events on the corresponding page.

Parallel Execution of Plugins

The runner has a registerWorkers method, which can be used to register custom methods for running in Testplane workers.

The registerWorkers method takes 2 arguments:

  • workerFilepath — path to the file with functions, a string with an absolute path.
  • exportedMethods — names of exported methods, an array of strings.

The method returns an object with the methods listed in exportedMethods, which return promises with results.

Note that the file in workerFilepath must export an object with the corresponding methods.

Example:

my-plugin.ts
let workers;

exports = testplane => {
testplane.on(testplane.events.RUNNER_START, async runner => {
const workerFilepath = require.resolve("./worker");
const exportedMethods = ["foo"];
workers = runner.registerWorkers(workerFilepath, exportedMethods);

// outputs `FOO_RUNNER_START`
console.log(await workers.foo("RUNNER_START"));
});

testplane.on(testplane.events.RUNNER_END, async () => {
// outputs `FOO_RUNNER_END`
console.log(await workers.foo("RUNNER_END"));
});
};
worker.ts
exports = {
foo: async function (event) {
return "FOO_" + event;
},
};

Useful Plugins

The Testplane ecosystem includes dozens of plugins. Here are some of them: