Skip to content

Commit 0114b0f

Browse files
fix: capture ReferenceError inside journeys (#450)
1 parent 251f504 commit 0114b0f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

__tests__/cli.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ describe('CLI', () => {
5656
expect(await cli.exitCode).toBe(0);
5757
});
5858

59+
it('exit with 1 on syntax errors', async () => {
60+
const cli = new CLIMock()
61+
.stdin(`step('syntax error', async () => {}})`)
62+
.args(['--inline', '--rich-events'])
63+
.run();
64+
expect(await cli.exitCode).toBe(1);
65+
});
66+
67+
it('treat reference error as journey error', async () => {
68+
const cli = new CLIMock()
69+
.stdin(`apinotfound('fail', async () => {})`)
70+
.args(['--inline', '--rich-events'])
71+
.run();
72+
await cli.waitFor('journey/end');
73+
expect(cli.output()).toContain('apinotfound is not defined');
74+
expect(await cli.exitCode).toBe(0);
75+
});
76+
5977
it('does not load a configuration file without a config param', async () => {
6078
// jest by default sets NODE_ENV to `test`
6179
const original = process.env['NODE_ENV'];
@@ -539,7 +557,7 @@ class CLIMock {
539557
const dataListener = data => {
540558
this.data = data.toString();
541559
// Uncomment the line below if the process is blocked and you need to see its output
542-
// console.warn(this.data);
560+
// console.log('CLIMock.stdout:', this.data);
543561
this.chunks.push(...this.data.split('\n').filter(Boolean));
544562
if (this.waitForPromise && this.data.includes(this.waitForText)) {
545563
this.process.stdout.off('data', dataListener);
@@ -551,7 +569,7 @@ class CLIMock {
551569
this.exitCode = new Promise(res => {
552570
// Uncomment to debug stderr
553571
// this.process.stderr.on('data', data => {
554-
// console.log('climock.stderr: ', data.toString());
572+
// console.log('CLIMock.stderr:', data.toString());
555573
// });
556574
this.process.on('exit', code => res(code));
557575
});

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const loadInlineScript = source => {
6262
'expect',
6363
source
6464
);
65-
journey('inline', async ({ page, context, browser, params }) => {
65+
journey('inline', ({ page, context, browser, params }) => {
6666
scriptFn.apply(null, [step, page, context, browser, params, expect]);
6767
});
6868
};

0 commit comments

Comments
 (0)