Skip to content

Commit

Permalink
* Types were migrated to '@iobroker/types' from '@types/iobroker' (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox authored Sep 14, 2024
1 parent 2aaf00d commit 7da539a
Show file tree
Hide file tree
Showing 60 changed files with 1,443 additions and 3,277 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

59 changes: 0 additions & 59 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]
os: [ubuntu-latest]

steps:
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## Changelog

<!--
PLACEHOLDER for next version:
PLACEHOLDER for the next version:
## __WORK IN PROGRESS__
-->
## __WORK IN PROGRESS__
* Types were migrated to '@iobroker/types' from '@types/iobroker'

## 4.1.3 (2024-04-17)
* Allow (deprecated) HTML as admin UI in package tests, so old adapters using HTML UI can still utilize the rest of the package tests

Expand All @@ -17,7 +20,7 @@
* Honor `onlyWWW` flag in `io-package.json`

## 4.1.0 (2022-08-30)
* Support specifying the JS-Controller version in integration tests
* Support for specifying the JS-Controller version in integration tests

## 4.0.0 (2022-08-28)
* BREAKING: Dropped support for Node.js 12
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ This method creates a mock database and a mock adapter. See below for a more det
const asserts = utils.unit.createAsserts(database, adapter);
```

This methods takes a mock database and adapter and creates a set of asserts for your tests. All IDs may either be a string, which is taken literally, or an array of strings which are concatenated with `"."`. If an ID is not fully qualified, the adapter namespace is prepended automatically.
These methods take a mock database and adapter and create a set of asserts for your tests. All IDs may either be a string, which is taken literally, or an array of strings which are concatenated with `"."`. If an ID is not fully qualified, the adapter namespace is prepended automatically.

- `assertObjectExists(id: string | string[])` asserts that an object with the given ID exists in the database.
- `assertStateExists(id: string | string[])` asserts that a state with the given ID exists in the database.
Expand Down
1 change: 0 additions & 1 deletion build/lib/adapterTools.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="iobroker" />
/**
* Loads an adapter's package.json
* @param adapterDir The directory the adapter resides in
Expand Down
23 changes: 11 additions & 12 deletions build/lib/adapterTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAdapterDependencies = exports.getAdapterFullName = exports.getAdapterName = exports.getAppName = exports.loadInstanceObjects = exports.loadAdapterCommon = exports.loadAdapterConfig = exports.locateAdapterMainFile = exports.getAdapterExecutionMode = exports.loadIoPackage = exports.loadNpmPackage = void 0;
exports.loadNpmPackage = loadNpmPackage;
exports.loadIoPackage = loadIoPackage;
exports.getAdapterExecutionMode = getAdapterExecutionMode;
exports.locateAdapterMainFile = locateAdapterMainFile;
exports.loadAdapterConfig = loadAdapterConfig;
exports.loadAdapterCommon = loadAdapterCommon;
exports.loadInstanceObjects = loadInstanceObjects;
exports.getAppName = getAppName;
exports.getAdapterName = getAdapterName;
exports.getAdapterFullName = getAdapterFullName;
exports.getAdapterDependencies = getAdapterDependencies;
// Add debug logging for tests
const typeguards_1 = require("alcalzone-shared/typeguards");
const debug_1 = __importDefault(require("debug"));
Expand All @@ -40,20 +50,17 @@ const debug = (0, debug_1.default)("testing:unit:adapterTools");
function loadNpmPackage(adapterDir) {
return require(path.join(adapterDir, "package.json"));
}
exports.loadNpmPackage = loadNpmPackage;
/**
* Loads an adapter's io-package.json
* @param adapterDir The directory the adapter resides in
*/
function loadIoPackage(adapterDir) {
return require(path.join(adapterDir, "io-package.json"));
}
exports.loadIoPackage = loadIoPackage;
function getAdapterExecutionMode(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
return ioPackage.common.mode;
}
exports.getAdapterExecutionMode = getAdapterExecutionMode;
/**
* Locates an adapter's main file
* @param adapterDir The directory the adapter resides in
Expand Down Expand Up @@ -83,7 +90,6 @@ async function locateAdapterMainFile(adapterDir) {
}
throw new Error(`The adapter main file was not found in ${adapterDir}`);
}
exports.locateAdapterMainFile = locateAdapterMainFile;
/**
* Locates an adapter's config to populate the `adapter.config` object with
* @param adapterDir The directory the adapter resides in
Expand All @@ -92,7 +98,6 @@ function loadAdapterConfig(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
return ioPackage.native || {};
}
exports.loadAdapterConfig = loadAdapterConfig;
/**
* Loads the adapter's common configuration from `io-package.json`
* @param adapterDir The directory the adapter resides in
Expand All @@ -101,7 +106,6 @@ function loadAdapterCommon(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
return ioPackage.common || {};
}
exports.loadAdapterCommon = loadAdapterCommon;
/**
* Loads the instanceObjects for an adapter from its `io-package.json`
* @param adapterDir The directory the adapter resides in
Expand All @@ -110,25 +114,21 @@ function loadInstanceObjects(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
return ioPackage.instanceObjects || [];
}
exports.loadInstanceObjects = loadInstanceObjects;
/** Returns the branded name of "iobroker" */
function getAppName(adapterDir) {
const npmPackage = loadNpmPackage(adapterDir);
return npmPackage.name.split(".")[0] || "iobroker";
}
exports.getAppName = getAppName;
/** Returns the name of an adapter without the prefix */
function getAdapterName(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
return ioPackage.common.name;
}
exports.getAdapterName = getAdapterName;
/** Returns the full name of an adapter, including the prefix */
function getAdapterFullName(adapterDir) {
const npmPackage = loadNpmPackage(adapterDir);
return npmPackage.name;
}
exports.getAdapterFullName = getAdapterFullName;
/** Reads other ioBroker modules this adapter depends on from io-package.json */
function getAdapterDependencies(adapterDir) {
const ioPackage = loadIoPackage(adapterDir);
Expand All @@ -147,4 +147,3 @@ function getAdapterDependencies(adapterDir) {
}
return ret;
}
exports.getAdapterDependencies = getAdapterDependencies;
1 change: 0 additions & 1 deletion build/lib/executeCommand.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export interface ExecuteCommandOptions {
/** Whether the executed command should be logged to the stdout. Default: false */
logCommandExecution: boolean;
Expand Down
3 changes: 1 addition & 2 deletions build/lib/executeCommand.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeCommand = void 0;
exports.executeCommand = executeCommand;
const typeguards_1 = require("alcalzone-shared/typeguards");
const child_process_1 = require("child_process");
const isWindows = /^win/.test(process.platform);
Expand Down Expand Up @@ -80,4 +80,3 @@ function executeCommand(command, argsOrOptions, options) {
}
});
}
exports.executeCommand = executeCommand;
3 changes: 1 addition & 2 deletions build/lib/str2regex.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.str2regex = void 0;
exports.str2regex = str2regex;
function str2regex(pattern) {
return new RegExp(pattern
.replace(/\\/g, "\\\\") // Backslashes escapen
.replace(/\./g, "\\.") // Punkte als solche matchen
.replace(/\*/g, ".*") // Wildcard in Regex umsetzen
.replace(/!/g, "?!"));
}
exports.str2regex = str2regex;
1 change: 1 addition & 0 deletions build/lib/testAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/lib/testAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
// TODO: Do we need this file?
// import * as utils from "@iobroker/adapter-core";
Object.defineProperty(exports, "__esModule", { value: true });
// const adapter = utils.adapter({
// name: "foo",
// ready() {
Expand Down
1 change: 0 additions & 1 deletion build/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const createMocks_1 = require("./unit/harness/createMocks");
const mockDatabase_1 = require("./unit/mocks/mockDatabase");
var harness_1 = require("./integration/lib/harness");
Object.defineProperty(exports, "IntegrationTestHarness", { enumerable: true, get: function () { return harness_1.TestHarness; } });
var mockAdapter_1 = require("./unit/mocks/mockAdapter");
var mockDatabase_2 = require("./unit/mocks/mockDatabase");
Object.defineProperty(exports, "MockDatabase", { enumerable: true, get: function () { return mockDatabase_2.MockDatabase; } });
/** Predefined test sets */
Expand Down
2 changes: 0 additions & 2 deletions build/tests/integration/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="iobroker" />
/// <reference types="mocha" />
import { TestHarness } from "./lib/harness";
export interface TestAdapterOptions {
allowedExitCodes?: (number | string)[];
Expand Down
4 changes: 2 additions & 2 deletions build/tests/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.testAdapter = void 0;
exports.testAdapter = testAdapter;
const async_1 = require("alcalzone-shared/async");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
Expand Down Expand Up @@ -114,6 +114,7 @@ function testAdapter(adapterDir, options = {}) {
switch (harness.getAdapterExecutionMode()) {
case "schedule":
case "once":
// @ts-expect-error subscribe was deprecated
case "subscribe":
allowedExitCodes.add(0);
}
Expand Down Expand Up @@ -201,4 +202,3 @@ function testAdapter(adapterDir, options = {}) {
}
});
}
exports.testAdapter = testAdapter;
4 changes: 0 additions & 4 deletions build/tests/integration/lib/dbConnection.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/// <reference types="iobroker" />
/// <reference types="iobroker" />
/// <reference types="node" />
/// <reference types="node" />
import EventEmitter from "events";
export type ObjectsDB = Record<string, ioBroker.Object>;
export type StatesDB = Record<string, ioBroker.State>;
Expand Down
5 changes: 0 additions & 5 deletions build/tests/integration/lib/harness.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// <reference types="iobroker" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="iobroker" />
/// <reference types="node" />
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import type { DBConnection } from "./dbConnection";
Expand Down
2 changes: 2 additions & 0 deletions build/tests/integration/lib/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class TestHarness extends events_1.EventEmitter {
type: "instance",
common: {},
native: {},
instanceObjects: [],
objects: [],
});
this.dbConnection.subscribeMessage(fromAdapterID);
}
Expand Down
1 change: 0 additions & 1 deletion build/tests/integration/lib/logger.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/// <reference types="iobroker" />
export declare function createLogger(loglevel: ioBroker.LogLevel): ioBroker.Logger;
3 changes: 1 addition & 2 deletions build/tests/integration/lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLogger = void 0;
exports.createLogger = createLogger;
var LoglevelOrder;
(function (LoglevelOrder) {
LoglevelOrder[LoglevelOrder["error"] = 0] = "error";
Expand All @@ -22,4 +22,3 @@ function createLogger(loglevel) {
level: loglevel,
};
}
exports.createLogger = createLogger;
11 changes: 5 additions & 6 deletions build/tests/integration/lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTestAdapterDir = exports.getTestDBDir = exports.getTestLogDir = exports.getTestDataDir = exports.getTestControllerDir = void 0;
exports.getTestControllerDir = getTestControllerDir;
exports.getTestDataDir = getTestDataDir;
exports.getTestLogDir = getTestLogDir;
exports.getTestDBDir = getTestDBDir;
exports.getTestAdapterDir = getTestAdapterDir;
const path = __importStar(require("path"));
const adapterTools_1 = require("../../../lib/adapterTools");
/**
Expand All @@ -34,7 +38,6 @@ const adapterTools_1 = require("../../../lib/adapterTools");
function getTestControllerDir(appName, testDir) {
return path.resolve(testDir, "node_modules", `${appName}.js-controller`);
}
exports.getTestControllerDir = getTestControllerDir;
/**
* Locates the directory where JS-Controller stores its data for integration tests
* @param appName The branded name of "iobroker"
Expand All @@ -43,7 +46,6 @@ exports.getTestControllerDir = getTestControllerDir;
function getTestDataDir(appName, testDir) {
return path.resolve(testDir, `${appName}-data`);
}
exports.getTestDataDir = getTestDataDir;
/**
* Locates the directory where JS-Controller stores its logs for integration tests
* @param appName The branded name of "iobroker"
Expand All @@ -52,7 +54,6 @@ exports.getTestDataDir = getTestDataDir;
function getTestLogDir(appName, testDir) {
return path.resolve(testDir, "log");
}
exports.getTestLogDir = getTestLogDir;
/**
* Locates the directory where JS-Controller stores its sqlite db during integration tests
* @param appName The branded name of "iobroker"
Expand All @@ -61,7 +62,6 @@ exports.getTestLogDir = getTestLogDir;
function getTestDBDir(appName, testDir) {
return path.resolve(getTestDataDir(appName, testDir), "sqlite");
}
exports.getTestDBDir = getTestDBDir;
/**
* Locates the directory where the adapter will be be stored for integration tests
* @param adapterDir The root directory of the adapter
Expand All @@ -71,4 +71,3 @@ function getTestAdapterDir(adapterDir, testDir) {
const adapterName = (0, adapterTools_1.getAdapterFullName)(adapterDir);
return path.resolve(testDir, "node_modules", adapterName);
}
exports.getTestAdapterDir = getTestAdapterDir;
3 changes: 1 addition & 2 deletions build/tests/packageFiles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePackageFiles = void 0;
exports.validatePackageFiles = validatePackageFiles;
/* eslint-disable @typescript-eslint/no-var-requires */
const typeguards_1 = require("alcalzone-shared/typeguards");
const chai_1 = require("chai");
Expand Down Expand Up @@ -255,4 +255,3 @@ function validatePackageFiles(adapterDir) {
// });
// });
}
exports.validatePackageFiles = validatePackageFiles;
1 change: 0 additions & 1 deletion build/tests/unit/harness/createMocks.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="iobroker" />
import { MockDatabase } from "../mocks/mockDatabase";
/**
* Creates a new set of mocks, including a mock database and a mock adapter.
Expand Down
Loading

0 comments on commit 7da539a

Please sign in to comment.