Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix tests for node@16 error format change #4283

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ const Inert = require('@hapi/inert');
const Lab = require('@hapi/lab');
const Vision = require('@hapi/vision');
const Wreck = require('@hapi/wreck');
const Somever = require('@hapi/somever');

const Common = require('./common');

const internals = {};
const internals = {
// needed to handle changes in error output
isNode16OrHigher: Somever.match(process.version, '>=16.9.0')
};


const { describe, it } = exports.lab = Lab.script();
Expand Down Expand Up @@ -335,7 +339,8 @@ describe('Core', () => {
expect(res.statusCode).to.equal(500);

const [, event] = await log;
expect(event.error.message).to.equal('Cannot read property \'here\' of null');
const expectedErrorMessage = internals.isNode16OrHigher ? 'Cannot read properties of null (reading \'here\')' : 'Cannot read property \'here\' of null';
expect(event.error.message).to.equal(expectedErrorMessage);
});
});

Expand Down
9 changes: 7 additions & 2 deletions test/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const Code = require('@hapi/code');
const Hapi = require('..');
const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');
const Somever = require('@hapi/somever');


const internals = {};
const internals = {
// needed to handle changes in error output
isNode16OrHigher: Somever.match(process.version, '>=16.9.0')
};


const { describe, it } = exports.lab = Lab.script();
Expand Down Expand Up @@ -73,7 +77,8 @@ describe('handler', () => {
expect(res.statusCode).to.equal(500);

const [, event] = await log;
expect(event.error.message).to.equal('Cannot read property \'here\' of null');
const expectedErrorMessage = internals.isNode16OrHigher ? 'Cannot read properties of null (reading \'here\')' : 'Cannot read property \'here\' of null';
expect(event.error.message).to.equal(expectedErrorMessage);
});
});

Expand Down