Skip to content

Commit

Permalink
Attempt at fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Aug 28, 2024
1 parent cffad1c commit 07e52d6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/js-sdk-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
exclude:
- node-version: 14.x
os: macOS-latest
name: Node.js ${{ matrix.node-version }} (${{ matrix.node-version }}) test
name: Node.js ${{ matrix.node-version }} test
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"request": "launch",
"name": "Run tests",
"cwd": "${workspaceRoot}",
"env": { "TS_NODE_PROJECT": "./tsconfig.mocha.json" },
"env": { "TS_NODE_PROJECT": "./tsconfig.mocha.node.json" },
"runtimeArgs": [
"--expose-gc"
],
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--require",
"ts-node/register",
"test/**/*.ts",
"test/node/index.ts",
"--fgrep",
"",
"--color",
Expand Down
20 changes: 12 additions & 8 deletions test/ConfigCatClientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,13 @@ describe("ConfigCatClient", () => {
setupHooks: hooks => hooks.on("configChanged", () => configChangedEventCount++)
};
const options: AutoPollOptions = new AutoPollOptions("APIKEY", "common", "1.0.0", userOptions, null);
new ConfigCatClient(options, configCatKernel);

await delay(2.5 * pollIntervalSeconds * 1000);
const client = new ConfigCatClient(options, configCatKernel);
try {
await delay(2.5 * pollIntervalSeconds * 1000);

assert.equal(configChangedEventCount, 3);
assert.equal(configChangedEventCount, 3);
}
finally { client.dispose(); }
});

it("Initialization With AutoPollOptions - config doesn't change - should fire configChanged only once", async () => {
Expand All @@ -543,11 +545,13 @@ describe("ConfigCatClient", () => {
setupHooks: hooks => hooks.on("configChanged", () => configChangedEventCount++)
};
const options: AutoPollOptions = new AutoPollOptions("APIKEY", "common", "1.0.0", userOptions, null);
new ConfigCatClient(options, configCatKernel);

await delay(2.5 * pollIntervalSeconds * 1000);
const client = new ConfigCatClient(options, configCatKernel);
try {
await delay(2.5 * pollIntervalSeconds * 1000);

assert.equal(configChangedEventCount, 1);
assert.equal(configChangedEventCount, 1);
}
finally { client.dispose(); }
});

it("Initialization With AutoPollOptions - with maxInitWaitTimeSeconds - getValueAsync should wait", async () => {
Expand Down
1 change: 1 addition & 0 deletions test/DefaultEventEmitterTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assert } from "chai";
import { DefaultEventEmitter } from "../src/DefaultEventEmitter";
import "core-js/features/array/flat.js";

function createHandler(eventName: string, capturedArgs: any[][]) {
return (...args: any[]) => capturedArgs.push([eventName, args]);
Expand Down
4 changes: 3 additions & 1 deletion test/helpers/fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ export class FakeConfigFetcherWithAlwaysVariableEtag extends FakeConfigFetcher {
return '{"f":{"debug":{"t":0,"v":{"b":true},"i":"abcdefgh"}}}';
}

private eTag = 0;

getEtag(): string {
return Math.random().toString();
return `"${(this.eTag++).toString(16).padStart(8, "0")}"`;
}
}

Expand Down
16 changes: 16 additions & 0 deletions webpack.karma.chromium-extension.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ module.exports = new function(options) {
configFile: "tsconfig.karma.chromium-extension.json"
}
}]
},
// Some test dependencies may use modern ES features which are not supported
// by all the targets defined in our CI workflow.
// So these dependencies must be downleveled to not break the checks.
// (@babel/preset-env transpiles to ES5 by default.)
{
test: /\.m?js$/,
include: [
path.resolve("node_modules/mock-xmlhttprequest")
],
use: [{
loader: "babel-loader",
options: {
"presets": ["@babel/preset-env"]
}
}]
}
]
}
Expand Down

0 comments on commit 07e52d6

Please sign in to comment.