From 68f6a8bec07d70f686425b279e953bd712ac6651 Mon Sep 17 00:00:00 2001 From: devin ivy Date: Mon, 25 Apr 2022 09:55:48 -0400 Subject: [PATCH 01/11] Drop node v12, support node v18 (#175) * Drop node v12: test on v14, v16, and v18. Update typescript * Utilize node v14+ syntax --- .github/workflows/ci-module.yml | 3 +++ LICENSE.md | 6 +++--- lib/index.js | 22 +++++++++++----------- package.json | 5 +++-- test/index.js | 6 +++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-module.yml b/.github/workflows/ci-module.yml index 9dc4315..18ea44f 100644 --- a/.github/workflows/ci-module.yml +++ b/.github/workflows/ci-module.yml @@ -3,6 +3,7 @@ name: ci on: push: branches: + - v9 - master pull_request: workflow_dispatch: @@ -10,3 +11,5 @@ on: jobs: test: uses: hapijs/.github/.github/workflows/ci-module.yml@master + with: + min-node-version: 14 diff --git a/LICENSE.md b/LICENSE.md index 59e4358..82fe1b1 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ -Copyright (c) 2014-2012, Sideway Inc, and project contributors -Copyright (c) 2014, Walmart -Copyright (c) 2011-2014 Jake Luer +Copyright (c) 2014-2022, Sideway Inc, and project contributors +Copyright (c) 2014, Walmart +Copyright (c) 2011-2014 Jake Luer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/lib/index.js b/lib/index.js index c10ff4e..a456866 100755 --- a/lib/index.js +++ b/lib/index.js @@ -50,9 +50,9 @@ internals.atUnnamedRx = /^\s*at (?:async )?(.+)\:(\d+)\:(\d+)\)?$/; exports.thrownAt = function (error) { - error = error || new Error(); + error = error ?? new Error(); const stack = typeof error.stack === 'string' ? error.stack : ''; - const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] || ''; + const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] ?? ''; const at = frame.match(frame.includes('(') ? internals.atNamedRx : internals.atUnnamedRx); return Array.isArray(at) ? { filename: at[1], @@ -83,7 +83,7 @@ exports.expect = function (value, prefix) { internals.Assertion = function (ref, prefix, location, at) { this._ref = ref; - this._prefix = prefix || ''; + this._prefix = prefix ?? ''; this._location = location; this._at = at; this._flags = {}; @@ -135,7 +135,7 @@ internals.Assertion.prototype.assert = function (result, verb, actual, expected) Error.captureStackTrace(error, this.assert); error.actual = actual; error.expected = expected; - error.at = exports.thrownAt(error) || this._at; + error.at = exports.thrownAt(error) ?? this._at; throw error; }; @@ -193,7 +193,7 @@ internals.addMethod = function (names, fn) { internals.addMethod('error', function (...args /* type, message */) { const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : Error; - const lastArg = args[1] || args[0]; + const lastArg = args[1] ?? args[0]; const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null; const err = this._ref; @@ -296,7 +296,7 @@ internals.addMethod('length', internals.length); internals.equal = function (value, options) { - options = options || {}; + options = options ?? {}; const settings = Hoek.applyToDefaults({ prototype: exports.settings.comparePrototypes, deepFunction: true }, options); const compare = this._flags.shallow ? (a, b) => a === b @@ -397,7 +397,7 @@ internals.throw = function (...args /* type, message */) { internals.assert(this, !this._flags.not || !args.length, 'Cannot specify arguments when expecting not to throw'); const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null; - const lastArg = args[1] || args[0]; + const lastArg = args[1] ?? args[0]; const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null; let thrown = false; @@ -413,7 +413,7 @@ internals.throw = function (...args /* type, message */) { } if (message !== null) { - const error = err.message || ''; + const error = err.message ?? ''; this.assert(typeof message === 'string' ? error === message : error.match(message), 'throw an error with specified message', error, message); } @@ -433,7 +433,7 @@ internals.reject = async function (...args/* type, message */) { internals.assert(this, internals.isPromise(this._ref), 'Can only assert reject on promises'); const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null; - const lastArg = args[1] || args[0]; + const lastArg = args[1] ?? args[0]; const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null; let thrown = null; @@ -456,7 +456,7 @@ internals.reject = async function (...args/* type, message */) { } if (message !== null) { - const error = thrown.message || ''; + const error = thrown.message ?? ''; this.assert(typeof message === 'string' ? error === message : error.match(message), 'reject with an error with specified message', error, message); } @@ -479,7 +479,7 @@ internals.addMethod(['reject', 'rejects'], internals.reject); internals.isPromise = function (promise) { - return promise && typeof promise.then === 'function'; + return typeof promise?.then === 'function'; }; diff --git a/package.json b/package.json index 78eba7d..8f9acdf 100755 --- a/package.json +++ b/package.json @@ -23,8 +23,9 @@ }, "devDependencies": { "@hapi/eslint-plugin": "*", - "@hapi/lab": "24.x.x", - "typescript": "~4.0.2" + "@hapi/lab": "25.0.0-beta.0", + "@types/node": "^17.0.25", + "typescript": "~4.6.3" }, "scripts": { "test": "lab -t 100 -L -Y", diff --git a/test/index.js b/test/index.js index 1471f28..dbe21c8 100755 --- a/test/index.js +++ b/test/index.js @@ -586,9 +586,9 @@ describe('expect()', () => { it('invalidates assertion (anonymous type)', () => { - const Custom = function () { }; - Util.inherits(Custom, Error); - delete Custom.name; // Ensure that the type is anonymous + const Custom = class extends Error { + static name = undefined; // Ensure that the type is anonymous + }; try { Code.expect(error).to.be.an.error(Custom); From 9985ad13f2b9cfbc25e0a68ce27753c39ac67c26 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Sun, 1 May 2022 14:32:28 -0400 Subject: [PATCH 02/11] Update deps for node v18 support, remove CI reference to old branch --- .github/workflows/ci-module.yml | 1 - package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-module.yml b/.github/workflows/ci-module.yml index 18ea44f..54426ca 100644 --- a/.github/workflows/ci-module.yml +++ b/.github/workflows/ci-module.yml @@ -3,7 +3,6 @@ name: ci on: push: branches: - - v9 - master pull_request: workflow_dispatch: diff --git a/package.json b/package.json index 8f9acdf..573a084 100755 --- a/package.json +++ b/package.json @@ -19,11 +19,11 @@ ] }, "dependencies": { - "@hapi/hoek": "9.x.x" + "@hapi/hoek": "10.x.x" }, "devDependencies": { "@hapi/eslint-plugin": "*", - "@hapi/lab": "25.0.0-beta.0", + "@hapi/lab": "25.0.0-beta.1", "@types/node": "^17.0.25", "typescript": "~4.6.3" }, From 1dda95a8aafe668b0d19274e576a870805d394d6 Mon Sep 17 00:00:00 2001 From: devin ivy Date: Sun, 1 May 2022 15:21:51 -0400 Subject: [PATCH 03/11] Fix license years for Sideway versus contributors (#176) --- LICENSE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 82fe1b1..244fd32 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,5 @@ -Copyright (c) 2014-2022, Sideway Inc, and project contributors +Copyright (c) 2014-2022, Project contributors +Copyright (c) 2014-2020, Sideway Inc Copyright (c) 2014, Walmart Copyright (c) 2011-2014 Jake Luer All rights reserved. From a4ab995a4372fec067778ba1666e9c71ccfd9218 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Sun, 1 May 2022 16:10:43 -0400 Subject: [PATCH 04/11] 9.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 573a084..6a3ba7b 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/code", "description": "assertion library", - "version": "8.0.7", + "version": "9.0.0", "repository": "git://github.com/hapijs/code", "main": "lib/index.js", "types": "lib/index.d.ts", From 02ee6bbf66797790b3c3e8793aed581031df6aaf Mon Sep 17 00:00:00 2001 From: Ari Bolton Date: Tue, 14 Jun 2022 08:39:43 -0700 Subject: [PATCH 05/11] Fix `reject()` types (#177) * Fix types * Update tests * Update docs * Update lab * Remove redundant await's Co-authored-by: Gil Pedersen --- API.md | 2 +- lib/index.d.ts | 20 ++++++++++---------- package.json | 2 +- test/index.ts | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/API.md b/API.md index cb39273..7f0f1fb 100755 --- a/API.md +++ b/API.md @@ -625,7 +625,7 @@ and compared to the provided optional requirements where: - `message` a string or regular expression matching the rejected error `message` property. Note that a string must provide a full match. -Returns the rejected error object. +Returns a promise resolving to the rejected error object. ```js const NodeUtil = require('util'); diff --git a/lib/index.d.ts b/lib/index.d.ts index 4759610..026b97b 100755 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -616,10 +616,10 @@ declare namespace expect { * @param type - constructor function the error must be an instance of. * @param message - string or regular expression the error message must match. * - * @returns rejected value. + * @returns a promise resolving to the rejected value. */ - reject(type: Class, message?: string | RegExp): E; - reject(message?: string | RegExp): E; + reject(type: Class, message?: string | RegExp): Promise; + reject(message?: string | RegExp): Promise; /** * Asserts that the Promise reference value rejects with an exception when called. @@ -627,10 +627,10 @@ declare namespace expect { * @param type - constructor function the error must be an instance of. * @param message - string or regular expression the error message must match. * - * @returns rejected value. + * @returns a promise resolving to the rejected value. */ - rejects(type: Class, message?: string | RegExp): E; - rejects(message?: string | RegExp): E; + rejects(type: Class, message?: string | RegExp): Promise; + rejects(message?: string | RegExp): Promise; } interface Not_PromiseAssertion extends BaseAssertion { @@ -638,15 +638,15 @@ declare namespace expect { /** * Asserts that the Promise reference value rejects with an exception when called. * - * @returns null. + * @returns a promise resolving to null. */ - reject(): null; + reject(): Promise; /** * Asserts that the Promise reference value rejects with an exception when called. * - * @returns null. + * @returns a promise resolving to null. */ - rejects(): null; + rejects(): Promise; } } diff --git a/package.json b/package.json index 6a3ba7b..756dd93 100755 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "@hapi/eslint-plugin": "*", - "@hapi/lab": "25.0.0-beta.1", + "@hapi/lab": "^25.0.1", "@types/node": "^17.0.25", "typescript": "~4.6.3" }, diff --git a/test/index.ts b/test/index.ts index d756dd2..12e9476 100755 --- a/test/index.ts +++ b/test/index.ts @@ -186,8 +186,8 @@ Code.expect(type2).to.equal({ a: [1] }, { skip: ['c'] }); const rejection = Promise.reject(new Error('Oh no!')); -await expect.type>(Code.expect(rejection).to.reject('Oh no!')); -await expect.type>(Code.expect(rejection).rejects('Oh no!')); +expect.type>(Code.expect(rejection).to.reject('Oh no!')); +expect.type>(Code.expect(rejection).rejects('Oh no!')); class CustomError extends Error { } @@ -200,10 +200,10 @@ Code.expect(throws).to.throw(CustomError, 'Oh no!'); Code.expect(() => { }).to.not.throw().and.to.be.a.function(); const typedRejection = Promise.reject(new CustomError('Oh no!')); -await expect.type(Code.expect(typedRejection).to.reject(CustomError, 'Oh no!')); -await expect.type(Code.expect(typedRejection).rejects(CustomError, 'Oh no!')); +expect.type>(Code.expect(typedRejection).to.reject(CustomError, 'Oh no!')); +expect.type>(Code.expect(typedRejection).rejects(CustomError, 'Oh no!')); -await expect.type(Code.expect(Promise.resolve(true)).to.not.reject()); +expect.type>(Code.expect(Promise.resolve(true)).to.not.reject()); function foo(): number | undefined { return 123; From aa1f2b36bcdd56d69f876af5d1e2b114807c80d2 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 14 Jun 2022 11:40:21 -0400 Subject: [PATCH 06/11] 9.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 756dd93..31c6989 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/code", "description": "assertion library", - "version": "9.0.0", + "version": "9.0.1", "repository": "git://github.com/hapijs/code", "main": "lib/index.js", "types": "lib/index.d.ts", From b4ffcec5880a463ac2f4fb06097c943a9787fa63 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Tue, 29 Nov 2022 09:37:58 +0100 Subject: [PATCH 07/11] Fix typo and add missing type (#178) * Fix typo * Add missing about assertion * Update lib/index.d.ts Co-authored-by: Jonas Pauthier Co-authored-by: Jonas Pauthier --- lib/index.d.ts | 10 ++++++++++ lib/index.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 026b97b..f9de592 100755 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -504,6 +504,16 @@ declare namespace expect { */ above(value: T): Assertion; + /** + * Asserts that the reference value is within a delta difference from the provided value. + * + * @param value - the value to compare to. + * @param delta - the delta +/- range value. + * + * @returns assertion chain object. + */ + about(value: T, delta: number): Assertion; + /** * Asserts that the reference value is greater than (>) the provided value. * diff --git a/lib/index.js b/lib/index.js index a456866..cd20268 100755 --- a/lib/index.js +++ b/lib/index.js @@ -356,7 +356,7 @@ internals.between = function (from, to) { internals.addMethod('between', internals.between); -internals.above = function (value, delta) { +internals.about = function (value, delta) { internals.assert(this, internals.type(this._ref) === 'number', 'Can only assert about on numbers'); internals.assert(this, internals.type(value) === 'number' && internals.type(delta) === 'number', 'About assertion requires two number arguments'); @@ -364,7 +364,7 @@ internals.above = function (value, delta) { return this.assert(Math.abs(this._ref - value) <= delta, 'be about ' + value + ' \u00b1' + delta); }; -internals.addMethod('about', internals.above); +internals.addMethod('about', internals.about); internals.instanceof = function (type) { From 0de76047dcf4b6875872879204d0547d4a684fd3 Mon Sep 17 00:00:00 2001 From: Nargonath Date: Tue, 29 Nov 2022 09:46:15 +0100 Subject: [PATCH 08/11] 9.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 31c6989..718c3c1 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/code", "description": "assertion library", - "version": "9.0.1", + "version": "9.0.2", "repository": "git://github.com/hapijs/code", "main": "lib/index.js", "types": "lib/index.d.ts", From 63dbf43b55065a1fd15ea9e3b57e7ed7ea1cc465 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Sat, 11 Feb 2023 19:00:46 +0100 Subject: [PATCH 09/11] chore: bump hoek (#179) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 718c3c1..fa0a0c9 100755 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ ] }, "dependencies": { - "@hapi/hoek": "10.x.x" + "@hapi/hoek": "^11.0.2" }, "devDependencies": { "@hapi/eslint-plugin": "*", From 425043e302090e541f569ee37d8dd4c0444a9cf4 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Sat, 11 Feb 2023 19:01:14 +0100 Subject: [PATCH 10/11] 9.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa0a0c9..9fd3a78 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/code", "description": "assertion library", - "version": "9.0.2", + "version": "9.0.3", "repository": "git://github.com/hapijs/code", "main": "lib/index.js", "types": "lib/index.d.ts", From b1b39c033f8109da62db1221b209153f9a59ce36 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Wed, 23 Oct 2024 17:37:38 +0200 Subject: [PATCH 11/11] chore: pin eslint-plugin --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fd3a78..5ed5047 100755 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "@hapi/hoek": "^11.0.2" }, "devDependencies": { - "@hapi/eslint-plugin": "*", + "@hapi/eslint-plugin": "^6.0.0", "@hapi/lab": "^25.0.1", "@types/node": "^17.0.25", "typescript": "~4.6.3"