Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/evaluator/matchers/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MaybeThenable } from '../../dtos/types';
import { ISegmentsCacheBase } from '../../storages/types';
import { ILogger } from '../../logger/types';
import thenable from '../../utils/promise/thenable';
import { ENGINE_MATCHER_SEGMENT_ASYNC, ENGINE_MATCHER_SEGMENT } from '../../logger/constants';
import { ENGINE_MATCHER_SEGMENT } from '../../logger/constants';

export default function matcherSegmentContext(log: ILogger, segmentName: string, storage: { segments: ISegmentsCacheBase }) {

Expand All @@ -11,7 +11,7 @@ export default function matcherSegmentContext(log: ILogger, segmentName: string,

if (thenable(isInSegment)) {
isInSegment.then(result => {
log.debug(ENGINE_MATCHER_SEGMENT_ASYNC, [segmentName, key, isInSegment]);
log.debug(ENGINE_MATCHER_SEGMENT, [segmentName, key, isInSegment]);

return result;
});
Expand Down
8 changes: 4 additions & 4 deletions src/integrations/__tests__/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ describe('IntegrationsManagerFactory for browser', () => {

let integrations: BrowserIntegration[] = [{ type: GOOGLE_ANALYTICS_TO_SPLIT }, { type: SPLIT_TO_GOOGLE_ANALYTICS }];
const instance2 = browserIMF(integrations, fakeParams as any) as IIntegrationManager;
expect((GaToSplitMock as jest.Mock).mock.calls.length).toBe(1); // GaToSplit invoked once
expect((SplitToGaMock as unknown as jest.Mock).mock.calls.length).toBe(1); // SplitToGa invoked once
expect(GaToSplitMock).toBeCalledTimes(1); // GaToSplit invoked once
expect(SplitToGaMock).toBeCalledTimes(1); // SplitToGa invoked once
expect(typeof instance2.handleImpression).toBe('function'); // The instance should implement the handleImpression method if settings.integrations has items that register a listener.
expect(typeof instance2.handleEvent).toBe('function'); // The instance should implement the handleEvent method if settings.integrations has items that register a listener.

clearMocks();

integrations = [{ type: GOOGLE_ANALYTICS_TO_SPLIT }, { type: SPLIT_TO_GOOGLE_ANALYTICS }, { type: GOOGLE_ANALYTICS_TO_SPLIT }, { type: SPLIT_TO_GOOGLE_ANALYTICS }, { type: SPLIT_TO_GOOGLE_ANALYTICS }];
browserIMF(integrations, fakeParams as any);
expect((GaToSplitMock as jest.Mock).mock.calls.length).toBe(2); // GaToSplit invoked twice
expect((SplitToGaMock as unknown as jest.Mock).mock.calls.length).toBe(3); // SplitToGa invoked thrice
expect(GaToSplitMock).toBeCalledTimes(2); // GaToSplit invoked twice
expect(SplitToGaMock).toBeCalledTimes(3); // SplitToGa invoked thrice

clearMocks();
});
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/ga/__tests__/GaToSplit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ test('GaToSplit: `hits` flag param', () => {
// send hit and assert that it was not tracked as a Split event
(fakeStorage.events.track as jest.Mock).mockClear();
window.ga('send', hitSample);
expect((fakeStorage.events.track as jest.Mock).mock.calls.length).toBe(0);
expect(fakeStorage.events.track).toBeCalledTimes(0);

// test teardown
gaRemove();
Expand Down
14 changes: 7 additions & 7 deletions src/integrations/ga/__tests__/SplitToGa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('SplitToGa', () => {

let integration = new SplitToGa(loggerMock, {});
expect(typeof integration).toBe('object');
expect(loggerMock.warn.mock.calls.length).toBe(0);
expect(loggerMock.warn).not.toBeCalled();

gaRemove();
expect(SplitToGa.getGa()).toBe(undefined); // should return undefined if ga command queue does not exist
Expand All @@ -110,13 +110,13 @@ describe('SplitToGa', () => {
const instance = new SplitToGa(loggerMock, {}) as SplitToGa;
instance.queue(fakeImpression);
// should queue `ga send` with the default mapped FieldsObject for impressions, appended with `splitHit` field
expect(ga.mock.calls[ga.mock.calls.length - 1]).toEqual(['send', { ...defaultImpressionFieldsObject, splitHit: true }]);
expect(ga).lastCalledWith('send', { ...defaultImpressionFieldsObject, splitHit: true });

instance.queue(fakeEvent);
// should queue `ga send` with the default mapped FieldsObject for events, appended with `splitHit` field
expect(ga.mock.calls[ga.mock.calls.length - 1]).toEqual(['send', { ...defaultEventFieldsObject, splitHit: true }]);
expect(ga).lastCalledWith('send', { ...defaultEventFieldsObject, splitHit: true });

expect(ga.mock.calls.length).toBe(2);
expect(ga).toBeCalledTimes(2);

/** Custom behaviour **/
// Custom filter
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('SplitToGa', () => {
[`${trackerNames[1]}.send`, { ...customMapper(), splitHit: true }]
]); // should queue `ga send` with the custom trackerName and FieldsObject from customMapper, appended with `splitHit` field

expect(ga.mock.calls.length).toBe(2);
expect(ga).toBeCalledTimes(2);

// Custom mapper that returns the default FieldsObject
function customMapper2(data: SplitIO.IntegrationData, defaultFieldsObject: UniversalAnalytics.FieldsObject) {
Expand All @@ -158,9 +158,9 @@ describe('SplitToGa', () => {
ga.mockClear();
instance3.queue(fakeImpression);
// should queue `ga send` with the custom FieldsObject from customMapper2, appended with `splitHit` field
expect(ga.mock.calls[ga.mock.calls.length - 1]).toEqual(['send', { ...customMapper2(fakeImpression, defaultImpressionFieldsObject), splitHit: true }]);
expect(ga).lastCalledWith('send', { ...customMapper2(fakeImpression, defaultImpressionFieldsObject), splitHit: true });

expect(ga.mock.calls.length).toBe(1);
expect(ga).toBeCalledTimes(1);

// Custom mapper that throws an error
function customMapper3() {
Expand Down
26 changes: 13 additions & 13 deletions src/listeners/__tests__/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ test('Browser JS listener / Impressions optimized mode', (done) => {

setTimeout(() => {
// Unload event was triggered. Thus sendBeacon method should have been called three times.
expect((global.window.navigator.sendBeacon as jest.Mock).mock.calls.length).toBe(3);
expect(global.window.navigator.sendBeacon).toBeCalledTimes(3);

// Http post services should have not been called
expect((fakeSplitApi.postTestImpressionsBulk as jest.Mock).mock.calls.length).toBe(0);
expect((fakeSplitApi.postEventsBulk as jest.Mock).mock.calls.length).toBe(0);
expect((fakeSplitApi.postTestImpressionsCount as jest.Mock).mock.calls.length).toBe(0);
expect(fakeSplitApi.postTestImpressionsBulk).not.toBeCalled();
expect(fakeSplitApi.postEventsBulk).not.toBeCalled();
expect(fakeSplitApi.postTestImpressionsCount).not.toBeCalled();

// pre-check and call stop
expect((global.window.removeEventListener as jest.Mock).mock.calls.length).toBe(0);
expect(global.window.removeEventListener).not.toBeCalled();
listener.stop();

// removed correct listener from correct signal on stop.
Expand All @@ -149,12 +149,12 @@ test('Browser JS listener / Impressions debug mode', (done) => {

setTimeout(() => {
// Unload event was triggered. Thus sendBeacon method should have been called twice.
expect((global.window.navigator.sendBeacon as jest.Mock).mock.calls.length).toBe(2);
expect(global.window.navigator.sendBeacon).toBeCalledTimes(2);

// Http post services should have not been called
expect((fakeSplitApi.postTestImpressionsBulk as jest.Mock).mock.calls.length).toBe(0);
expect((fakeSplitApi.postEventsBulk as jest.Mock).mock.calls.length).toBe(0);
expect((fakeSplitApi.postTestImpressionsCount as jest.Mock).mock.calls.length).toBe(0);
expect(fakeSplitApi.postTestImpressionsBulk).not.toBeCalled();
expect(fakeSplitApi.postEventsBulk).not.toBeCalled();
expect(fakeSplitApi.postTestImpressionsCount).not.toBeCalled();

// pre-check and call stop
expect(global.window.removeEventListener).not.toBeCalled();
Expand Down Expand Up @@ -183,12 +183,12 @@ test('Browser JS listener / Impressions debug mode without sendBeacon API', (don

setTimeout(() => {
// Unload event was triggered. Thus sendBeacon method should have been called twice.
expect((sendBeacon as jest.Mock).mock.calls.length).toBe(0);
expect(sendBeacon).not.toBeCalled();

// Http post services should have not been called
expect((fakeSplitApi.postTestImpressionsBulk as jest.Mock).mock.calls.length).toBe(1);
expect((fakeSplitApi.postEventsBulk as jest.Mock).mock.calls.length).toBe(1);
expect((fakeSplitApi.postTestImpressionsCount as jest.Mock).mock.calls.length).toBe(0);
expect(fakeSplitApi.postTestImpressionsBulk).toBeCalledTimes(1);
expect(fakeSplitApi.postEventsBulk).toBeCalledTimes(1);
expect(fakeSplitApi.postTestImpressionsCount).not.toBeCalled();

// pre-check and call stop
expect(global.window.removeEventListener).not.toBeCalled();
Expand Down
42 changes: 21 additions & 21 deletions src/listeners/__tests__/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ test('Node JS listener / Signal Listener SIGTERM callback with sync handler', ()
jest.spyOn(listener, 'stop');

// Control asserts.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(0);
expect(handlerMock.mock.calls.length).toBe(0);
expect(processKillSpy.mock.calls.length).toBe(0);
expect(listener.stop).not.toBeCalled();
expect(handlerMock).not.toBeCalled();
expect(processKillSpy).not.toBeCalled();

// Call function
// @ts-expect-error
listener._sigtermHandler();

// Handler was properly called.
expect(handlerMock.mock.calls.length).toBe(1);
expect(handlerMock).toBeCalledTimes(1);

// Clean up is called.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(1);
expect(listener.stop).toBeCalledTimes(1);
// It called for kill again, so the shutdown keeps going.
expect(processKillSpy.mock.calls).toEqual([[process.pid, 'SIGTERM']]);

Expand All @@ -64,21 +64,21 @@ test('Node JS listener / Signal Listener SIGTERM callback with sync handler that
jest.spyOn(listener, 'stop');

// Control asserts.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(0);
expect(handlerMock.mock.calls.length).toBe(0);
expect(processKillSpy.mock.calls.length).toBe(0);
expect(listener.stop).not.toBeCalled();
expect(handlerMock).not.toBeCalled();
expect(processKillSpy).not.toBeCalled();

// Call function.
// @ts-expect-error
listener._sigtermHandler();

// Handler was properly called.
expect(handlerMock.mock.calls.length).toBe(1);
expect(handlerMock).toBeCalledTimes(1);

// Even if the handler throws, clean up is called.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(1);
expect(listener.stop).toBeCalledTimes(1);
// Even if the handler throws, it should call for kill again, so the shutdown keeps going.
expect(processKillSpy.mock.calls.length).toBe(1);
expect(processKillSpy).toBeCalledTimes(1);
expect(processKillSpy.mock.calls).toEqual([[process.pid, 'SIGTERM']]);

// Reset the kill spy since it's used on other tests.
Expand Down Expand Up @@ -107,17 +107,17 @@ test('Node JS listener / Signal Listener SIGTERM callback with async handler', a
listener._sigtermHandler();

// Handler was properly called.
expect(handlerMock.mock.calls.length).toBe(1);
expect(handlerMock).toBeCalledTimes(1);

// Check that the wrap up is waiting for the promise to be resolved.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(0);
expect(processKillSpy.mock.calls.length).toBe(0);
expect(listener.stop).not.toBeCalled();
expect(processKillSpy).not.toBeCalled();

fakePromise.then(() => {
// Clean up is called even if there is an error.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(1);
expect(listener.stop).toBeCalledTimes(1);
// It called for kill again, so the shutdown keeps going.
expect(processKillSpy.mock.calls.length).toBe(1);
expect(processKillSpy).toBeCalledTimes(1);
expect(processKillSpy.mock.calls).toEqual([[process.pid, 'SIGTERM']]);

// Reset the kill spy since it's used on other tests.
Expand Down Expand Up @@ -151,18 +151,18 @@ test('Node JS listener / Signal Listener SIGTERM callback with async handler tha
const handlerPromise = listener._sigtermHandler();

// Handler was properly called.
expect(handlerMock.mock.calls.length).toBe(1);
expect(handlerMock).toBeCalledTimes(1);

// Check that the wrap up is waiting for the promise to be resolved.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(0);
expect(processKillSpy.mock.calls.length).toBe(0);
expect(listener.stop).not.toBeCalled();
expect(processKillSpy).not.toBeCalled();

// Calling .then since the wrapUp handler does not throw.
(handlerPromise as Promise<void>).then(() => {
// Clean up is called.
expect((listener.stop as jest.Mock).mock.calls.length).toBe(1);
expect(listener.stop).toBeCalledTimes(1);
// It called for kill again, so the shutdown keeps going.
expect(processKillSpy.mock.calls.length).toBe(1);
expect(processKillSpy).toBeCalledTimes(1);
expect(processKillSpy.mock.calls).toEqual([[process.pid, 'SIGTERM']]);

/* Clean up everything */
Expand Down
Loading