Skip to content

Commit 835fd48

Browse files
fix: expose running journey as currentJourney (#988)
1 parent 8e60803 commit 835fd48

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

__tests__/core/index.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ it('add journeys to runner', () => {
5454

5555
expect(j.name).toBe(name);
5656
expect(j.id).toBe(name);
57-
expect(runner.journey).toEqual(j);
57+
expect(runner.currentJourney).toEqual(j);
5858
expect(runner.journeys.length).toBe(1);
5959
});
6060

@@ -63,22 +63,22 @@ it('add steps to journeys', () => {
6363
const s1 = step('step1', noop);
6464
const s2 = step('step2', noop);
6565

66-
expect(runner.journey).toEqual(j);
66+
expect(runner.currentJourney).toEqual(j);
6767
expect(runner.journeys.length).toBe(1);
68-
expect(runner.journey?.steps.length).toBe(2);
69-
expect(runner.journey?.steps).toEqual([s1, s2]);
68+
expect(runner.currentJourney?.steps.length).toBe(2);
69+
expect(runner.currentJourney?.steps).toEqual([s1, s2]);
7070
});
7171

7272
it('add hooks to journeys', () => {
7373
const j = journey(name, noop);
7474
before(noop);
7575
after(noop);
7676

77-
expect(runner.journey).toEqual(j);
77+
expect(runner.currentJourney).toEqual(j);
7878
expect(runner.journeys.length).toBe(1);
79-
expect(runner.journey?.steps.length).toBe(0);
80-
expect(runner.journey?._getHook("before")).toEqual([noop]);
81-
expect(runner.journey?._getHook("after")).toEqual([noop]);
79+
expect(runner.currentJourney?.steps.length).toBe(0);
80+
expect(runner.currentJourney?._getHook("before")).toEqual([noop]);
81+
expect(runner.currentJourney?._getHook("after")).toEqual([noop]);
8282
});
8383

8484
it('add hooks - error on before/after outside journey context', () => {

__tests__/core/runner.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ describe('runner', () => {
181181
const error = new Error('Broken step');
182182
const j1 = journey('fail-journey-with-hooks', () => {
183183
before(({ info }) => {
184-
expect(info.journey?.status).toBe('pending');
184+
expect(info.currentJourney?.status).toBe('pending');
185185
});
186186
after(({ info }) => {
187-
expect(info.journey?.status).toBe('failed');
188-
expect(info.journey?.error).toBe(error);
189-
expect(info.journey?.duration).toBeGreaterThan(0);
187+
expect(info.currentJourney?.status).toBe('failed');
188+
expect(info.currentJourney?.error).toBe(error);
189+
expect(info.currentJourney?.duration).toBeGreaterThan(0);
190190
});
191191
step('step1', () => { throw error });
192192
});
@@ -201,11 +201,11 @@ describe('runner', () => {
201201
it('run journey - expose info in journey', async () => {
202202
const j1 = journey('with info', ({ info }) => {
203203
step('step1', () => {
204-
expect(info.journey?.status).toBe('pending');
204+
expect(info.currentJourney?.status).toBe('pending');
205205
});
206206
after(({ info }) => {
207-
expect(info.journey?.status).toBe('succeeded');
208-
expect(info.journey?.duration).toBeGreaterThan(0);
207+
expect(info.currentJourney?.status).toBe('succeeded');
208+
expect(info.currentJourney?.duration).toBeGreaterThan(0);
209209
})
210210
});
211211
const result = await runner._runJourney(j1, defaultRunOptions);

src/core/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const createStep = (type?: 'skip' | 'soft' | 'only') =>
6464
wrapFnWithLocation(
6565
(location: Location, name: string, callback: VoidCallback) => {
6666
log(`Step register: ${name}`);
67-
const step = runner.journey?._addStep(name, callback, location);
67+
const step = runner.currentJourney?._addStep(name, callback, location);
6868
if (type) {
6969
step[type] = true;
7070
}
@@ -83,8 +83,8 @@ export const monitor = {
8383
* If the context is inside journey, then set it to journey context
8484
* otherwise set to the global monitor which will be used for all journeys
8585
*/
86-
if (runner.journey) {
87-
runner.journey._updateMonitor(config);
86+
if (runner.currentJourney) {
87+
runner.currentJourney._updateMonitor(config);
8888
} else {
8989
runner._updateMonitor(config);
9090
}
@@ -100,15 +100,15 @@ export const afterAll = (callback: HooksCallback) => {
100100
};
101101

102102
export const before = (callback: HooksCallback) => {
103-
if (!runner.journey) {
103+
if (!runner.currentJourney) {
104104
throw new Error('before is called outside of the journey context');
105105
}
106-
return runner.journey._addHook('before', callback);
106+
return runner.currentJourney._addHook('before', callback);
107107
};
108108

109109
export const after = (callback: HooksCallback) => {
110-
if (!runner.journey) {
110+
if (!runner.currentJourney) {
111111
throw new Error('after is called outside of the journey context');
112112
}
113-
return runner.journey._addHook('after', callback);
113+
return runner.currentJourney._addHook('after', callback);
114114
};

src/core/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface RunnerInfo {
6666
/**
6767
* Currently active journey
6868
*/
69-
readonly journey: Journey | undefined;
69+
readonly currentJourney: Journey | undefined;
7070
/**
7171
* All registerd journeys
7272
*/
@@ -86,7 +86,7 @@ export default class Runner implements RunnerInfo {
8686
#monitor?: Monitor;
8787
config: RunOptions;
8888

89-
get journey() {
89+
get currentJourney() {
9090
return this.#currentJourney;
9191
}
9292

0 commit comments

Comments
 (0)