Skip to content

Commit 68f6a8b

Browse files
authored
Drop node v12, support node v18 (#175)
* Drop node v12: test on v14, v16, and v18. Update typescript * Utilize node v14+ syntax
1 parent ed94bc0 commit 68f6a8b

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

.github/workflows/ci-module.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ name: ci
33
on:
44
push:
55
branches:
6+
- v9
67
- master
78
pull_request:
89
workflow_dispatch:
910

1011
jobs:
1112
test:
1213
uses: hapijs/.github/.github/workflows/ci-module.yml@master
14+
with:
15+
min-node-version: 14

LICENSE.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Copyright (c) 2014-2012, Sideway Inc, and project contributors
2-
Copyright (c) 2014, Walmart
3-
Copyright (c) 2011-2014 Jake Luer
1+
Copyright (c) 2014-2022, Sideway Inc, and project contributors
2+
Copyright (c) 2014, Walmart
3+
Copyright (c) 2011-2014 Jake Luer
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

lib/index.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ internals.atUnnamedRx = /^\s*at (?:async )?(.+)\:(\d+)\:(\d+)\)?$/;
5050

5151
exports.thrownAt = function (error) {
5252

53-
error = error || new Error();
53+
error = error ?? new Error();
5454
const stack = typeof error.stack === 'string' ? error.stack : '';
55-
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] || '';
55+
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] ?? '';
5656
const at = frame.match(frame.includes('(') ? internals.atNamedRx : internals.atUnnamedRx);
5757
return Array.isArray(at) ? {
5858
filename: at[1],
@@ -83,7 +83,7 @@ exports.expect = function (value, prefix) {
8383
internals.Assertion = function (ref, prefix, location, at) {
8484

8585
this._ref = ref;
86-
this._prefix = prefix || '';
86+
this._prefix = prefix ?? '';
8787
this._location = location;
8888
this._at = at;
8989
this._flags = {};
@@ -135,7 +135,7 @@ internals.Assertion.prototype.assert = function (result, verb, actual, expected)
135135
Error.captureStackTrace(error, this.assert);
136136
error.actual = actual;
137137
error.expected = expected;
138-
error.at = exports.thrownAt(error) || this._at;
138+
error.at = exports.thrownAt(error) ?? this._at;
139139
throw error;
140140
};
141141

@@ -193,7 +193,7 @@ internals.addMethod = function (names, fn) {
193193
internals.addMethod('error', function (...args /* type, message */) {
194194

195195
const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : Error;
196-
const lastArg = args[1] || args[0];
196+
const lastArg = args[1] ?? args[0];
197197
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
198198
const err = this._ref;
199199

@@ -296,7 +296,7 @@ internals.addMethod('length', internals.length);
296296

297297
internals.equal = function (value, options) {
298298

299-
options = options || {};
299+
options = options ?? {};
300300
const settings = Hoek.applyToDefaults({ prototype: exports.settings.comparePrototypes, deepFunction: true }, options);
301301

302302
const compare = this._flags.shallow ? (a, b) => a === b
@@ -397,7 +397,7 @@ internals.throw = function (...args /* type, message */) {
397397
internals.assert(this, !this._flags.not || !args.length, 'Cannot specify arguments when expecting not to throw');
398398

399399
const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null;
400-
const lastArg = args[1] || args[0];
400+
const lastArg = args[1] ?? args[0];
401401
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
402402

403403
let thrown = false;
@@ -413,7 +413,7 @@ internals.throw = function (...args /* type, message */) {
413413
}
414414

415415
if (message !== null) {
416-
const error = err.message || '';
416+
const error = err.message ?? '';
417417
this.assert(typeof message === 'string' ? error === message : error.match(message), 'throw an error with specified message', error, message);
418418
}
419419

@@ -433,7 +433,7 @@ internals.reject = async function (...args/* type, message */) {
433433
internals.assert(this, internals.isPromise(this._ref), 'Can only assert reject on promises');
434434

435435
const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null;
436-
const lastArg = args[1] || args[0];
436+
const lastArg = args[1] ?? args[0];
437437
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
438438

439439
let thrown = null;
@@ -456,7 +456,7 @@ internals.reject = async function (...args/* type, message */) {
456456
}
457457

458458
if (message !== null) {
459-
const error = thrown.message || '';
459+
const error = thrown.message ?? '';
460460
this.assert(typeof message === 'string' ? error === message : error.match(message), 'reject with an error with specified message', error, message);
461461
}
462462

@@ -479,7 +479,7 @@ internals.addMethod(['reject', 'rejects'], internals.reject);
479479

480480
internals.isPromise = function (promise) {
481481

482-
return promise && typeof promise.then === 'function';
482+
return typeof promise?.then === 'function';
483483
};
484484

485485

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
},
2424
"devDependencies": {
2525
"@hapi/eslint-plugin": "*",
26-
"@hapi/lab": "24.x.x",
27-
"typescript": "~4.0.2"
26+
"@hapi/lab": "25.0.0-beta.0",
27+
"@types/node": "^17.0.25",
28+
"typescript": "~4.6.3"
2829
},
2930
"scripts": {
3031
"test": "lab -t 100 -L -Y",

test/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ describe('expect()', () => {
586586

587587
it('invalidates assertion (anonymous type)', () => {
588588

589-
const Custom = function () { };
590-
Util.inherits(Custom, Error);
591-
delete Custom.name; // Ensure that the type is anonymous
589+
const Custom = class extends Error {
590+
static name = undefined; // Ensure that the type is anonymous
591+
};
592592

593593
try {
594594
Code.expect(error).to.be.an.error(Custom);

0 commit comments

Comments
 (0)