Skip to content

Commit d82d029

Browse files
committed
chore: cleanup
1 parent 8a4defb commit d82d029

18 files changed

+131
-173
lines changed

Diff for: __tests__/perfume.spec.ts

+7-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as observe from '../src/observe';
99
import { visibility } from '../src/onVisibilityChange';
1010
import { IThresholdTier } from '../src/types';
1111
import { config } from '../src/config';
12-
import { testConfig } from './userJourneyTestConstants';
12+
import { testConfig } from './stepsTestConstants';
1313
import mock from './_mock';
1414

1515
describe('Perfume', () => {
@@ -58,24 +58,9 @@ describe('Perfume', () => {
5858
});
5959
});
6060

61-
it('should run with userJourney config version A', () => {
61+
it('should run with steps config version B', () => {
6262
new Perfume({
63-
userJourneys: {
64-
first_journey: {
65-
steps: [
66-
'load_first_screen_first_journey',
67-
'load_second_screen_first_journey',
68-
'load_third_screen_first_journey',
69-
'load_fourth_screen_first_journey',
70-
],
71-
},
72-
},
73-
});
74-
});
75-
76-
it('should run with userJourney config version B', () => {
77-
new Perfume({
78-
userJourneySteps: {
63+
steps: {
7964
load_first_screen_first_journey: {
8065
threshold: IThresholdTier.unavoidable,
8166
marks: ['launch', 'loaded_first_screen_first_journey'],
@@ -91,25 +76,15 @@ describe('Perfume', () => {
9176
});
9277
});
9378

94-
it('should run with userJourney config version D', () => {
79+
it('should run with steps config version D', () => {
9580
new Perfume({
96-
onMarkJourney: () => {},
81+
onMarkStep: () => {},
9782
});
9883
});
9984

100-
it('should run with userJourney config version E', () => {
85+
it('should run with steps config version E', () => {
10186
new Perfume({
102-
userJourneys: {
103-
first_journey: {
104-
steps: [
105-
'load_first_screen_first_journey',
106-
'load_second_screen_first_journey',
107-
'load_third_screen_first_journey',
108-
'load_fourth_screen_first_journey',
109-
],
110-
},
111-
},
112-
userJourneySteps: {
87+
steps: {
11388
load_first_screen_first_journey: {
11489
threshold: IThresholdTier.unavoidable,
11590
marks: ['launch', 'loaded_first_screen_first_journey'],

Diff for: __tests__/userJourney/markJourney.spec.ts renamed to __tests__/steps/markJourney.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* @jest-environment jsdom
33
*/
44
import { WP } from '../../src/constants';
5-
import mock from '.././_mock';
5+
import mock from '../_mock';
66
import Perfume from '../../src/perfume';
7-
import { markJourney } from '../../src/userJourney/markJourney';
8-
import { userJourneyMap } from '../../src/userJourney/userJourneyMap';
7+
import { markStep } from '../../src/steps/markStep';
8+
import { steps } from '../../src/steps/steps';
99

10-
import { testConfig } from '../userJourneyTestConstants';
10+
import { testConfig } from '../stepsTestConstants';
1111

12-
describe('markJourney', () => {
12+
describe('markStep', () => {
1313
let spy: jest.SpyInstance;
1414

1515
beforeEach(() => {
@@ -24,22 +24,22 @@ describe('markJourney', () => {
2424
}
2525
});
2626

27-
describe('markJourney()', () => {
27+
describe('markStep()', () => {
2828
it('correctly sets the activeSteps maps', () => {
2929
spy = jest.spyOn(WP, 'mark');
30-
markJourney('start_navigate_to_second_screen_first_journey');
30+
markStep('start_navigate_to_second_screen_first_journey');
3131
expect(spy.mock.calls.length).toBe(1);
3232
expect(spy).toHaveBeenCalledWith(
3333
'mark.start_navigate_to_second_screen_first_journey',
3434
);
35-
expect(userJourneyMap.activeSteps).toMatchObject({
35+
expect(steps.active).toMatchObject({
3636
load_second_screen_first_journey: true,
3737
});
3838
});
3939

40-
it('using the markJourneyOnce function should call WP.mark with the journey name', () => {
40+
it('using the markStepOnce function should call WP.mark with the journey name', () => {
4141
spy = jest.spyOn(WP, 'mark');
42-
markJourney('start_navigate_to_second_screen_first_journey');
42+
markStep('start_navigate_to_second_screen_first_journey');
4343
expect(spy.mock.calls.length).toBe(1);
4444
expect(spy).toHaveBeenCalledWith(
4545
'mark.start_navigate_to_second_screen_first_journey',

Diff for: __tests__/userJourney/markJourneyOnce.spec.ts renamed to __tests__/steps/markJourneyOnce.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* @jest-environment jsdom
44
*/
55
import { WP } from '../../src/constants';
6-
import mock from '.././_mock';
6+
import mock from '../_mock';
77
import Perfume from '../../src/perfume';
8-
import { markJourneyOnce } from '../../src/userJourney/markJourneyOnce';
8+
import { markStepOnce } from '../../src/steps/markStepOnce';
99

10-
import { testConfig } from '../userJourneyTestConstants';
10+
import { testConfig } from '../stepsTestConstants';
1111

12-
describe('markJourneyOnce', () => {
12+
describe('markStepOnce', () => {
1313
let spy: jest.SpyInstance;
1414

1515
beforeEach(() => {
@@ -24,11 +24,11 @@ describe('markJourneyOnce', () => {
2424
}
2525
});
2626

27-
describe('markJourneyOnce()', () => {
27+
describe('markStepOnce()', () => {
2828
it('using the markJourneyOnce function should call WP.mark with the journey name', () => {
2929
jest.spyOn(WP, 'getEntriesByName').mockImplementation(() => []);
3030
spy = jest.spyOn(WP, 'mark');
31-
markJourneyOnce('start_navigate_to_second_screen_first_journey');
31+
markStepOnce('start_navigate_to_second_screen_first_journey');
3232
expect(spy.mock.calls.length).toBe(1);
3333
expect(spy).toHaveBeenCalledWith(
3434
'mark.start_navigate_to_second_screen_first_journey',

Diff for: __tests__/userJourney/measureStep.spec.ts renamed to __tests__/steps/measureStep.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* @jest-environment jsdom
33
*/
44
import { WP } from '../../src/constants';
5-
import mock from '.././_mock';
5+
import mock from '../_mock';
66
import Perfume from '../../src/perfume';
7-
import { markJourney } from '../../src/userJourney/markJourney';
7+
import { markStep } from '../../src/steps/markStep';
88
import { config } from '../../src/config';
99

10-
import { testConfig } from '../userJourneyTestConstants';
10+
import { testConfig } from '../stepsTestConstants';
1111

12-
describe('measureUserJourneyStep', () => {
12+
describe('measureStep', () => {
1313
let spy: jest.SpyInstance;
1414
let analyticsTrackerSpy: jest.SpyInstance;
1515
let measureSpy: jest.SpyInstance;
@@ -31,12 +31,12 @@ describe('measureUserJourneyStep', () => {
3131
config.analyticsTracker = () => {};
3232
spy = jest.spyOn(WP, 'mark');
3333
analyticsTrackerSpy = jest.spyOn(config, 'analyticsTracker');
34-
markJourney('start_navigate_to_second_screen_first_journey');
34+
markStep('start_navigate_to_second_screen_first_journey');
3535
expect(spy.mock.calls.length).toBe(1);
3636
expect(spy).toHaveBeenCalledWith(
3737
'mark.start_navigate_to_second_screen_first_journey',
3838
);
39-
markJourney('start_navigate_to_third_screen_first_journey');
39+
markStep('start_navigate_to_third_screen_first_journey');
4040
expect(spy.mock.calls.length).toBe(2);
4141
expect(spy).toHaveBeenLastCalledWith(
4242
'mark.start_navigate_to_third_screen_first_journey',
@@ -51,7 +51,7 @@ describe('measureUserJourneyStep', () => {
5151
spy = jest.spyOn(WP, 'mark');
5252
measureSpy = jest.spyOn(WP, 'measure');
5353
analyticsTrackerSpy = jest.spyOn(config, 'analyticsTracker');
54-
markJourney('start_navigate_to_second_screen_first_journey');
54+
markStep('start_navigate_to_second_screen_first_journey');
5555
expect(spy.mock.calls.length).toBe(1);
5656
expect(spy).toHaveBeenCalledWith(
5757
'mark.start_navigate_to_second_screen_first_journey',
@@ -100,7 +100,7 @@ describe('measureUserJourneyStep', () => {
100100
return [entries[name]] ?? [];
101101
});
102102
// ========== Mock Data end ==========
103-
markJourney('loaded_second_screen_first_journey');
103+
markStep('loaded_second_screen_first_journey');
104104
expect(spy.mock.calls.length).toBe(2);
105105
expect(spy).toHaveBeenLastCalledWith(
106106
'mark.loaded_second_screen_first_journey',

Diff for: __tests__/userJourney/onMarkJourney.spec.ts renamed to __tests__/steps/onMarkJourney.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* @jest-environment jsdom
33
*/
44
import { WP } from '../../src/constants';
5-
import mock from '.././_mock';
5+
import mock from '../_mock';
66
import Perfume from '../../src/perfume';
7-
import { markJourney } from '../../src/userJourney/markJourney';
7+
import { markStep } from '../../src/steps/markStep';
88
import { config } from '../../src/config';
99

10-
import { testConfig } from '../userJourneyTestConstants';
10+
import { testConfig } from '../stepsTestConstants';
1111

12-
describe('markJourney', () => {
12+
describe('markStep', () => {
1313
let spy: jest.SpyInstance;
14-
let onMarkJourneySpy: jest.SpyInstance;
14+
let onMarkStepSpy: jest.SpyInstance;
1515

1616
beforeEach(() => {
1717
(WP as any) = mock.performance();
@@ -25,20 +25,20 @@ describe('markJourney', () => {
2525
}
2626
});
2727

28-
describe('callback markJourney', () => {
28+
describe('callback onMarkStep', () => {
2929
it('start and finish one single step', () => {
30-
config.onMarkJourney = () => {};
31-
onMarkJourneySpy = jest.spyOn(config, 'onMarkJourney');
30+
config.onMarkStep = () => {};
31+
onMarkStepSpy = jest.spyOn(config, 'onMarkStep');
3232
// start with the first mark
33-
markJourney('start_navigate_to_second_screen_first_journey');
33+
markStep('start_navigate_to_second_screen_first_journey');
3434

35-
expect(onMarkJourneySpy).toHaveBeenCalledWith(
35+
expect(onMarkStepSpy).toHaveBeenCalledWith(
3636
'start_navigate_to_second_screen_first_journey',
3737
['load_second_screen_first_journey'],
3838
);
3939

40-
markJourney('loaded_second_screen_first_journey');
41-
expect(onMarkJourneySpy).toHaveBeenLastCalledWith(
40+
markStep('loaded_second_screen_first_journey');
41+
expect(onMarkStepSpy).toHaveBeenLastCalledWith(
4242
'loaded_second_screen_first_journey',
4343
['load_second_screen_first_journey'],
4444
);

Diff for: __tests__/userJourney/setStepsMap.spec.ts renamed to __tests__/steps/setStepsMap.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import { WP } from '../../src/constants';
55
import mock from '../_mock';
66
import Perfume from '../../src/perfume';
7-
import { userJourneyMap } from '../../src/userJourney/userJourneyMap';
7+
import { steps } from '../../src/steps/steps';
88

9-
import { testConfig } from '../userJourneyTestConstants';
9+
import { testConfig } from '../stepsTestConstants';
1010

11-
describe('setUserJourneyStepsMap', () => {
11+
describe('setSteps', () => {
1212
beforeEach(() => {
1313
(WP as any) = mock.performance();
1414
const perfume = new Perfume(testConfig);
1515
});
1616

1717
describe('correctly sets each map', () => {
1818
it('correctly sets the finalMarkToStepsMap map', () => {
19-
expect(userJourneyMap.finalMarkToStepsMap).toMatchObject({
19+
expect(steps.finalMarkToStepsMap).toMatchObject({
2020
loaded_first_screen_first_journey: {
2121
launch: ['load_first_screen_first_journey'],
2222
},
@@ -56,7 +56,7 @@ describe('setUserJourneyStepsMap', () => {
5656
});
5757
});
5858
it('correctly sets the startMarkToStepsMap map', () => {
59-
expect(userJourneyMap.startMarkToStepsMap).toMatchObject({
59+
expect(steps.startMarkToStepsMap).toMatchObject({
6060
launch: {
6161
load_first_screen_first_journey: true,
6262
load_first_screen_second_journey: true,

Diff for: __tests__/userJourneyTestConstants.ts renamed to __tests__/stepsTestConstants.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* istanbul ignore file */
22

33
import {
4-
IUserJourneyThresholds,
4+
IStepsThresholds,
55
IPerfumeOptions,
66
IPerfumeConfig,
77
IThresholdTier,
8-
IUserJourneyStepsConfig,
8+
IStepsConfig,
99
} from '../src/types';
1010

11-
export const STEP_THRESHOLDS: IUserJourneyThresholds = {
11+
export const STEP_THRESHOLDS: IStepsThresholds = {
1212
[IThresholdTier.instant]: {
1313
vitalsThresholds: [100, 200],
1414
maxOutlierThreshold: 10000,
@@ -31,7 +31,7 @@ export const STEP_THRESHOLDS: IUserJourneyThresholds = {
3131
},
3232
};
3333

34-
const userJourneySteps: IUserJourneyStepsConfig = {
34+
const steps: IStepsConfig = {
3535
load_second_screen_first_journey: {
3636
threshold: IThresholdTier.instant,
3737
marks: [
@@ -81,8 +81,8 @@ const userJourneySteps: IUserJourneyStepsConfig = {
8181
};
8282

8383
export const testConfig: IPerfumeOptions = {
84-
userJourneySteps,
85-
onMarkJourney: jest.fn(),
84+
steps,
85+
onMarkStep: jest.fn(),
8686
};
8787

8888
export type TestConfig = IPerfumeConfig;

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
7575
"testPathIgnorePatterns": [
7676
"_mock.ts",
77-
"userJourneyTestConstants.ts",
77+
"stepsTestConstants.ts",
7878
"/docs/",
7979
"/node_modules/"
8080
],

Diff for: src/perfume.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { reportStorageEstimate } from './storageEstimate';
1919
import { IPerfumeOptions } from './types';
2020
import { roundByFour } from './utils';
2121
import { getVitalsScore } from './vitalsScore';
22-
import { setStepsMap } from './userJourney/setStepsMap';
22+
import { setStepsMap } from './steps/setStepsMap';
2323

2424
let ntbtTimeoutID = 0;
2525

@@ -33,8 +33,8 @@ export default class Perfume {
3333
config.isElementTiming = !!options.elementTiming;
3434
config.maxTime = options.maxMeasureTime || config.maxTime;
3535
config.reportOptions = options.reportOptions || config.reportOptions;
36-
config.userJourneySteps = options.userJourneySteps;
37-
config.onMarkJourney = options.onMarkJourney;
36+
config.steps = options.steps;
37+
config.onMarkStep = options.onMarkStep;
3838

3939
// Exit from Perfume when basic Web Performance APIs aren't supported
4040
if (!isPerformanceSupported()) {
@@ -68,8 +68,8 @@ export default class Perfume {
6868
if (WN && WN.storage && typeof WN.storage.estimate === 'function') {
6969
WN.storage.estimate().then(reportStorageEstimate);
7070
}
71-
// initializing User Journeys if present
72-
if (config.userJourneySteps) {
71+
// initializing Steps if present
72+
if (config.steps) {
7373
setStepsMap();
7474
}
7575
}

Diff for: src/userJourney/markJourney.ts renamed to src/steps/markStep.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { M, WP } from '../constants';
33
import { measureSteps } from './measureSteps';
44

55
/**
6-
* Function which creates a journey mark with a name generated
6+
* Function which creates a step mark with a name generated
77
* from the provided mark when called.
88
*
99
* The generated mark name has the following format:
1010
* `mark.${mark}`
1111
*
1212
*/
13-
export const markJourney = (mark: string) => {
13+
export const markStep = (mark: string) => {
1414
WP.mark(M + mark);
1515
measureSteps(mark);
1616
};

Diff for: src/userJourney/markJourneyOnce.ts renamed to src/steps/markStepOnce.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { M, WP } from '../constants';
33
import { measureSteps } from './measureSteps';
44

55
/**
6-
* Function which creates a journey mark with a name generated
6+
* Function which creates a step mark with a name generated
77
* from the provided mark if a mark with the same name does not
88
* already exist when called.
99
*
1010
* The generated mark name has the following format:
1111
* `mark.${mark}`
1212
*
1313
*/
14-
export const markJourneyOnce = (mark: string) => {
14+
export const markStepOnce = (mark: string) => {
1515
if (WP.getEntriesByName(M + mark).length === 0) {
1616
WP.mark(M + mark);
1717
measureSteps(mark);

0 commit comments

Comments
 (0)