Skip to content

Commit

Permalink
feat: support specifying the controller version (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Aug 30, 2022
1 parent 21df86d commit 2a7f522
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ module.exports = {
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-non-null-assertion": "off", // This is necessary for Map.has()/get()!
"@typescript-eslint/no-inferrable-types": [
"error",
{
ignoreParameters: true,
ignoreProperties: true,
},
],
},
overrides: [
{
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ tests.integration(path.join(__dirname, ".."), {
// By default, termination during startup is not allowed.
allowedExitCodes: [11],

// To test against a different version of JS-Controller, you can change the version or dist-tag here.
// Make sure to remove this setting when you're done testing.
controllerVersion: "latest", // or a specific version like "4.0.1"

// Define your own tests inside defineAdditionalTests
defineAdditionalTests({ suite }) {
// All tests (it, describe) must be grouped in one or more suites. Each suite sets up a fresh environment for the adapter tests.
Expand Down
5 changes: 5 additions & 0 deletions build/tests/integration/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export interface TestAdapterOptions {
loglevel?: ioBroker.LogLevel;
/** How long to wait before the adapter startup is considered successful */
waitBeforeStartupSuccess?: number;
/**
* Which JS-Controller version or dist-tag should be used for the tests. Default: dev
* This should only be changed during active development.
*/
controllerVersion?: string;
/** Allows you to define additional tests */
defineAdditionalTests?: (args: TestContext) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion build/tests/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function testAdapter(adapterDir, options = {}) {
// Installation happens in two steps:
// First we need to set up JS Controller, so the databases etc. can be created
// First we need to copy all files and execute an npm install
await controllerSetup.prepareTestDir();
await controllerSetup.prepareTestDir(options.controllerVersion);
// Only then we can install the adapter, because some (including VIS) try to access
// the databases if JS Controller is installed
await adapterSetup.installAdapterInTestDir();
Expand Down
2 changes: 1 addition & 1 deletion build/tests/integration/lib/controllerSetup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export declare class ControllerSetup {
private testAdapterDir;
private testControllerDir;
private testDataDir;
prepareTestDir(): Promise<void>;
prepareTestDir(controllerVersion?: string): Promise<void>;
/**
* Tests if JS-Controller is already installed
* @param appName The branded name of "iobroker"
Expand Down
6 changes: 3 additions & 3 deletions build/tests/integration/lib/controllerSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ControllerSetup {
debug(` appName: ${this.appName}`);
debug(` adapterName: ${this.adapterName}`);
}
async prepareTestDir() {
debug("Preparing the test directory...");
async prepareTestDir(controllerVersion = "dev") {
debug(`Preparing the test directory. JS-Controller version: "${controllerVersion}"...`);
// Make sure the test dir exists
await (0, fs_extra_1.ensureDir)(this.testDir);
// Write the package.json
Expand All @@ -69,7 +69,7 @@ class ControllerSetup {
author: "",
license: "ISC",
dependencies: {
[`${this.appName}.js-controller`]: "dev",
[`${this.appName}.js-controller`]: controllerVersion,
},
description: "",
};
Expand Down
7 changes: 6 additions & 1 deletion src/tests/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface TestAdapterOptions {
loglevel?: ioBroker.LogLevel;
/** How long to wait before the adapter startup is considered successful */
waitBeforeStartupSuccess?: number;
/**
* Which JS-Controller version or dist-tag should be used for the tests. Default: dev
* This should only be changed during active development.
*/
controllerVersion?: string;
/** Allows you to define additional tests */
defineAdditionalTests?: (args: TestContext) => void;
}
Expand Down Expand Up @@ -81,7 +86,7 @@ export function testAdapter(
// First we need to set up JS Controller, so the databases etc. can be created

// First we need to copy all files and execute an npm install
await controllerSetup.prepareTestDir();
await controllerSetup.prepareTestDir(options.controllerVersion);
// Only then we can install the adapter, because some (including VIS) try to access
// the databases if JS Controller is installed
await adapterSetup.installAdapterInTestDir();
Expand Down
10 changes: 7 additions & 3 deletions src/tests/integration/lib/controllerSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ export class ControllerSetup {
private testControllerDir: string;
private testDataDir: string;

public async prepareTestDir(): Promise<void> {
debug("Preparing the test directory...");
public async prepareTestDir(
controllerVersion: string = "dev",
): Promise<void> {
debug(
`Preparing the test directory. JS-Controller version: "${controllerVersion}"...`,
);
// Make sure the test dir exists
await ensureDir(this.testDir);

Expand All @@ -67,7 +71,7 @@ export class ControllerSetup {
author: "",
license: "ISC",
dependencies: {
[`${this.appName}.js-controller`]: "dev",
[`${this.appName}.js-controller`]: controllerVersion,
},
description: "",
};
Expand Down

0 comments on commit 2a7f522

Please sign in to comment.