@iobroker/testing 5.0.0 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/build/index.d.ts +1 -1
- package/build/lib/adapterTools.d.ts +7 -1
- package/build/lib/adapterTools.js +36 -21
- package/build/lib/executeCommand.d.ts +3 -2
- package/build/lib/executeCommand.js +30 -29
- package/build/lib/str2regex.js +4 -4
- package/build/tests/index.d.ts +9 -9
- package/build/tests/integration/index.d.ts +1 -1
- package/build/tests/integration/index.js +44 -39
- package/build/tests/integration/lib/adapterSetup.d.ts +1 -1
- package/build/tests/integration/lib/adapterSetup.js +50 -52
- package/build/tests/integration/lib/controllerSetup.d.ts +1 -10
- package/build/tests/integration/lib/controllerSetup.js +59 -56
- package/build/tests/integration/lib/dbConnection.d.ts +12 -12
- package/build/tests/integration/lib/dbConnection.js +71 -69
- package/build/tests/integration/lib/harness.d.ts +9 -7
- package/build/tests/integration/lib/harness.js +68 -49
- package/build/tests/integration/lib/logger.js +1 -1
- package/build/tests/integration/lib/tools.d.ts +6 -1
- package/build/tests/integration/lib/tools.js +27 -12
- package/build/tests/packageFiles/index.js +92 -90
- package/build/tests/unit/harness/createMocks.d.ts +3 -2
- package/build/tests/unit/harness/createMocks.js +0 -1
- package/build/tests/unit/index.js +5 -4
- package/build/tests/unit/mocks/mockAdapter.d.ts +3 -3
- package/build/tests/unit/mocks/mockAdapter.js +195 -162
- package/build/tests/unit/mocks/mockAdapterCore.d.ts +4 -9
- package/build/tests/unit/mocks/mockAdapterCore.js +23 -14
- package/build/tests/unit/mocks/mockDatabase.d.ts +13 -12
- package/build/tests/unit/mocks/mockDatabase.js +40 -45
- package/build/tests/unit/mocks/mockLogger.d.ts +1 -1
- package/build/tests/unit/mocks/mockLogger.js +1 -1
- package/build/tests/unit/mocks/tools.d.ts +2 -2
- package/build/tests/unit/mocks/tools.js +14 -11
- package/package.json +15 -22
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Locates the directory where JS-Controller is installed for integration tests
|
|
3
|
+
*
|
|
3
4
|
* @param appName The branded name of "iobroker"
|
|
4
5
|
* @param testDir The directory the integration tests are executed in
|
|
5
6
|
*/
|
|
6
7
|
export declare function getTestControllerDir(appName: string, testDir: string): string;
|
|
7
8
|
/**
|
|
8
9
|
* Locates the directory where JS-Controller stores its data for integration tests
|
|
10
|
+
*
|
|
9
11
|
* @param appName The branded name of "iobroker"
|
|
10
12
|
* @param testDir The directory the integration tests are executed in
|
|
11
13
|
*/
|
|
12
14
|
export declare function getTestDataDir(appName: string, testDir: string): string;
|
|
13
15
|
/**
|
|
14
16
|
* Locates the directory where JS-Controller stores its logs for integration tests
|
|
17
|
+
*
|
|
15
18
|
* @param appName The branded name of "iobroker"
|
|
16
19
|
* @param testDir The directory the integration tests are executed in
|
|
17
20
|
*/
|
|
18
21
|
export declare function getTestLogDir(appName: string, testDir: string): string;
|
|
19
22
|
/**
|
|
20
23
|
* Locates the directory where JS-Controller stores its sqlite db during integration tests
|
|
24
|
+
*
|
|
21
25
|
* @param appName The branded name of "iobroker"
|
|
22
26
|
* @param testDir The directory the integration tests are executed in
|
|
23
27
|
*/
|
|
24
28
|
export declare function getTestDBDir(appName: string, testDir: string): string;
|
|
25
29
|
/**
|
|
26
|
-
* Locates the directory where the adapter will be
|
|
30
|
+
* Locates the directory where the adapter will be stored for integration tests
|
|
31
|
+
*
|
|
27
32
|
* @param adapterDir The root directory of the adapter
|
|
28
33
|
* @param testDir The directory the integration tests are executed in
|
|
29
34
|
*/
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.getTestControllerDir = getTestControllerDir;
|
|
27
37
|
exports.getTestDataDir = getTestDataDir;
|
|
@@ -32,14 +42,16 @@ const path = __importStar(require("path"));
|
|
|
32
42
|
const adapterTools_1 = require("../../../lib/adapterTools");
|
|
33
43
|
/**
|
|
34
44
|
* Locates the directory where JS-Controller is installed for integration tests
|
|
45
|
+
*
|
|
35
46
|
* @param appName The branded name of "iobroker"
|
|
36
47
|
* @param testDir The directory the integration tests are executed in
|
|
37
48
|
*/
|
|
38
49
|
function getTestControllerDir(appName, testDir) {
|
|
39
|
-
return path.resolve(testDir,
|
|
50
|
+
return path.resolve(testDir, 'node_modules', `${appName}.js-controller`);
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
* Locates the directory where JS-Controller stores its data for integration tests
|
|
54
|
+
*
|
|
43
55
|
* @param appName The branded name of "iobroker"
|
|
44
56
|
* @param testDir The directory the integration tests are executed in
|
|
45
57
|
*/
|
|
@@ -48,26 +60,29 @@ function getTestDataDir(appName, testDir) {
|
|
|
48
60
|
}
|
|
49
61
|
/**
|
|
50
62
|
* Locates the directory where JS-Controller stores its logs for integration tests
|
|
63
|
+
*
|
|
51
64
|
* @param appName The branded name of "iobroker"
|
|
52
65
|
* @param testDir The directory the integration tests are executed in
|
|
53
66
|
*/
|
|
54
67
|
function getTestLogDir(appName, testDir) {
|
|
55
|
-
return path.resolve(testDir,
|
|
68
|
+
return path.resolve(testDir, 'log');
|
|
56
69
|
}
|
|
57
70
|
/**
|
|
58
71
|
* Locates the directory where JS-Controller stores its sqlite db during integration tests
|
|
72
|
+
*
|
|
59
73
|
* @param appName The branded name of "iobroker"
|
|
60
74
|
* @param testDir The directory the integration tests are executed in
|
|
61
75
|
*/
|
|
62
76
|
function getTestDBDir(appName, testDir) {
|
|
63
|
-
return path.resolve(getTestDataDir(appName, testDir),
|
|
77
|
+
return path.resolve(getTestDataDir(appName, testDir), 'sqlite');
|
|
64
78
|
}
|
|
65
79
|
/**
|
|
66
|
-
* Locates the directory where the adapter will be
|
|
80
|
+
* Locates the directory where the adapter will be stored for integration tests
|
|
81
|
+
*
|
|
67
82
|
* @param adapterDir The root directory of the adapter
|
|
68
83
|
* @param testDir The directory the integration tests are executed in
|
|
69
84
|
*/
|
|
70
85
|
function getTestAdapterDir(adapterDir, testDir) {
|
|
71
86
|
const adapterName = (0, adapterTools_1.getAdapterFullName)(adapterDir);
|
|
72
|
-
return path.resolve(testDir,
|
|
87
|
+
return path.resolve(testDir, 'node_modules', adapterName);
|
|
73
88
|
}
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.validatePackageFiles = validatePackageFiles;
|
|
27
37
|
const typeguards_1 = require("alcalzone-shared/typeguards");
|
|
@@ -33,31 +43,30 @@ const path = __importStar(require("path"));
|
|
|
33
43
|
* This is meant to be executed in a mocha context.
|
|
34
44
|
*/
|
|
35
45
|
function validatePackageFiles(adapterDir) {
|
|
36
|
-
const packageJsonPath = path.join(adapterDir,
|
|
37
|
-
const ioPackageJsonPath = path.join(adapterDir,
|
|
46
|
+
const packageJsonPath = path.join(adapterDir, 'package.json');
|
|
47
|
+
const ioPackageJsonPath = path.join(adapterDir, 'io-package.json');
|
|
38
48
|
// This allows us to skip tests that require valid JSON files
|
|
39
49
|
const invalidFiles = {
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
'package.json': false,
|
|
51
|
+
'io-package.json': false,
|
|
42
52
|
};
|
|
43
53
|
function skipIfInvalid(...filenames) {
|
|
44
|
-
if (filenames.some(
|
|
54
|
+
if (filenames.some(f => invalidFiles[f])) {
|
|
45
55
|
return this.skip();
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
function markAsInvalid(filename) {
|
|
48
|
-
if (this.currentTest.state ===
|
|
49
|
-
invalidFiles[filename] === false) {
|
|
59
|
+
if (this.currentTest.state === 'failed' && invalidFiles[filename] === false) {
|
|
50
60
|
invalidFiles[filename] = true;
|
|
51
61
|
console.error(`Skipping subsequent tests including "${filename}" because they require valid JSON files!`);
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
64
|
/** Ensures that a given property exists on the target object */
|
|
55
65
|
function ensurePropertyExists(propertyPath, targetObj) {
|
|
56
|
-
const propertyParts = propertyPath.split(
|
|
66
|
+
const propertyParts = propertyPath.split('.');
|
|
57
67
|
it(`The property "${propertyPath}" exists`, () => {
|
|
58
68
|
let prev = targetObj;
|
|
59
69
|
for (const part of propertyParts) {
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
61
70
|
(0, chai_1.expect)(prev[part]).to.not.be.undefined;
|
|
62
71
|
prev = prev[part];
|
|
63
72
|
}
|
|
@@ -65,7 +74,7 @@ function validatePackageFiles(adapterDir) {
|
|
|
65
74
|
}
|
|
66
75
|
describe(`Validate the package files`, () => {
|
|
67
76
|
describe(`Ensure they are readable`, () => {
|
|
68
|
-
for (const filename of [
|
|
77
|
+
for (const filename of ['package.json', 'io-package.json']) {
|
|
69
78
|
const packagePath = path.join(adapterDir, filename);
|
|
70
79
|
describe(`${filename}`, () => {
|
|
71
80
|
afterEach(function () {
|
|
@@ -74,67 +83,61 @@ function validatePackageFiles(adapterDir) {
|
|
|
74
83
|
beforeEach(function () {
|
|
75
84
|
skipIfInvalid.call(this, filename);
|
|
76
85
|
});
|
|
77
|
-
it(
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
86
|
+
it('exists', () => {
|
|
79
87
|
(0, chai_1.expect)(fs.existsSync(packagePath), `${filename} is missing in the adapter dir. Please create it!`).to.be.true;
|
|
80
88
|
});
|
|
81
|
-
it(
|
|
89
|
+
it('contains valid JSON', () => {
|
|
82
90
|
(0, chai_1.expect)(() => {
|
|
83
|
-
JSON.parse(fs.readFileSync(packagePath,
|
|
91
|
+
JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
84
92
|
}, `${filename} contains invalid JSON!`).not.to.throw();
|
|
85
93
|
});
|
|
86
|
-
it(
|
|
87
|
-
(0, chai_1.expect)(
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
89
|
-
require(packagePath), `${filename} must contain an object!`).to.be.an("object");
|
|
94
|
+
it('is an object', () => {
|
|
95
|
+
(0, chai_1.expect)(require(packagePath), `${filename} must contain an object!`).to.be.an('object');
|
|
90
96
|
});
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
99
|
});
|
|
94
100
|
describe(`Check contents of package.json`, () => {
|
|
95
101
|
beforeEach(function () {
|
|
96
|
-
skipIfInvalid.call(this,
|
|
102
|
+
skipIfInvalid.call(this, 'package.json');
|
|
97
103
|
});
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
99
104
|
const packageContent = require(packageJsonPath);
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
101
105
|
const iopackContent = require(ioPackageJsonPath);
|
|
102
106
|
const requiredProperties = [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
'name',
|
|
108
|
+
'version',
|
|
109
|
+
'description',
|
|
110
|
+
'author',
|
|
111
|
+
'license',
|
|
112
|
+
'repository',
|
|
113
|
+
'repository.type',
|
|
110
114
|
];
|
|
111
|
-
requiredProperties.forEach(
|
|
112
|
-
it(
|
|
115
|
+
requiredProperties.forEach(prop => ensurePropertyExists(prop, packageContent));
|
|
116
|
+
it('The package name is correct', () => {
|
|
113
117
|
let name = packageContent.name;
|
|
114
118
|
(0, chai_1.expect)(name).to.match(/^iobroker\./, `The npm package name must start with lowercase "iobroker."!`);
|
|
115
|
-
name = name.replace(/^iobroker\./,
|
|
116
|
-
(0, chai_1.expect)(name).to.match(/[a-z0-9_
|
|
119
|
+
name = name.replace(/^iobroker\./, '');
|
|
120
|
+
(0, chai_1.expect)(name).to.match(/[-a-z0-9_]+/, `The adapter name must only contain lowercase letters, numbers, "-" and "_"!`);
|
|
117
121
|
(0, chai_1.expect)(name).to.match(/^[a-z]/, `The adapter name must start with a letter!`);
|
|
118
122
|
(0, chai_1.expect)(name).to.match(/[a-z0-9]$/, `The adapter name must end with a letter or number!`);
|
|
119
123
|
});
|
|
120
124
|
if (!iopackContent.common.onlyWWW) {
|
|
121
125
|
it(`property main is defined for non onlyWWW adapters`, () => {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
123
126
|
(0, chai_1.expect)(packageContent.main).to.not.be.undefined;
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
129
|
it(`The repository type is "git"`, () => {
|
|
127
|
-
(0, chai_1.expect)(packageContent.repository.type).to.equal(
|
|
130
|
+
(0, chai_1.expect)(packageContent.repository.type).to.equal('git');
|
|
128
131
|
});
|
|
129
|
-
it(
|
|
132
|
+
it('npm is not listed as a dependency', () => {
|
|
130
133
|
for (const depType of [
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
'dependencies',
|
|
135
|
+
'devDependencies',
|
|
136
|
+
'optionalDependencies',
|
|
137
|
+
'peerDependencies',
|
|
135
138
|
]) {
|
|
136
|
-
if ((0, typeguards_1.isObject)(packageContent[depType]) &&
|
|
137
|
-
|
|
139
|
+
if ((0, typeguards_1.isObject)(packageContent[depType]) && 'npm' in packageContent[depType]) {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
138
141
|
throw new chai_1.AssertionError(`npm must not be listed in ${depType}, found "${packageContent[depType].npm}"!`);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
@@ -142,30 +145,30 @@ function validatePackageFiles(adapterDir) {
|
|
|
142
145
|
});
|
|
143
146
|
describe(`Check contents of io-package.json`, () => {
|
|
144
147
|
beforeEach(function () {
|
|
145
|
-
skipIfInvalid.call(this,
|
|
148
|
+
skipIfInvalid.call(this, 'io-package.json');
|
|
146
149
|
});
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
148
150
|
const iopackContent = require(ioPackageJsonPath);
|
|
149
151
|
const requiredProperties = [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
152
|
+
'common.name',
|
|
153
|
+
'common.titleLang',
|
|
154
|
+
'common.version',
|
|
155
|
+
'common.news',
|
|
156
|
+
'common.desc',
|
|
157
|
+
'common.icon',
|
|
158
|
+
'common.extIcon',
|
|
159
|
+
'common.type',
|
|
160
|
+
'common.authors',
|
|
161
|
+
'native',
|
|
160
162
|
];
|
|
161
|
-
requiredProperties.forEach(
|
|
163
|
+
requiredProperties.forEach(prop => ensurePropertyExists(prop, iopackContent));
|
|
162
164
|
it(`The title does not contain "adapter" or "iobroker"`, () => {
|
|
163
|
-
if (!iopackContent.title)
|
|
165
|
+
if (!iopackContent.title) {
|
|
164
166
|
return;
|
|
167
|
+
}
|
|
165
168
|
(0, chai_1.expect)(iopackContent.common.title).not.to.match(/iobroker|adapter/i);
|
|
166
169
|
});
|
|
167
170
|
it(`titleLang is an object to support multiple languages`, () => {
|
|
168
|
-
(0, chai_1.expect)(iopackContent.common.titleLang).to.be.an(
|
|
171
|
+
(0, chai_1.expect)(iopackContent.common.titleLang).to.be.an('object');
|
|
169
172
|
});
|
|
170
173
|
it(`titleLang does not contain "adapter" or "iobroker"`, () => {
|
|
171
174
|
for (const title of Object.values(iopackContent.common.titleLang)) {
|
|
@@ -173,38 +176,39 @@ function validatePackageFiles(adapterDir) {
|
|
|
173
176
|
}
|
|
174
177
|
});
|
|
175
178
|
it(`The description is an object to support multiple languages`, () => {
|
|
176
|
-
(0, chai_1.expect)(iopackContent.common.desc).to.be.an(
|
|
179
|
+
(0, chai_1.expect)(iopackContent.common.desc).to.be.an('object');
|
|
177
180
|
});
|
|
178
181
|
it(`common.authors is an array that is not empty`, () => {
|
|
179
182
|
const authors = iopackContent.common.authors;
|
|
180
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
181
183
|
(0, chai_1.expect)((0, typeguards_1.isArray)(authors)).to.be.true;
|
|
182
184
|
(0, chai_1.expect)(authors.length).to.be.at.least(1);
|
|
183
185
|
});
|
|
184
186
|
it(`common.news is an object that contains maximum 20 entries`, () => {
|
|
185
187
|
const news = iopackContent.common.news;
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
187
188
|
(0, chai_1.expect)((0, typeguards_1.isObject)(news)).to.be.true;
|
|
188
189
|
(0, chai_1.expect)(Object.keys(news).length).to.be.at.most(20);
|
|
189
190
|
});
|
|
190
191
|
if (iopackContent.common.licenseInformation) {
|
|
191
192
|
it(`if common.licenseInformation exists, it is an object with required properties`, () => {
|
|
192
|
-
(0, chai_1.expect)(iopackContent.common.licenseInformation).to.be.an(
|
|
193
|
-
(0, chai_1.expect)(iopackContent.common.licenseInformation.type).to.be.oneOf([
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
193
|
+
(0, chai_1.expect)(iopackContent.common.licenseInformation).to.be.an('object');
|
|
194
|
+
(0, chai_1.expect)(iopackContent.common.licenseInformation.type).to.be.oneOf([
|
|
195
|
+
'free',
|
|
196
|
+
'commercial',
|
|
197
|
+
'paid',
|
|
198
|
+
'limited',
|
|
199
|
+
]);
|
|
200
|
+
if (iopackContent.common.licenseInformation.type !== 'free') {
|
|
201
|
+
(0, chai_1.expect)(iopackContent.common.licenseInformation.link, 'License link is missing').to.not.be
|
|
202
|
+
.undefined;
|
|
197
203
|
}
|
|
198
204
|
});
|
|
199
205
|
it(`common.license should not exist together with common.licenseInformation`, () => {
|
|
200
|
-
|
|
201
|
-
(0, chai_1.expect)(iopackContent.common.license, "common.license must be removed").to.be.undefined;
|
|
206
|
+
(0, chai_1.expect)(iopackContent.common.license, 'common.license must be removed').to.be.undefined;
|
|
202
207
|
});
|
|
203
208
|
}
|
|
204
209
|
else {
|
|
205
210
|
it(`common.license must exist without common.licenseInformation`, () => {
|
|
206
|
-
|
|
207
|
-
(0, chai_1.expect)(iopackContent.common.license, "common.licenseInformation (preferred) or common.license (deprecated) must exist").to.not.be.undefined;
|
|
211
|
+
(0, chai_1.expect)(iopackContent.common.license, 'common.licenseInformation (preferred) or common.license (deprecated) must exist').to.not.be.undefined;
|
|
208
212
|
});
|
|
209
213
|
}
|
|
210
214
|
if (iopackContent.common.tier != undefined) {
|
|
@@ -215,34 +219,32 @@ function validatePackageFiles(adapterDir) {
|
|
|
215
219
|
}
|
|
216
220
|
// If the adapter has a configuration page, check that a supported admin UI is used
|
|
217
221
|
const hasNoConfigPage = iopackContent.common.noConfig === true ||
|
|
218
|
-
iopackContent.common.noConfig ===
|
|
219
|
-
iopackContent.common.adminUI?.config ===
|
|
222
|
+
iopackContent.common.noConfig === 'true' ||
|
|
223
|
+
iopackContent.common.adminUI?.config === 'none';
|
|
220
224
|
if (!hasNoConfigPage) {
|
|
221
|
-
it(
|
|
225
|
+
it('The adapter uses a supported admin UI', () => {
|
|
222
226
|
const hasSupportedUI = !!iopackContent.common.materialize ||
|
|
223
|
-
iopackContent.common.adminUI?.config ===
|
|
224
|
-
iopackContent.common.adminUI?.config ===
|
|
225
|
-
iopackContent.common.adminUI?.config ===
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
iopackContent.common.adminUI?.config === 'html' ||
|
|
228
|
+
iopackContent.common.adminUI?.config === 'json' ||
|
|
229
|
+
iopackContent.common.adminUI?.config === 'materialize';
|
|
230
|
+
(0, chai_1.expect)(hasSupportedUI, 'Unsupported Admin UI, must be html, materialize or JSON config!').to.be
|
|
231
|
+
.true;
|
|
228
232
|
});
|
|
229
233
|
}
|
|
230
234
|
});
|
|
231
235
|
describe(`Compare contents of package.json and io-package.json`, () => {
|
|
232
236
|
beforeEach(function () {
|
|
233
|
-
skipIfInvalid.call(this,
|
|
237
|
+
skipIfInvalid.call(this, 'package.json', 'io-package.json');
|
|
234
238
|
});
|
|
235
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
236
239
|
const packageContent = require(packageJsonPath);
|
|
237
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
238
240
|
const iopackContent = require(ioPackageJsonPath);
|
|
239
|
-
it(
|
|
240
|
-
(0, chai_1.expect)(
|
|
241
|
+
it('The name matches', () => {
|
|
242
|
+
(0, chai_1.expect)(`iobroker.${iopackContent.common.name}`).to.equal(packageContent.name);
|
|
241
243
|
});
|
|
242
|
-
it(
|
|
244
|
+
it('The version matches', () => {
|
|
243
245
|
(0, chai_1.expect)(iopackContent.common.version).to.equal(packageContent.version);
|
|
244
246
|
});
|
|
245
|
-
it(
|
|
247
|
+
it('The license matches', () => {
|
|
246
248
|
if (iopackContent.common.licenseInformation) {
|
|
247
249
|
(0, chai_1.expect)(iopackContent.common.licenseInformation.license).to.equal(packageContent.license);
|
|
248
250
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type MockAdapter } from '../mocks/mockAdapter';
|
|
2
|
+
import { MockDatabase } from '../mocks/mockDatabase';
|
|
2
3
|
/**
|
|
3
4
|
* Creates a new set of mocks, including a mock database and a mock adapter.
|
|
4
5
|
* To test the startup of an adapter, use `startMockAdapter` instead.
|
|
5
6
|
*/
|
|
6
7
|
export declare function createMocks(adapterOptions: Partial<ioBroker.AdapterOptions>): {
|
|
7
8
|
database: MockDatabase;
|
|
8
|
-
adapter:
|
|
9
|
+
adapter: MockAdapter;
|
|
9
10
|
};
|
|
@@ -7,7 +7,6 @@ const mockDatabase_1 = require("../mocks/mockDatabase");
|
|
|
7
7
|
* Creates a new set of mocks, including a mock database and a mock adapter.
|
|
8
8
|
* To test the startup of an adapter, use `startMockAdapter` instead.
|
|
9
9
|
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
11
10
|
function createMocks(adapterOptions) {
|
|
12
11
|
const databaseMock = new mockDatabase_1.MockDatabase();
|
|
13
12
|
const adapterMock = mockAdapter_1.createAdapterMock.bind(undefined)(databaseMock, adapterOptions);
|
|
@@ -7,17 +7,18 @@ exports.testAdapterWithMocks = testAdapterWithMocks;
|
|
|
7
7
|
* This is meant to be executed in a mocha context.
|
|
8
8
|
*/
|
|
9
9
|
function testAdapterWithMocks(_adapterDir, options = {}) {
|
|
10
|
-
describe(`Unit tests`,
|
|
10
|
+
describe(`Unit tests`, () => {
|
|
11
11
|
// Call the user's tests
|
|
12
|
-
if (typeof options.defineAdditionalTests ===
|
|
12
|
+
if (typeof options.defineAdditionalTests === 'function') {
|
|
13
13
|
options.defineAdditionalTests();
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
it(
|
|
17
|
-
console.warn(
|
|
16
|
+
it('DEPRECATED!', () => {
|
|
17
|
+
console.warn('\u001b[33mUnit tests for adapter startup are deprecated!');
|
|
18
18
|
console.warn(`If you do not define your own tests, you can remove the "test:unit" script`);
|
|
19
19
|
console.warn(`from package.json and from your Travis/Github Actions workflow.\u001b[0m`);
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
return Promise.resolve();
|
|
22
23
|
});
|
|
23
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MockDatabase } from
|
|
2
|
-
import { MockLogger } from
|
|
3
|
-
import { Mock } from
|
|
1
|
+
import type { MockDatabase } from './mockDatabase';
|
|
2
|
+
import { type MockLogger } from './mockLogger';
|
|
3
|
+
import { type Mock } from './tools';
|
|
4
4
|
export type MockAdapter = Mock<ioBroker.Adapter> & {
|
|
5
5
|
readyHandler: ioBroker.ReadyHandler | undefined;
|
|
6
6
|
objectChangeHandler: ioBroker.ObjectChangeHandler | undefined;
|