Skip to content

Commit a5305f9

Browse files
committed
fix tests
1 parent 2ff16c9 commit a5305f9

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

lib/core/decision_service/index.tests.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import AudienceEvaluator from '../audience_evaluator';
3434
import errorHandler from '../../plugins/error_handler';
3535
import eventDispatcher from '../../plugins/event_dispatcher/index.node';
3636
import * as jsonSchemaValidator from '../../utils/json_schema_validator';
37+
import { getMockProjectConfigManager } from '../../tests/mock_project_config_manager';
38+
import { createProjectConfig } from '../project_config';
39+
3740
import {
3841
getTestProjectConfig,
3942
getTestProjectConfigWithFeatures,
@@ -1067,7 +1070,9 @@ describe('lib/core/decision_service', function() {
10671070
beforeEach(function() {
10681071
optlyInstance = new Optimizely({
10691072
clientEngine: 'node-sdk',
1070-
datafile: cloneDeep(testData),
1073+
projectConfigManager: getMockProjectConfigManager({
1074+
initConfig: createProjectConfig(cloneDeep(testData))
1075+
}),
10711076
jsonSchemaValidator: jsonSchemaValidator,
10721077
isValidInstance: true,
10731078
logger: createdLogger,

lib/optimizely_user_context/index.tests.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import eventDispatcher from '../plugins/event_dispatcher/index.node';
3030
import { CONTROL_ATTRIBUTES, LOG_LEVEL, LOG_MESSAGES } from '../utils/enums';
3131
import testData from '../tests/test_data';
3232
import { OptimizelyDecideOption } from '../shared_types';
33+
import { getMockProjectConfigManager } from '../tests/mock_project_config_manager';
34+
import { createProjectConfig } from '../core/project_config';
3335

3436
describe('lib/optimizely_user_context', function() {
3537
describe('APIs', function() {
@@ -356,7 +358,9 @@ describe('lib/optimizely_user_context', function() {
356358
beforeEach(function() {
357359
optlyInstance = new Optimizely({
358360
clientEngine: 'node-sdk',
359-
datafile: testData.getTestDecideProjectConfig(),
361+
projectConfigManager: getMockProjectConfigManager({
362+
initConfig: createProjectConfig(testData.getTestDecideProjectConfig())
363+
}),
360364
errorHandler: errorHandler,
361365
eventProcessor,
362366
isValidInstance: true,
@@ -689,7 +693,9 @@ describe('lib/optimizely_user_context', function() {
689693
beforeEach(function() {
690694
optlyInstance = new Optimizely({
691695
clientEngine: 'node-sdk',
692-
datafile: testData.getTestDecideProjectConfig(),
696+
projectConfigManager: getMockProjectConfigManager({
697+
initConfig: createProjectConfig(testData.getTestDecideProjectConfig())
698+
}),
693699
errorHandler: errorHandler,
694700
eventProcessor,
695701
isValidInstance: true,
@@ -791,7 +797,9 @@ describe('lib/optimizely_user_context', function() {
791797
beforeEach(function() {
792798
optlyInstance = new Optimizely({
793799
clientEngine: 'node-sdk',
794-
datafile: testData.getTestDecideProjectConfig(),
800+
projectConfigManager: getMockProjectConfigManager({
801+
initConfig: createProjectConfig(testData.getTestDecideProjectConfig())
802+
}),
795803
errorHandler: errorHandler,
796804
eventProcessor,
797805
isValidInstance: true,
@@ -833,7 +841,9 @@ describe('lib/optimizely_user_context', function() {
833841
});
834842
var optlyInstance = new Optimizely({
835843
clientEngine: 'node-sdk',
836-
datafile: testData.getTestDecideProjectConfig(),
844+
projectConfigManager: getMockProjectConfigManager({
845+
initConfig: createProjectConfig(testData.getTestDecideProjectConfig())
846+
}),
837847
errorHandler: errorHandler,
838848
eventProcessor,
839849
isValidInstance: true,

lib/utils/ticker/ticker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export class ExponentialBackoff implements BackoffController {
2525
this.current = base;
2626
}
2727

28-
backoff() {
28+
backoff(): number {
2929
this.current = Math.min(this.current * 2, this.max);
3030
return this.current + this.maxJitter * Math.random();
3131
}
3232

33-
reset() {
33+
reset(): void {
3434
this.current = this.base;
3535
}
3636
}
@@ -39,7 +39,7 @@ export class IntervalTicker implements Ticker {
3939
private timeoutId?: NodeJS.Timeout;
4040
private handler?: AsyncTransformer<boolean, void>;
4141
private interval: number;
42-
private prevSuccess: boolean = true;
42+
private prevSuccess = true;
4343
private backoffController?: BackoffController;
4444

4545
constructor(interval: number, backoffController?: BackoffController) {
@@ -56,7 +56,7 @@ export class IntervalTicker implements Ticker {
5656
this.setTimer(this.interval);
5757
}, () => {
5858
this.prevSuccess = false;
59-
let time = this.backoffController?.backoff() ?? this.interval;
59+
const time = this.backoffController?.backoff() ?? this.interval;
6060
this.setTimer(time);
6161
});
6262
}, timeout);
@@ -70,7 +70,7 @@ export class IntervalTicker implements Ticker {
7070
clearInterval(this.timeoutId);
7171
}
7272

73-
onTick(handler: AsyncTransformer<boolean, void>) {
73+
onTick(handler: AsyncTransformer<boolean, void>): void {
7474
this.handler = handler;
7575
}
7676
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"clean:win": "(if exist dist rd /s/q dist)",
7575
"lint": "tsc --noEmit && eslint 'lib/**/*.js' 'lib/**/*.ts'",
7676
"test-vitest": "tsc --noEmit --p tsconfig.spec.json && vitest run",
77-
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/index.browser.tests.js'",
77+
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r lib/tests/exit_on_unhandled_rejection.js '**/*.tests.js'",
7878
"test": "npm run test-mocha && npm run test-vitest",
7979
"posttest": "npm run lint",
8080
"test-ci": "npm run test-xbrowser && npm run test-umdbrowser",

vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineConfig({
44
test: {
55
onConsoleLog: () => true,
66
environment: 'happy-dom',
7-
include: ["**/static_project_config_manager.spec.ts"],
7+
include: ["**/*.spec.ts"],
88
typecheck: {
99
tsconfig: 'tsconfig.spec.json',
1010
exclude: ['**/index.react_native.spec.ts'],

0 commit comments

Comments
 (0)