@iobroker/testing 3.0.1 → 3.0.2

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/CHANGELOG.md CHANGED
@@ -4,6 +4,9 @@
4
4
  PLACEHOLDER for next version:
5
5
  ## __WORK IN PROGRESS__
6
6
  -->
7
+ ## 3.0.2 (2022-05-15)
8
+ * Fix: Replace the `harness` argument to the `suite()` function with a `getHarness()` function to avoid accessing a stale harness.
9
+
7
10
  ## 3.0.1 (2022-05-09)
8
11
  * BREAKING: The function signature of `defineAdditionalTests` in integration tests has changed. All user-defined integration tests must now be grouped in one or more `suite` blocks. The adapter will now only be started at the beginning of each suite. See the documentation for details.
9
12
  * BREAKING: The function signature of `harness.startAdapterAndWait` has changed. It now accepts a boolean as the first parameter which controls whether to wait for the `alive` state (`false`) or the `info.connection` state (`true`).
package/README.md CHANGED
@@ -50,7 +50,13 @@ tests.integration(path.join(__dirname, ".."), {
50
50
  // The adapter will run until the end of each suite.
51
51
 
52
52
  // Since the tests are heavily instrumented, each suite gives access to a so called "harness" to control the tests.
53
- suite("Test sendTo()", (harness) => {
53
+ suite("Test sendTo()", (getHarness) => {
54
+ // For convenience, get the current suite's harness before all tests
55
+ let harness;
56
+ before(() => {
57
+ harness = getHarness();
58
+ });
59
+
54
60
  it("Should work", () => {
55
61
  return new Promise(async (resolve) => {
56
62
  // Start the adapter and wait until it has started
@@ -15,9 +15,9 @@ export interface TestContext {
15
15
  * Defines a test suite. At the start of each suite, the adapter will be started with a fresh environment.
16
16
  * To define tests in each suite, use describe and it as usual.
17
17
  *
18
- * Each suite has its own test harness, which gets passed as an argument.
18
+ * Each suite has its own test harness, which can be retrieved using the function that is passed to the suite callback.
19
19
  */
20
- suite: (name: string, fn: (harness: TestHarness) => void) => void;
20
+ suite: (name: string, fn: (getHarness: () => TestHarness) => void) => void;
21
21
  describe: Mocha.SuiteFunction;
22
22
  it: Mocha.TestFunction;
23
23
  }
@@ -175,18 +175,13 @@ function testAdapter(adapterDir, options = {}) {
175
175
  describe("User-defined tests", () => {
176
176
  // patch the global it() function so nobody can bypass the checks
177
177
  global.it = patchedIt;
178
- const lazyHarness = new Proxy({}, {
179
- get(target, propKey) {
180
- return harness[propKey];
181
- },
182
- });
183
178
  const args = {
184
179
  // a test suite is a special describe which sets up and tears down the test environment before and after ALL tests
185
180
  suite: (name, fn) => {
186
181
  describe(name, () => {
187
182
  isInSuite = true;
188
183
  before(resetDbAndStartHarness);
189
- fn(lazyHarness);
184
+ fn(() => harness);
190
185
  after(shutdownTests);
191
186
  isInSuite = false;
192
187
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/testing",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Shared utilities for adapter and module testing in ioBroker",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",