diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f92878de..9a3361b4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - node_version: [20, 22, 24] + node_version: [22, 24] os: [ubuntu-latest, windows-latest, macOS-latest] steps: diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 19395843..00000000 --- a/.mocharc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "require": "./test/setup.js", - "ui": "bdd" -} diff --git a/eslint.config.js b/eslint.config.js index 304b60d3..f0e98b49 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -37,6 +37,7 @@ export default [ 'multiline-comment-style': [2, 'starred-block'], 'prefer-promise-reject-errors': 2, // "promise/prefer-await-to-then": 2, + 'n/no-unsupported-features/node-builtins': 0, 'security/detect-unsafe-regex': 2, }, }, diff --git a/package-lock.json b/package-lock.json index 75f94cf2..d3930b5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,8 +20,6 @@ "@commitlint/config-conventional": "^20.2.0", "@types/mocha": "^10.0.10", "c8": "^10.1.3", - "chai": "^4.5.0", - "chai-as-promised": "^8.0.2", "coveralls": "^3.1.1", "debug": "^4.4.3", "eslint": "^9.39.2", @@ -34,7 +32,6 @@ "husky": "^9.1.7", "is-ci": "^4.1.0", "mocha": "^11.7.5", - "mocha-circleci-reporter": "0.0.3", "mysql2": "3.16", "pg": "^8.16.3", "pg-query-stream": "^4.10.3", @@ -2100,15 +2097,6 @@ "node": ">=0.8" } }, - "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/asynckit": { "version": "0.4.0", "dev": true, @@ -2206,6 +2194,8 @@ }, "node_modules/browser-stdout": { "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true, "license": "ISC" }, @@ -2298,6 +2288,19 @@ "node": ">=6" } }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/caniuse-lite": { "version": "1.0.30001761", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz", @@ -2324,47 +2327,6 @@ "dev": true, "license": "Apache-2.0" }, - "node_modules/chai": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz", - "integrity": "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==", - "dev": true, - "license": "MIT", - "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.3", - "deep-eql": "^4.1.3", - "get-func-name": "^2.0.2", - "loupe": "^2.3.6", - "pathval": "^1.1.1", - "type-detect": "^4.1.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/chai-as-promised": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-8.0.2.tgz", - "integrity": "sha512-1GadL+sEJVLzDjcawPM4kjfnL+p/9vrxiEUonowKOAzvVg0PixJUdtuDzdkDeQhK3zfOE76GqGkZIQ7/Adcrqw==", - "dev": true, - "license": "MIT", - "dependencies": { - "check-error": "^2.1.1" - }, - "peerDependencies": { - "chai": ">= 2.1.2 < 7" - } - }, - "node_modules/chai-as-promised/node_modules/check-error": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", - "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", - "dev": true, - "engines": { - "node": ">= 16" - } - }, "node_modules/chalk": { "version": "4.1.2", "dev": true, @@ -2390,26 +2352,6 @@ "node": ">=10" } }, - "node_modules/charenc": { - "version": "0.0.2", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": "*" - } - }, - "node_modules/check-error": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", - "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", - "dev": true, - "dependencies": { - "get-func-name": "^2.0.2" - }, - "engines": { - "node": "*" - } - }, "node_modules/chokidar": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", @@ -2579,11 +2521,6 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "2.15.1", - "dev": true, - "license": "MIT" - }, "node_modules/comment-parser": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.4.1.tgz", @@ -2853,14 +2790,6 @@ "node": ">= 8" } }, - "node_modules/crypt": { - "version": "0.0.2", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": "*" - } - }, "node_modules/crypto-random-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-4.0.0.tgz", @@ -2932,16 +2861,17 @@ } } }, - "node_modules/deep-eql": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", - "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true, - "dependencies": { - "type-detect": "^4.0.0" - }, + "license": "MIT", "engines": { - "node": ">=6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/deep-extend": { @@ -3991,6 +3921,8 @@ }, "node_modules/flat": { "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, "license": "BSD-3-Clause", "bin": { @@ -4093,11 +4025,6 @@ "node": ">=14.14" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "dev": true, - "license": "ISC" - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -4149,15 +4076,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-func-name": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", - "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/get-stream": { "version": "6.0.1", "dev": true, @@ -4238,6 +4156,27 @@ "node": ">=16" } }, + "node_modules/glob": { + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", + "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/glob-parent": { "version": "6.0.2", "dev": true, @@ -4249,6 +4188,32 @@ "node": ">=10.13.0" } }, + "node_modules/glob/node_modules/brace-expansion": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/global-directory": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/global-directory/-/global-directory-4.0.1.tgz", @@ -4290,14 +4255,6 @@ "dev": true, "license": "ISC" }, - "node_modules/growl": { - "version": "1.10.5", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4.x" - } - }, "node_modules/handlebars": { "version": "4.7.8", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", @@ -4363,6 +4320,8 @@ }, "node_modules/he": { "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, "license": "MIT", "bin": { @@ -4590,15 +4549,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/inflight": { - "version": "1.0.6", - "dev": true, - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, "node_modules/inherits": { "version": "2.0.4", "dev": true, @@ -4636,11 +4586,6 @@ "dev": true, "license": "MIT" }, - "node_modules/is-buffer": { - "version": "1.1.6", - "dev": true, - "license": "MIT" - }, "node_modules/is-builtin-module": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", @@ -4739,6 +4684,8 @@ }, "node_modules/is-path-inside": { "version": "3.0.3", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", + "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true, "license": "MIT", "engines": { @@ -4793,6 +4740,8 @@ }, "node_modules/is-unicode-supported": { "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true, "license": "MIT", "engines": { @@ -5232,6 +5181,8 @@ }, "node_modules/log-symbols": { "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, "license": "MIT", "dependencies": { @@ -5251,15 +5202,6 @@ "integrity": "sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A==", "dev": true }, - "node_modules/loupe": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", - "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", - "dev": true, - "dependencies": { - "get-func-name": "^2.0.1" - } - }, "node_modules/lru-cache": { "version": "10.4.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", @@ -5359,16 +5301,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/md5": { - "version": "2.3.0", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "charenc": "0.0.2", - "crypt": "0.0.2", - "is-buffer": "~1.1.6" - } - }, "node_modules/meow": { "version": "12.1.1", "resolved": "https://registry.npmjs.org/meow/-/meow-12.1.1.tgz", @@ -5482,22 +5414,6 @@ "node": ">=16 || 14 >=14.17" } }, - "node_modules/mkdirp": { - "version": "0.5.1", - "dev": true, - "license": "MIT", - "dependencies": { - "minimist": "0.0.8" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/mkdirp/node_modules/minimist": { - "version": "0.0.8", - "dev": true, - "license": "MIT" - }, "node_modules/mocha": { "version": "11.7.5", "resolved": "https://registry.npmjs.org/mocha/-/mocha-11.7.5.tgz", @@ -5535,176 +5451,6 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/mocha-circleci-reporter": { - "version": "0.0.3", - "dev": true, - "license": "MIT", - "dependencies": { - "mocha": "^5.1.1", - "mocha-junit-reporter": "^1.17.0" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/ansi-regex": { - "version": "3.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/debug": { - "version": "3.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/diff": { - "version": "3.5.0", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/escape-string-regexp": { - "version": "1.0.5", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/glob": { - "version": "7.1.2", - "dev": true, - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/has-flag": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/he": { - "version": "1.1.1", - "dev": true, - "license": "MIT", - "bin": { - "he": "bin/he" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/minimatch": { - "version": "3.0.4", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/mocha": { - "version": "5.2.0", - "dev": true, - "license": "MIT", - "dependencies": { - "browser-stdout": "1.3.1", - "commander": "2.15.1", - "debug": "3.1.0", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.5", - "he": "1.1.1", - "minimatch": "3.0.4", - "mkdirp": "0.5.1", - "supports-color": "5.4.0" - }, - "bin": { - "_mocha": "bin/_mocha", - "mocha": "bin/mocha" - }, - "engines": { - "node": ">= 4.0.0" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/mocha-junit-reporter": { - "version": "1.23.3", - "dev": true, - "license": "MIT", - "dependencies": { - "debug": "^2.2.0", - "md5": "^2.1.0", - "mkdirp": "~0.5.1", - "strip-ansi": "^4.0.0", - "xml": "^1.0.0" - }, - "peerDependencies": { - "mocha": ">=2.2.5" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/mocha-junit-reporter/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/mocha-junit-reporter/node_modules/mkdirp": { - "version": "0.5.6", - "dev": true, - "license": "MIT", - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" - }, - "node_modules/mocha-circleci-reporter/node_modules/strip-ansi": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-regex": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/mocha-circleci-reporter/node_modules/supports-color": { - "version": "5.4.0", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/mocha/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -5722,27 +5468,6 @@ "balanced-match": "^1.0.0" } }, - "node_modules/mocha/node_modules/glob": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", - "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", - "dev": true, - "license": "ISC", - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^3.1.2", - "minimatch": "^9.0.4", - "minipass": "^7.1.2", - "package-json-from-dist": "^1.0.0", - "path-scurry": "^1.11.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/mocha/node_modules/js-yaml": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", @@ -8086,14 +7811,6 @@ "node": ">=0.10.0" } }, - "node_modules/once": { - "version": "1.4.0", - "dev": true, - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/onetime": { "version": "5.1.2", "dev": true, @@ -8311,14 +8028,6 @@ "node": ">=8" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-key": { "version": "3.1.1", "dev": true, @@ -8358,15 +8067,6 @@ "node": ">=8" } }, - "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/performance-now": { "version": "2.1.0", "dev": true, @@ -8714,6 +8414,7 @@ "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, + "license": "MIT", "dependencies": { "safe-buffer": "^5.1.0" } @@ -9613,6 +9314,7 @@ "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } @@ -10140,27 +9842,6 @@ "balanced-match": "^1.0.0" } }, - "node_modules/test-exclude/node_modules/glob": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz", - "integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==", - "dev": true, - "license": "ISC", - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^3.1.2", - "minimatch": "^9.0.4", - "minipass": "^7.1.2", - "package-json-from-dist": "^1.0.0", - "path-scurry": "^1.11.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/test-exclude/node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -10411,16 +10092,6 @@ "node": ">= 0.8.0" } }, - "node_modules/type-detect": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", - "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", @@ -10697,16 +10368,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "dev": true, - "license": "ISC" - }, - "node_modules/xml": { - "version": "1.0.1", - "dev": true, - "license": "MIT" - }, "node_modules/xtend": { "version": "4.0.2", "dev": true, @@ -10752,6 +10413,8 @@ }, "node_modules/yargs-unparser": { "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "license": "MIT", "dependencies": { @@ -10764,30 +10427,10 @@ "node": ">=10" } }, - "node_modules/yargs-unparser/node_modules/camelcase": { - "version": "6.3.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/yargs-unparser/node_modules/decamelize": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/yargs-unparser/node_modules/is-plain-obj": { "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index debea06b..b1a87853 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ "check-types": "tsc -p ./tsconfig.json", "prepublish": "npm run check-types", "test": "npm run spec && ((c8 report --reporter=text-lcov | coveralls) || exit 0)", - "test:ci": "eslint ./ && c8 mocha test/specs/**/*.spec.js --reporter mocha-circleci-reporter && (c8 report --reporter=text-lcov | coveralls)", + "test:ci": "eslint ./ && c8 node --test test/specs/**/*.spec.js && (c8 report --reporter=text-lcov | coveralls)", "test:integration": "bash ./test/integration/run.sh", - "spec": "c8 mocha test/specs/**/*.spec.js", + "spec": "c8 node --test test/specs/**/*.spec.js", "lint": "eslint ./ && npx prettier --check . && npm run check-types", "prettier": "prettier --write --ignore-unknown .", "lint-fix": "eslint --fix ./", @@ -59,8 +59,6 @@ "@commitlint/config-conventional": "^20.2.0", "@types/mocha": "^10.0.10", "c8": "^10.1.3", - "chai": "^4.5.0", - "chai-as-promised": "^8.0.2", "coveralls": "^3.1.1", "debug": "^4.4.3", "eslint": "^9.39.2", @@ -73,7 +71,6 @@ "husky": "^9.1.7", "is-ci": "^4.1.0", "mocha": "^11.7.5", - "mocha-circleci-reporter": "0.0.3", "mysql2": "3.16", "pg": "^8.16.3", "pg-query-stream": "^4.10.3", diff --git a/test/integration/binary.spec.js b/test/integration/binary.spec.js index 946f4ced..378ff769 100644 --- a/test/integration/binary.spec.js +++ b/test/integration/binary.spec.js @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; + import {dare} from './helpers/api.js'; describe(`Binary handling`, () => { diff --git a/test/integration/disparities.spec.js b/test/integration/disparities.spec.js index 423f18fe..cc9ad331 100644 --- a/test/integration/disparities.spec.js +++ b/test/integration/disparities.spec.js @@ -1,6 +1,7 @@ import Dare from '../../src/index.js'; import Debug from 'debug'; import assert from 'node:assert/strict'; + import mysql from 'mysql2/promise'; import db from './helpers/db.js'; import {options} from './helpers/api.js'; diff --git a/test/integration/get.spec.js b/test/integration/get.spec.js index 45c52f1d..ebf6e1b9 100644 --- a/test/integration/get.spec.js +++ b/test/integration/get.spec.js @@ -1,6 +1,6 @@ import {DareError} from '../../src/index.js'; -import {expect} from 'chai'; import assert from 'node:assert/strict'; + import defaultAPI, {options, castToStringIfNeeded} from './helpers/api.js'; import db from './helpers/db.js'; @@ -20,7 +20,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username']); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); }); it('can use pagination to get more results', async () => { @@ -55,7 +55,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username']); - expect(resp).to.have.property('username', newName); + assert.equal(resp.username, newName); }); it('can delete results', async () => { @@ -64,9 +64,10 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { await dare.del('users', {id: insertId}); - await expect(dare.get('users', ['username'], {id: insertId})) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.NOT_FOUND); + await assert.rejects( + dare.get('users', ['username'], {id: insertId}), + error => error instanceof DareError && error.code === DareError.NOT_FOUND + ); }); it('Can update results with INSERT...ON DUPLICATE KEYS UPDATE', async () => { @@ -83,7 +84,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username']); - expect(resp).to.have.property('username', newName); + assert.equal(resp.username, newName); }); it('should be able to return nested values', async () => { @@ -206,7 +207,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*username,first_name,last_name': '+Fir* +Las*', }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } // And use an alias of the fulltext field @@ -217,7 +218,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*textsearch': 'Fir* Las*', }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } // And format the search to be compatible with MySQL Fulltext syntax @@ -227,7 +228,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*textsearch': username, }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } // Hyphens @@ -235,7 +236,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*textsearch': '+last-name', }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } // Apostrophe's @@ -243,7 +244,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*textsearch': "+Old'n'Name", }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } // Full Text on Generated Fields @@ -264,7 +265,7 @@ describe(`Dare init tests: options ${Object.keys(options)}`, () => { const resp = await dare.get('users', ['username'], { '*ft_index': '+Old*n*', }); - expect(resp).to.have.property('username', username); + assert.equal(resp.username, username); } } }); diff --git a/test/integration/getFieldKey.spec.js b/test/integration/getFieldKey.spec.js index 85e0081a..86f61215 100644 --- a/test/integration/getFieldKey.spec.js +++ b/test/integration/getFieldKey.spec.js @@ -1,6 +1,7 @@ import Dare from '../../src/index.js'; import Debug from 'debug'; -import {expect} from 'chai'; +import assert from 'node:assert/strict'; + import mysql from 'mysql2/promise'; import db from './helpers/db.js'; import {options} from './helpers/api.js'; @@ -64,7 +65,7 @@ describe(`getFieldKey`, () => { {orderby: 'firstName'} ); - expect(resp).to.have.property('firstName', firstName); + assert.equal(resp.firstName, firstName); } // Post using camelCase @@ -80,7 +81,7 @@ describe(`getFieldKey`, () => { {orderby: 'firstName'} ); - expect(resp).to.have.property('firstName', firstName); + assert.equal(resp.firstName, firstName); } }); }); diff --git a/test/integration/helpers/MySQL.js b/test/integration/helpers/MySQL.js index 77a676e5..0e5b81e5 100644 --- a/test/integration/helpers/MySQL.js +++ b/test/integration/helpers/MySQL.js @@ -76,7 +76,7 @@ export default class MySQL { await this.conn.query(resetDataSql); } - end() { + async end() { // Close this connection return this.conn.end(); } diff --git a/test/integration/helpers/api.js b/test/integration/helpers/api.js index b2da742b..77038aa0 100644 --- a/test/integration/helpers/api.js +++ b/test/integration/helpers/api.js @@ -4,6 +4,7 @@ import mysql from 'mysql2/promise'; import db from './db.js'; import options from '../../data/options.js'; + const debug = Debug('sql'); export {options}; diff --git a/test/integration/json.spec.js b/test/integration/json.spec.js index 86d9676a..6b7a08ae 100644 --- a/test/integration/json.spec.js +++ b/test/integration/json.spec.js @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; + import SQL, {raw} from 'sql-template-tag'; import defaultAPI from './helpers/api.js'; diff --git a/test/integration/mocha-hooks/index.js b/test/integration/mocha-hooks/index.js index 4b6493b3..b382b6ed 100644 --- a/test/integration/mocha-hooks/index.js +++ b/test/integration/mocha-hooks/index.js @@ -1,10 +1,5 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import db from '../helpers/db.js'; -// Extend Chai -chai.use(chaiAsPromised); - const mochaHooks = { beforeAll: [ async function () { diff --git a/test/integration/multi-table-modifications.spec.js b/test/integration/multi-table-modifications.spec.js index bd53fbb3..5a1a94d1 100644 --- a/test/integration/multi-table-modifications.spec.js +++ b/test/integration/multi-table-modifications.spec.js @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; + import defaultAPI from './helpers/api.js'; describe('Multi table modifications', () => { diff --git a/test/integration/post_query.spec.js b/test/integration/post_query.spec.js index 18689a2d..2fcc4a32 100644 --- a/test/integration/post_query.spec.js +++ b/test/integration/post_query.spec.js @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; + import defaultAPI from './helpers/api.js'; describe('post from query', () => { diff --git a/test/integration/run.sh b/test/integration/run.sh index ac363608..19574f35 100644 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -25,7 +25,7 @@ cd "$INTEGRATION_TEST_DIR" || exit 1 DB_ROOT_USER="root" DB_ROOT_PASSWORD="test_pass" -DB_ENGINE=${DB_ENGINE:-mysql:8.0.23} +export DB_ENGINE=${DB_ENGINE:-mysql:8.0.23} DB_ENGINE_NAME=$(echo $DB_ENGINE | cut -d: -f1) diff --git a/test/integration/shortcut_map.spec.js b/test/integration/shortcut_map.spec.js index 4a661253..0cd65002 100644 --- a/test/integration/shortcut_map.spec.js +++ b/test/integration/shortcut_map.spec.js @@ -1,6 +1,7 @@ import Dare from '../../src/index.js'; import Debug from 'debug'; import assert from 'node:assert/strict'; + import mysql from 'mysql2/promise'; import db from './helpers/db.js'; import {options, castToStringIfNeeded} from './helpers/api.js'; diff --git a/test/integration/stream.spec.js b/test/integration/stream.spec.js index 88edb93f..82bcd4de 100644 --- a/test/integration/stream.spec.js +++ b/test/integration/stream.spec.js @@ -1,4 +1,5 @@ import assert from 'node:assert/strict'; + import Dare from '../../src/index.js'; import Debug from 'debug'; import mysql from 'mysql2/promise'; diff --git a/test/lib/sql-equal.js b/test/lib/sql-equal.js index b7a12159..05873658 100644 --- a/test/lib/sql-equal.js +++ b/test/lib/sql-equal.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert/strict'; /* * SQL Match * Convert a SQL string into a regular expression to compare with a generated SQL string @@ -6,7 +6,7 @@ import {expect} from 'chai'; export default (a, b) => { // Reformat both sql statements and compare - expect(reformat(a)).to.equal(reformat(b)); + assert.deepStrictEqual(reformat(a), reformat(b)); }; function reformat(sql) { diff --git a/test/setup.js b/test/setup.js index 4c12c7b8..9ed6f4f9 100644 --- a/test/setup.js +++ b/test/setup.js @@ -1,5 +1,4 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; - -// Extend Chai -chai.use(chaiAsPromised); +/* + * Native Node.js test framework setup + * No additional setup required for node:test and node:assert + */ diff --git a/test/specs/after.spec.js b/test/specs/after.spec.js index e2b56503..9743ff3c 100644 --- a/test/specs/after.spec.js +++ b/test/specs/after.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; +import {describe, it, beforeEach} from 'node:test'; describe('after Handler', () => { let dare; @@ -24,8 +25,8 @@ describe('after Handler', () => { }); }); - it('after handler should be defined in instances of Dare', () => { - expect(dare).to.have.property('after'); + it('after handler should be defined in instances of Dare', async () => { + assert.ok('after' in dare); }); describe('should be called after success on api methods', () => { @@ -44,7 +45,7 @@ describe('after Handler', () => { for (const method in env) { it(method, async () => { const resp = await env[method](); - expect(resp).to.eql('called'); + assert.strictEqual(resp, 'called'); }); } }); @@ -57,7 +58,7 @@ describe('after Handler', () => { return 'done'; }, expected(err, resp) { - expect(resp).to.eql('done'); + assert.strictEqual(resp, 'done'); }, }, { @@ -66,7 +67,7 @@ describe('after Handler', () => { return resp.map(item => item.id); }, expected(err, resp) { - expect(resp).to.eql([1]); + assert.deepStrictEqual(resp, [1]); }, }, { @@ -75,7 +76,7 @@ describe('after Handler', () => { return Promise.resolve(100); }, expected(err, resp) { - expect(resp).to.eql(100); + assert.strictEqual(resp, 100); }, }, { @@ -84,17 +85,17 @@ describe('after Handler', () => { // Do something but dont return... }, expected(err, resp) { - expect(resp).to.eql([{id: 1}]); + assert.deepStrictEqual(resp, [{id: 1}]); }, }, { label: 'called with the this.options', handler() { - expect(this.options).to.have.property('method', 'get'); - expect(this.options).to.have.property('table', 'users'); + assert.strictEqual(this.options.method, 'get'); + assert.strictEqual(this.options.table, 'users'); }, expected(err, resp) { - expect(resp).to.eql([{id: 1}]); + assert.deepStrictEqual(resp, [{id: 1}]); }, }, { @@ -103,7 +104,7 @@ describe('after Handler', () => { throw Error('whoops'); }, expected(err) { - expect(err).to.have.property('message', 'whoops'); + assert.strictEqual(err.message, 'whoops'); }, }, ].forEach(({label, handler: users, expected}) => { @@ -170,8 +171,8 @@ describe('after Handler', () => { for (const method in env) { it(method, async () => { const resp = await env[method](); - expect(resp).to.eql('overriden'); - expect(dare.after).to.not.eql(new_after_handler); + assert.strictEqual(resp, 'overriden'); + assert.notDeepStrictEqual(dare.after, new_after_handler); }); } }); diff --git a/test/specs/delete.spec.js b/test/specs/delete.spec.js index 05dc1b82..efa1e016 100644 --- a/test/specs/delete.spec.js +++ b/test/specs/delete.spec.js @@ -1,10 +1,10 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; -import assert from 'node:assert/strict'; // Test Generic DB functions import sqlEqual from '../lib/sql-equal.js'; import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; describe('del', () => { let dare; @@ -18,21 +18,21 @@ describe('del', () => { }; }); - it('should contain the function dare.del', () => { - expect(dare.del).to.be.a('function'); + it('should contain the function dare.del', async () => { + assert.strictEqual(typeof dare.del, 'function'); }); it('should generate an DELETE statement and execute dare.execute', async () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'DELETE FROM test WHERE test.id = ? LIMIT ?'); - expect(values).to.deep.equal([1, 1]); + assert.deepStrictEqual(values, [1, 1]); return {success: true}; }; const resp = await dare.del('test', {id: 1}); - expect(resp).to.have.property('success', true); + assert.strictEqual(resp.success, true); }); it('should throw an exception if affectedRows: 0', async () => { @@ -40,9 +40,11 @@ describe('del', () => { const test = dare.del('groups', {id: 20_000}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.NOT_FOUND); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.NOT_FOUND); + return true; + }); }); it('should return opts.notfound if affectedRows: 0', async () => { @@ -50,14 +52,14 @@ describe('del', () => { dare.sql = async () => ({affectedRows: 0}); const test = await dare.del('groups', {id: 20_000}, {notfound}); - return expect(test).to.equal(notfound); + return assert.strictEqual(test, notfound); }); it('should use provided table name', async () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'DELETE FROM test WHERE test.id = ? LIMIT ?'); - expect(values).to.deep.equal([1, 1]); + assert.deepStrictEqual(values, [1, 1]); return {success: true}; }; @@ -76,7 +78,7 @@ describe('del', () => { it('should trigger pre handler, options.del.[table]', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'DELETE FROM test WHERE test.id = ? LIMIT ?'); - expect(values).to.deep.equal([1, 1]); + assert.deepStrictEqual(values, [1, 1]); return {success: true}; }; @@ -98,7 +100,7 @@ describe('del', () => { it('should trigger pre handler, options.del.default, and wait for Promise to resolve', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'DELETE FROM test WHERE test.id = ? LIMIT ?'); - expect(values).to.deep.equal([1, 1]); + assert.deepStrictEqual(values, [1, 1]); return {success: true}; }; @@ -117,7 +119,7 @@ describe('del', () => { }); }); - it('should trigger pre handler, and handle errors being thrown', () => { + it('should trigger pre handler, and handle errors being thrown', async () => { const msg = 'test'; dare.options.models = { @@ -134,7 +136,7 @@ describe('del', () => { filter: {id: 2}, }); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); it('should return options.skip if set and not trigger further operations', async () => { @@ -151,7 +153,7 @@ describe('del', () => { filter: {id: 2}, }); - expect(resp).to.eql(true); + assert.strictEqual(resp, true); }); it('allow nested filters (integration-tested)', async () => { @@ -176,7 +178,7 @@ describe('del', () => { }, }); - expect(test).to.have.property('affectedRows', 1); + assert.strictEqual(test.affectedRows, 1); }); it('should allow nested filters with negation prefix (integration-tested)', async () => { @@ -201,7 +203,7 @@ describe('del', () => { }, }); - expect(test).to.have.property('affectedRows', 1); + assert.strictEqual(test.affectedRows, 1); }); describe('DB Engine specific tests', () => { diff --git a/test/specs/field_access.spec.js b/test/specs/field_access.spec.js index 95ce30ff..5e57bfb7 100644 --- a/test/specs/field_access.spec.js +++ b/test/specs/field_access.spec.js @@ -1,9 +1,9 @@ -import {expect} from 'chai'; import assert from 'node:assert/strict'; import Dare from '../../src/index.js'; // Test whether fields can be declared as immutable and unreadable import DareError from '../../src/utils/error.js'; import sqlEqual from '../lib/sql-equal.js'; +import {describe, it, beforeEach} from 'node:test'; describe('field access', () => { let dare; @@ -54,7 +54,7 @@ describe('field access', () => { ].forEach(field => { it(`should prevent access to non-readable field: ${JSON.stringify( field - )}`, () => { + )}`, async () => { const fieldName = field === 'unknown_field' ? field : 'password'; @@ -66,12 +66,13 @@ describe('field access', () => { ], }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - `Field '${fieldName}' is not readable` - ) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects( + call, + (err) => + err instanceof DareError && + err.message.includes(`Field '${fieldName}' is not readable`) && + err.code === DareError.INVALID_REFERENCE + ); }); }); @@ -81,7 +82,7 @@ describe('field access', () => { sql, `SELECT a.email_address AS "email" FROM users a LIMIT 1` ); - expect(values).to.deep.equal([]); + assert.deepEqual(values, []); return []; }; @@ -99,7 +100,7 @@ describe('field access', () => { }); describe('patch - UPDATE', () => { - it('should prevent mutations on non-writable fields', () => { + it('should prevent mutations on non-writable fields', async () => { const call = dare.patch({ table: 'users', body: { @@ -111,17 +112,18 @@ describe('field access', () => { }, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'id' is not writeable" - ) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects( + call, + (err) => + err instanceof DareError && + err.message.includes("Field 'id' is not writeable") && + err.code === DareError.INVALID_REFERENCE + ); }); }); describe('post - INSERT', () => { - it('should prevent inserts on non-writable fields', () => { + it('should prevent inserts on non-writable fields', async () => { const call = dare.post({ table: 'users', body: { @@ -130,17 +132,18 @@ describe('field access', () => { }, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'id' is not writeable" - ) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects( + call, + (err) => + err instanceof DareError && + err.message.includes("Field 'id' is not writeable") && + err.code === DareError.INVALID_REFERENCE + ); }); it('should allow inserts, not patch on writeable:false {post: {writeable: true}}', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'INSERT INTO users (`name`) VALUES (?)'); - expect(values).to.deep.equal(['me']); + assert.deepEqual(values, ['me']); return {insertId: 1}; }; @@ -152,7 +155,7 @@ describe('field access', () => { name: 'me', }, }); - expect(call).to.deep.equal({insertId: 1}); + assert.deepEqual(call, {insertId: 1}); } const call = dare.patch({ @@ -166,12 +169,13 @@ describe('field access', () => { }, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'name' is not writeable" - ) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects( + call, + (err) => + err instanceof DareError && + err.message.includes("Field 'name' is not writeable") && + err.code === DareError.INVALID_REFERENCE + ); }); }); }); diff --git a/test/specs/field_alias.spec.js b/test/specs/field_alias.spec.js index 25efdc74..8c3bc729 100644 --- a/test/specs/field_alias.spec.js +++ b/test/specs/field_alias.spec.js @@ -1,6 +1,7 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; // Create a schema @@ -31,7 +32,7 @@ describe('field alias', () => { describe('get - SELECT', () => { it('should map field aliases defined in the schema into SELECT requests Fields and Filters', async () => { - let _sql; + let _sql = ''; // Stub the execute function dare.sql = ({sql}) => { @@ -99,33 +100,33 @@ describe('field alias', () => { }); // Field alias - expect(_sql).to.contain('email AS "emailAddress"'); - expect(_sql).to.contain('email AS "field"'); - expect(_sql).to.contain('LOWER(a.email) AS "emailaddress"'); + assert.ok(_sql.includes('email AS "emailAddress"')); + assert.ok(_sql.includes('email AS "field"')); + assert.ok(_sql.includes('LOWER(a.email) AS "emailaddress"')); // Field SQL Alias - expect(_sql).to.contain('!ISNULL(a.email) AS "hasEmail"'); - expect(_sql).to.contain('!ISNULL(a.email) AS "alternateHasEmail"'); - expect(_sql).to.contain( + assert.ok(_sql.includes('!ISNULL(a.email) AS "hasEmail"')); + assert.ok(_sql.includes('!ISNULL(a.email) AS "alternateHasEmail"')); + assert(_sql.includes( 'IF(!ISNULL(a.email), "YES", "NO") AS "yesNoEmail"' - ); + )); // Standard - expect(_sql).to.contain(',a.country_id'); + assert.ok(_sql.includes(',a.country_id')); // Filter - expect(_sql).to.contain('email LIKE ?'); - expect(_sql).to.contain('!ISNULL(a.email) = ?'); - expect(_sql).to.contain('country_id = ?'); + assert.ok(_sql.includes('email LIKE ?')); + assert.ok(_sql.includes('!ISNULL(a.email) = ?')); + assert.ok(_sql.includes('country_id = ?')); // Join - expect(_sql).to.contain('email IS NOT NULL'); - expect(_sql).to.contain('!ISNULL(a.email) != ?'); - expect(_sql).to.contain('country_id IS NOT NULL'); + assert.ok(_sql.includes('email IS NOT NULL')); + assert.ok(_sql.includes('!ISNULL(a.email) != ?')); + assert.ok(_sql.includes('country_id IS NOT NULL')); }); it('cross table alias referencing', async () => { - let _sql; + let _sql = ''; // Stub the execute function dare.sql = ({sql}) => { @@ -181,26 +182,26 @@ describe('field alias', () => { limit, }); - expect(_sql).to.contain('email AS "Email Field"'); - expect(_sql).to.contain('email AS "Email Alias"'); - expect(_sql).to.contain('LOWER(b.email) AS "email_field"'); - expect(_sql).to.contain('LOWER(b.email) AS "email_alias"'); + assert.ok(_sql.includes('email AS "Email Field"')); + assert.ok(_sql.includes('email AS "Email Alias"')); + assert.ok(_sql.includes('LOWER(b.email) AS "email_field"')); + assert.ok(_sql.includes('LOWER(b.email) AS "email_alias"')); - expect(_sql).to.contain( + assert(_sql.includes( 'IF(!ISNULL(b.email), "Yes", "No") AS "Has Email alias"' - ); + )); - expect(_sql).to.contain('email LIKE ?'); - expect(_sql).to.contain('!ISNULL(b.email) = ?'); - expect(_sql).to.contain('country_id = ?'); - expect(_sql).to.contain('email IS NOT NULL'); - expect(_sql).to.contain('country_id IS NOT NULL'); + assert.ok(_sql.includes('email LIKE ?')); + assert.ok(_sql.includes('!ISNULL(b.email) = ?')); + assert.ok(_sql.includes('country_id = ?')); + assert.ok(_sql.includes('email IS NOT NULL')); + assert.ok(_sql.includes('country_id IS NOT NULL')); }); }); describe('patch - UPDATE', () => { it('should map field aliases defined in the schema into UPDATE filters', async () => { - let _sql; + let _sql = ''; // Stub the execute function dare.sql = ({sql}) => { @@ -226,10 +227,10 @@ describe('field alias', () => { }, }); - expect(_sql).to.contain('`email` = ?'); - expect(_sql).to.contain('`country_id` = ?'); - expect(_sql).to.contain('email LIKE ?'); - expect(_sql).to.contain('!ISNULL(a.email) = ?'); + assert.ok(_sql.includes('`email` = ?')); + assert.ok(_sql.includes('`country_id` = ?')); + assert.ok(_sql.includes('email LIKE ?')); + assert.ok(_sql.includes('!ISNULL(a.email) = ?')); }); it('should throw an error trying to patch a SQL Alias', async () => { @@ -244,15 +245,17 @@ describe('field alias', () => { }, }); - await expect(patch) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(patch, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); }); describe('del - DELETE', () => { it('should map field aliases defined in the schema into DELETE filters', async () => { - let _sql; + let _sql = ''; // Stub the execute function dare.sql = ({sql}) => { @@ -274,15 +277,15 @@ describe('field alias', () => { }, }); - expect(_sql).to.contain('users.email LIKE ?'); - expect(_sql).to.contain('!ISNULL(users.email) = ?'); - expect(_sql).to.contain('users.country_id = ?'); + assert.ok(_sql.includes('users.email LIKE ?')); + assert.ok(_sql.includes('!ISNULL(users.email) = ?')); + assert.ok(_sql.includes('users.country_id = ?')); }); }); describe('post - INSERT', () => { it('should map field aliases defined in the schema into INSERT body', async () => { - let _sql; + let _sql = ''; // Stub the execute function dare.sql = ({sql}) => { @@ -304,11 +307,11 @@ describe('field alias', () => { duplicate_keys_update: ['emailAddress', 'country_id'], }); - expect(_sql).to.contain('(`email`,`country_id`)'); + assert.ok(_sql.includes('(`email`,`country_id`)')); // ON DUPLICATE KEY UPDATE - expect(_sql).to.contain('`email`=VALUES(`email`)'); - expect(_sql).to.contain('`country_id`=VALUES(`country_id`)'); + assert.ok(_sql.includes('`email`=VALUES(`email`)')); + assert.ok(_sql.includes('`country_id`=VALUES(`country_id`)')); }); it('should throw an error trying to post to a SQL Alias field', async () => { @@ -320,9 +323,11 @@ describe('field alias', () => { }, }); - await expect(post) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(post, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); }); }); diff --git a/test/specs/field_format.spec.js b/test/specs/field_format.spec.js index 4677b820..e6d3661c 100644 --- a/test/specs/field_format.spec.js +++ b/test/specs/field_format.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset */ import field_format from '../../src/utils/field_format.js'; +import {describe, it} from 'node:test'; describe('utils/field_format', () => { // Should unwrap SQL Formating to underlying column name @@ -62,12 +63,12 @@ describe('utils/field_format', () => { // Expect const expected = test[1]; - it(`where ${input} => ${expected}`, () => { + it(`where ${input} => ${expected}`, async () => { // Call the field with the const actual = field_format(...input); // Expect the formatted list of fields to be identical to the inputted value - expect(actual).to.eql({ + assert.deepStrictEqual(actual, { expression: expected[0], label: expected[1] || undefined, agg: expected[2] || false, diff --git a/test/specs/field_reducer.spec.js b/test/specs/field_reducer.spec.js index ccdc59b4..e5af48d8 100644 --- a/test/specs/field_reducer.spec.js +++ b/test/specs/field_reducer.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset */ import field_reducer from '../../src/format/field_reducer.js'; +import {describe, it, beforeEach} from 'node:test'; describe('Field Reducer', () => { let dareInstance; @@ -202,21 +203,21 @@ describe('Field Reducer', () => { const f = input.reduce(fr, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f).to.eql(expected); + assert.deepStrictEqual(f, expected); if (expect_join_fields) { - expect(joined.b_table.fields).to.eql(expect_join_fields); + assert.deepStrictEqual(joined.b_table.fields, expect_join_fields); } else { - expect(joined).to.not.have.property('b_table'); + assert.ok(!('b_table' in joined)); } }); }); }); - it('should return generated fields', () => { + it('should return generated fields', async () => { const table_schema = { generated_field() { - expect(this).to.be.equal(dareInstance); + assert.strictEqual(this, dareInstance); return 'another_field'; }, }; @@ -237,10 +238,10 @@ describe('Field Reducer', () => { const f = ['generated_field'].reduce(fr, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f[0]).to.have.property('generated_field', 'another_field'); + assert.strictEqual(f[0].generated_field, 'another_field'); }); - it('should format datetime fields', () => { + it('should format datetime fields', async () => { const table_schema = { created: { type: 'datetime', @@ -263,13 +264,11 @@ describe('Field Reducer', () => { const f = ['created'].reduce(fr, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f[0]).to.have.property( - 'created', - "DATE_FORMAT(created,'%Y-%m-%dT%TZ')" - ); + assert('created' in f[0]); + assert.strictEqual(f[0].created, "DATE_FORMAT(created,'%Y-%m-%dT%TZ')"); }); - it('should format type=json fields', () => { + it('should format type=json fields', async () => { const table_schema = { meta: { type: 'json', @@ -292,21 +291,19 @@ describe('Field Reducer', () => { const f = ['meta'].reduce(fr, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f[0]).to.equal('meta'); + assert.strictEqual(f[0], 'meta'); const [postProcessing] = dareInstance.generated_fields; - expect(postProcessing).to.be.a('object'); + assert.strictEqual(typeof postProcessing, "object"); - expect(postProcessing).to.have.property('label', 'meta'); - expect(postProcessing).to.have.property( - 'field_alias_path', - field_alias_path - ); - expect(postProcessing).to.have.property('handler'); + assert.strictEqual(postProcessing.label, 'meta'); + assert('field_alias_path' in postProcessing); + assert.strictEqual(postProcessing.field_alias_path, field_alias_path); + assert.ok('handler' in postProcessing); }); - it('should format aliased fields', () => { + it('should format aliased fields', async () => { const table_schema = { fieldAlias: 'field', }; @@ -331,6 +328,6 @@ describe('Field Reducer', () => { ].reduce(fr, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f[0]).to.have.property('Label Alias', 'joinTable.field'); + assert.strictEqual(f[0]['Label Alias'], 'joinTable.field'); }); }); diff --git a/test/specs/filter_reducer.spec.js b/test/specs/filter_reducer.spec.js index 9da934cb..f17a3c07 100644 --- a/test/specs/filter_reducer.spec.js +++ b/test/specs/filter_reducer.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; /* @@ -7,6 +7,7 @@ import Dare from '../../src/index.js'; */ import reduceConditions from '../../src/format/reducer_conditions.js'; +import {describe, it, beforeEach} from 'node:test'; describe('Filter Reducer', () => { let dareInstance; @@ -158,11 +159,11 @@ describe('Filter Reducer', () => { dareInstance, }); - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); // Should not mutate the filters... - expect(filter).to.deep.eql(filter_cloned); + assert.deepStrictEqual(filter, filter_cloned); }); }); }); @@ -195,8 +196,8 @@ describe('Filter Reducer', () => { dareInstance: dareInst, }); - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); }); }); @@ -204,7 +205,7 @@ describe('Filter Reducer', () => { describe('postgres engine version handling', () => { const engine = 'postgres:16.3'; - it('should search fulltext - with an index', () => { + it('should search fulltext - with an index', async () => { const dareInst = dareInstance.use({engine}); const filter = { @@ -222,11 +223,11 @@ describe('Filter Reducer', () => { dareInstance: dareInst, }); - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); - it('should search fulltext - and build an index', () => { + it('should search fulltext - and build an index', async () => { const dareInst = dareInstance.use({engine}); const filter = { @@ -244,11 +245,11 @@ describe('Filter Reducer', () => { dareInstance: dareInst, }); - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); - it(`quote json number and boolean values`, () => { + it(`quote json number and boolean values`, () => { const dareInst = dareInstance.use({engine}); const filter = { @@ -269,8 +270,8 @@ describe('Filter Reducer', () => { const sql = `(a.jsonSettings->>? = ? AND a.jsonSettings->>? ILIKE ?)`; const values = ['key', '1', 'str', 'string%']; - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); }); }); diff --git a/test/specs/format_request.spec.js b/test/specs/format_request.spec.js index 55f62fd1..ce56281d 100644 --- a/test/specs/format_request.spec.js +++ b/test/specs/format_request.spec.js @@ -1,6 +1,5 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import SQL from 'sql-template-tag'; -import assert from 'node:assert/strict'; import Dare from '../../src/index.js'; /* * Format Request @@ -8,6 +7,7 @@ import Dare from '../../src/index.js'; */ import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; describe('format_request', () => { let dare; @@ -23,18 +23,20 @@ describe('format_request', () => { }); }); - it('should be defined in instances of Dare', () => { - expect(dare).to.have.property('format_request'); + it('should be defined in instances of Dare', async () => { + assert.ok('format_request' in dare); }); - it('should require arguments and return a promise', () => { + it('should require arguments and return a promise', async () => { const fn = dare.format_request(); - expect(fn).to.have.property('then'); + assert.ok('then' in fn); - return expect(fn) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(fn, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); it('should return a structure with default values', async () => { @@ -114,12 +116,14 @@ describe('format_request', () => { [{'tablename with spaces and -:*...': ['id']}], [{asset: ['DATE(id)']}], ].forEach(fields => { - it(`invalid: ${JSON.stringify(fields)}`, () => { + it(`invalid: ${JSON.stringify(fields)}`, async () => { const test = dare.format_request({...options, fields}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REFERENCE); + return true; + }); }); }); }); @@ -141,7 +145,7 @@ describe('format_request', () => { it(`where ${JSON.stringify(fields)}`, async () => { const req = await dare.format_request({...options, fields}); - expect(req._joins[0]).to.have.property('alias', 'asset'); + assert.strictEqual(req._joins[0].alias, 'asset'); }); }); }); @@ -163,12 +167,14 @@ describe('format_request', () => { describe('should throw an exception', () => { ['nonsense', 0, -1, NaN, {}, null].forEach(limit => { - it(`invalid: ${limit} (${typeof limit})`, () => { + it(`invalid: ${limit} (${typeof limit})`, async () => { const test = dare.format_request({...options, limit}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_LIMIT); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_LIMIT); + return true; + }); }); }); }); @@ -180,26 +186,28 @@ describe('format_request', () => { // Create another instance const _dare = dare.use(); - expect(dare.MAX_LIMIT).to.eql(null); - expect(_dare.MAX_LIMIT).to.eql(null); + assert.strictEqual(dare.MAX_LIMIT, null); + assert.strictEqual(_dare.MAX_LIMIT, null); // Update instance length _dare.MAX_LIMIT = limit; - expect(dare.MAX_LIMIT).to.eql(null); - expect(_dare.MAX_LIMIT).to.eql(limit); + assert.strictEqual(dare.MAX_LIMIT, null); + assert.strictEqual(_dare.MAX_LIMIT, limit); return _dare.format_request({...options, limit}); }); - it('should throw an DareError if limit is above MAX_LIMIT', () => { + it('should throw an DareError if limit is above MAX_LIMIT', async () => { // Update the length dare.MAX_LIMIT = limit - 1; const test = dare.format_request({...options, limit}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_LIMIT); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_LIMIT); + return true; + }); }); }); }); @@ -214,12 +222,14 @@ describe('format_request', () => { describe('should ignore', () => { ['nonsense', -1, NaN, {}].forEach(start => { - it(`invalid: ${start} (${typeof start})`, () => { + it(`invalid: ${start} (${typeof start})`, async () => { const test = dare.format_request({...options, start}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_START); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_START); + return true; + }); }); }); }); @@ -240,7 +250,7 @@ describe('format_request', () => { groupby, }); - expect(resp.groupby).to.eql([groupby]); + assert.deepStrictEqual(resp.groupby, [groupby]); }); }); }); @@ -248,19 +258,18 @@ describe('format_request', () => { describe('should throw an DareError, when:', () => { [-1, 101, {}, 'parenthisis(snap', '; ', 'SUM(SE-LECT 1)'].forEach( groupby => { - it(`invalid: ${groupby} (${typeof groupby})`, () => { + it(`invalid: ${groupby} (${typeof groupby})`, async () => { const test = dare.format_request({ table: 'table', fields: ['id'], groupby, }); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property( - 'code', - DareError.INVALID_REFERENCE - ); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REFERENCE); + return true; + }); }); } ); @@ -310,16 +319,18 @@ describe('format_request', () => { ['name', 1], ['name ASC', 'id WEST'], ].forEach(orderby => { - it(`invalid: ${orderby} (${typeof orderby})`, () => { + it(`invalid: ${orderby} (${typeof orderby})`, async () => { const test = dare.format_request({ table: 'table', fields: ['id'], orderby, }); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REFERENCE); + return true; + }); }); }); }); @@ -503,11 +514,11 @@ describe('format_request', () => { const query = resp.sql_where_conditions[0]; - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); // Should not mutate the filters... - expect(filter).to.deep.eql(filter_cloned); + assert.deepStrictEqual(filter, filter_cloned); }); }); }); @@ -529,19 +540,18 @@ describe('format_request', () => { }, }, ].forEach(filter => { - it(`invalid: ${JSON.stringify(filter)}`, () => { + it(`invalid: ${JSON.stringify(filter)}`, async () => { const test = dare.format_request({ table: 'activityEvents', fields: ['id'], [condition_type]: filter, }); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property( - 'code', - DareError.INVALID_REFERENCE - ); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REFERENCE); + return true; + }); }); }); }); @@ -590,8 +600,8 @@ describe('format_request', () => { const query = resp.sql_where_conditions[0]; - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); } }); @@ -613,8 +623,8 @@ describe('format_request', () => { const query = resp.sql_where_conditions[0]; - expect(query.sql).to.equal(sql); - expect(query.values).to.deep.equal(values); + assert.strictEqual(query.sql, sql); + assert.deepStrictEqual(query.values, values); }); }); }); @@ -622,7 +632,7 @@ describe('format_request', () => { }); describe('scheme', () => { - it('should throw an DareError when there are two tables with an undefined relationship', () => { + it('should throw an DareError when there are two tables with an undefined relationship', async () => { // Redefine the structure dare.options = { models: { @@ -646,12 +656,12 @@ describe('format_request', () => { ], }); - return expect(test) - .to.be.eventually.rejectedWith( - DareError, - "Could not understand field 'comments'" - ) - .and.have.property('code', DareError.INVALID_REFERENCE); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.message, "Could not understand field 'comments'"); + assert.strictEqual(error.code, DareError.INVALID_REFERENCE); + return true; + }); }); it('should understand options.schema which defines table structure which reference other tables.', async () => { @@ -772,7 +782,7 @@ describe('format_request', () => { fields: ['name'], }); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); it('should pass through the table scoped request', async () => { @@ -794,7 +804,7 @@ describe('format_request', () => { fields: ['name'], }); - expect(options.filter).to.eql({is_deleted: false}); + assert.deepStrictEqual(options.filter, {is_deleted: false}); }); it('should append parent and state through the table scoped request', async () => { @@ -855,11 +865,11 @@ describe('format_request', () => { fields: ['name'], }); - expect(comments.filter).to.eql({users: removed}); - assert.strictEqual(comments.state, state); + assert.deepStrictEqual(comments.filter, {users: removed}); + assert.deepStrictEqual(comments.state, state); // Check the joins include the state too - assert.strictEqual(comments._joins.at(0).state, state); + assert.deepStrictEqual(comments._joins.at(0).state, state); /* * Test 2 @@ -877,7 +887,7 @@ describe('format_request', () => { const commentsJoin = users._joins[0]; - expect(commentsJoin).to.not.have.property('filter'); + assert.ok(!('filter' in commentsJoin)); }); it('should allow nested children to assign filters', async () => { @@ -916,7 +926,7 @@ describe('format_request', () => { assert.deepStrictEqual(comments._joins.at(0).filter, removed); }); - it('should await the response from a promise', () => { + it('should await the response from a promise', async () => { const msg = 'snap'; dare.options.method = method; dare.options.models = { @@ -935,10 +945,10 @@ describe('format_request', () => { fields: ['name'], }); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); - it('should provide the instance of dare in the request', () => { + it('should provide the instance of dare in the request', async () => { let dareInstance; let that; @@ -958,8 +968,8 @@ describe('format_request', () => { fields: ['name'], }); - expect(dareInstance).to.equal(dare); - expect(that).to.equal(dare); + assert.strictEqual(dareInstance, dare); + assert.strictEqual(that, dare); }); }); }); diff --git a/test/specs/fulltext_parser.spec.js b/test/specs/fulltext_parser.spec.js index 2caaf2a7..81723ef3 100644 --- a/test/specs/fulltext_parser.spec.js +++ b/test/specs/fulltext_parser.spec.js @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import Dare from '../../src/index.js'; +import {describe, it} from 'node:test'; /** * @import {Engine} from '../../src/index.js' diff --git a/test/specs/get-datatypes.spec.js b/test/specs/get-datatypes.spec.js index 8c0fac97..22a77428 100644 --- a/test/specs/get-datatypes.spec.js +++ b/test/specs/get-datatypes.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions @@ -6,6 +6,7 @@ import sqlEqual from '../lib/sql-equal.js'; // Create a schema import options from '../data/options.js'; +import {describe, it, beforeEach} from 'node:test'; describe('get - datatypes', () => { let dare; @@ -28,7 +29,7 @@ describe('get - datatypes', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{created_time}]; }; @@ -38,7 +39,7 @@ describe('get - datatypes', () => { fields: ['created_time'], }); - expect(resp).to.have.property('created_time', created_time); + assert.strictEqual(resp.created_time, created_time); }); describe('type=json', () => { @@ -54,7 +55,7 @@ describe('get - datatypes', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{settings: metaString}]; }; @@ -64,7 +65,8 @@ describe('get - datatypes', () => { fields: ['settings'], }); - expect(resp).to.have.property('settings').to.deep.equal(settings); + assert('settings' in resp); + assert.deepStrictEqual(resp.settings, settings); }); it('should JSON parse a nested field with object if type=json', async () => { @@ -80,7 +82,7 @@ describe('get - datatypes', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{users: {settings: metaString}}]; }; @@ -94,10 +96,9 @@ describe('get - datatypes', () => { ], }); - expect(resp) - .to.have.property('users') - .to.have.property('settings') - .to.deep.equal(settings); + assert('users' in resp); + assert('settings' in resp.users); + assert.deepStrictEqual(resp.users.settings, settings); }); it('should return an empty object if response value is falsy', async () => { @@ -109,7 +110,7 @@ describe('get - datatypes', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{meta: null}]; }; @@ -119,7 +120,8 @@ describe('get - datatypes', () => { fields: ['settings'], }); - expect(resp).to.have.property('settings').to.deep.equal({}); + assert('settings' in resp); + assert.deepStrictEqual(resp.settings, {}); }); }); @@ -136,7 +138,7 @@ describe('get - datatypes', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{users: {id}}]; }; @@ -154,9 +156,8 @@ describe('get - datatypes', () => { ], }); - expect(resp) - .to.have.property('users') - .to.have.property('URL', `/user/${id}`); + assert('users' in resp); + assert.strictEqual(resp.users.URL, `/user/${id}`); }); }); }); diff --git a/test/specs/get-join.spec.js b/test/specs/get-join.spec.js index f5adc527..46d1ff94 100644 --- a/test/specs/get-join.spec.js +++ b/test/specs/get-join.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions @@ -6,6 +6,7 @@ import expectSQLEqual from '../lib/sql-equal.js'; // Create a schema import options from '../data/options.js'; +import {describe, it, beforeEach} from 'node:test'; // Walk function walk(obj, handler, key = null) { @@ -26,8 +27,8 @@ describe('get - request object', () => { dare = new Dare(options); }); - it('should contain the function dare.get', () => { - expect(dare.get).to.be.a('function'); + it('should contain the function dare.get', async () => { + assert.strictEqual(typeof dare.get, 'function'); }); it('should generate a SELECT statement and execute dare.sql', async () => { @@ -109,11 +110,11 @@ describe('get - request object', () => { limit, }); - expect(resp).to.be.an('array'); - expect(resp.length).to.eql(1); + assert.ok(Array.isArray(resp)); + assert.strictEqual(resp.length, 1); const item = resp[0]; - expect(item).to.have.property('name'); - expect(item.asset).to.have.property('name', 2001); + assert.ok('name' in item); + assert.strictEqual(item.asset.name, 2001); }); it('should respond with the same structure as the request.fields', async () => { @@ -143,14 +144,14 @@ describe('get - request object', () => { limit, }); - expect(resp).to.be.an('array'); + assert.ok(Array.isArray(resp)); }); it('should allow multiple definitions of the same thing', async () => { dare.sql = async ({sql}) => { const key = 'email1,users_email.email,users_email.emailnest'; - expect(sql).to.contain(key); + assert.ok(sql.includes(key)); return [ { @@ -179,9 +180,9 @@ describe('get - request object', () => { ], }); - expect(res).to.have.property('email1'); - expect(res.users_email).to.have.property('email'); - expect(res.users_email).to.have.property('emailnest'); + assert.ok('email1' in res); + assert.ok('email' in res.users_email); + assert.ok('emailnest' in res.users_email); }); }); @@ -200,8 +201,8 @@ describe('get - request object', () => { it(`valid: ${JSON.stringify(value)}`, async () => { dare.sql = ({sql, values}) => { walk(value, (value, key) => { - expect(sql).to.contain(key); - expect(values).to.contain(value); + assert.ok(sql.includes(key)); + assert.ok(values.includes(value)); }); return Promise.resolve([]); @@ -218,10 +219,10 @@ describe('get - request object', () => { it('valid: shorthand nested filter keys', async () => { dare.sql = ({sql, values}) => { - expect(sql).to.contain('.type = ?'); - expect(sql).to.contain('.name != ?'); - expect(values).to.contain('mobile'); - expect(values).to.contain('me'); + assert.ok(sql.includes('.type = ?')); + assert.ok(sql.includes('.name != ?')); + assert.ok(values.includes('mobile')); + assert.ok(values.includes('me')); return Promise.resolve([]); }; @@ -254,7 +255,7 @@ describe('get - request object', () => { LIMIT 5` ); - expect(values).to.deep.equal([1, 3, 2]); + assert.deepStrictEqual(values, [1, 3, 2]); return Promise.resolve([]); }; @@ -337,7 +338,7 @@ describe('get - request object', () => { it(`valid: ${JSON.stringify(test.join)}`, async () => { dare.sql = ({sql, values}) => { - expect(values).to.deep.equal([type]); + assert.deepStrictEqual(values, [type]); expectSQLEqual(sql, expected); @@ -568,7 +569,7 @@ describe('get - request object', () => { }, }); - expect(resp).to.deep.equal({ + assert.deepStrictEqual(resp, { name: 'Andrew', thumbnail: '/asset/1/thumbnail', url: '/asset/1/url', @@ -604,7 +605,7 @@ describe('get - request object', () => { }, }); - expect(resp).to.deep.equal({ + assert.deepStrictEqual(resp, { name: 'Andrew', thumbnail: '/asset/1/thumbnail', pictureUrl: 'http://example.com/picture/100/image', diff --git a/test/specs/get-sort-group.spec.js b/test/specs/get-sort-group.spec.js index c5436c25..7719759f 100644 --- a/test/specs/get-sort-group.spec.js +++ b/test/specs/get-sort-group.spec.js @@ -4,6 +4,7 @@ import options from '../data/options.js'; // Test Generic DB functions import expectSQLEqual from '../lib/sql-equal.js'; +import {describe, it, beforeEach} from 'node:test'; const limit = 5; diff --git a/test/specs/get-subquery.spec.js b/test/specs/get-subquery.spec.js index 532c1bb7..208dc72a 100644 --- a/test/specs/get-subquery.spec.js +++ b/test/specs/get-subquery.spec.js @@ -1,8 +1,9 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions import expectSQLEqual from '../lib/sql-equal.js'; +import {describe, it, beforeEach} from 'node:test'; // Dare instance let dare; @@ -72,8 +73,8 @@ describe('get - subquery', () => { }, }); - expect(resp).to.have.property('asset_name', 'name'); - expect(resp).to.have.property('collection_count', 42); + assert.strictEqual(resp.asset_name, 'name'); + assert.strictEqual(resp.collection_count, 42); }); it('should export the response in the format given', async () => { @@ -116,7 +117,7 @@ describe('get - subquery', () => { }, }); - expect(resp.collections).to.have.property('count', 42); + assert.strictEqual(resp.collections.count, 42); }); it('should concatinate many expressions into an array using JSON_ARRAYAGG', async () => { @@ -155,9 +156,9 @@ describe('get - subquery', () => { }, }); - expect(resp.collections).to.be.an('array'); - expect(resp.collections[0]).to.have.property('id', '1'); - expect(resp.collections[0]).to.have.property('name', 'a'); + assert.ok(Array.isArray(resp.collections)); + assert.strictEqual(resp.collections[0].id, '1'); + assert.strictEqual(resp.collections[0].name, 'a'); }); it('should concatinate many expressions into an array using JSON_ARRAYAGG', async () => { @@ -200,9 +201,9 @@ describe('get - subquery', () => { }, }); - expect(resp.assetCollections).to.be.an('array'); - expect(resp.assetCollections[0]).to.have.property('id', '1'); - expect(resp.assetCollections[0]).to.have.property('color', 'red'); + assert.ok(Array.isArray(resp.assetCollections)); + assert.strictEqual(resp.assetCollections[0].id, '1'); + assert.strictEqual(resp.assetCollections[0].color, 'red'); }); it('should *not* subquery a nested object without fields', async () => { @@ -235,7 +236,7 @@ describe('get - subquery', () => { }, }); - expect(resp).to.have.property('asset_name', 'name'); + assert.strictEqual(resp.asset_name, 'name'); }); it('should *not* use a subquery when the many table is used in the filter', async () => { @@ -357,7 +358,7 @@ describe('get - subquery', () => { describe('with groupby', () => { it('should allow multiple groupby on nested tables', async () => { dare.sql = async ({sql}) => { - expect(sql).to.contain('GROUP BY c.id,a.id'); + assert.ok(sql.includes('GROUP BY c.id,a.id')); return [ { @@ -436,7 +437,7 @@ describe('get - subquery', () => { }; dareInst.sql = async ({sql}) => { - expect(sql).to.not.contain('LIMIT 1'); + assert.ok(!sql.includes('LIMIT 1')); }; // Construct a query which counts these diff --git a/test/specs/get.spec.js b/test/specs/get.spec.js index 6c560ff1..580d4802 100644 --- a/test/specs/get.spec.js +++ b/test/specs/get.spec.js @@ -1,11 +1,11 @@ -import {expect} from 'chai'; -import assert from 'node:assert/strict'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions import sqlEqual from '../lib/sql-equal.js'; import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; const id = 1; @@ -19,8 +19,8 @@ describe('get', () => { }; }); - it('should contain the function dare.get', () => { - expect(dare.get).to.be.a('function'); + it('should contain the function dare.get', async () => { + assert.strictEqual(typeof dare.get, 'function'); }); it('should not mutate the request object', async () => { @@ -39,11 +39,11 @@ describe('get', () => { await dare.get(request); // Check shallow clone - expect(request).to.deep.equal(original); + assert.deepStrictEqual(request, original); // Check deep clone - expect(request).to.have.deep.property('fields', ['id', 'name']); - expect(request).to.have.deep.property('orderby', ['name']); + assert.deepStrictEqual(request.fields, ['id', 'name']); + assert.deepStrictEqual(request.orderby, ['name']); }); it('should throw an error if table is empty', async () => { @@ -53,12 +53,11 @@ describe('get', () => { const call = dare.get(request); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - '`table` option is undefined' - ) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(call, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); describe('Simple arguments', () => { @@ -80,15 +79,15 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; const resp = await dare.get('test', basic_fields, {id}); - expect(resp).to.be.a('object'); - expect(resp).to.eql(basic_record); + assert.strictEqual(typeof resp, "object"); + assert.deepStrictEqual(resp, basic_record); }); it('should create a query with fields', async () => { @@ -97,14 +96,14 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; const resp = await dare.get('test', basic_fields, {id}); - expect(resp).to.eql(basic_record); + assert.deepStrictEqual(resp, basic_record); }); it('should support array of value in the query condition', async () => { @@ -127,9 +126,9 @@ describe('get', () => { {limit: 2} ); - expect(resp).to.be.a('array'); - expect(resp.length).to.eql(2); - expect(resp[0]).to.eql(basic_record); + assert(Array.isArray(resp)); + assert.strictEqual(resp.length, 2); + assert.deepStrictEqual(resp[0], basic_record); }); it('should support wildcard characters for pattern matching', async () => { @@ -139,7 +138,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.name LIKE ? LIMIT 5' ); - expect(values).to.deep.equal([name]); + assert.deepStrictEqual(values, [name]); return [basic_record, basic_record]; }; @@ -151,7 +150,7 @@ describe('get', () => { {limit: 5} ); - expect(resp).to.be.a('array'); + assert(Array.isArray(resp)); }); it('should ignore $suffixing', async () => { @@ -162,7 +161,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name, a.prop FROM test a WHERE a.name LIKE ? AND a.name LIKE ? LIMIT 5' ); - expect(values).to.deep.equal([name, name$and]); + assert.deepStrictEqual(values, [name, name$and]); return [basic_record, basic_record]; }; @@ -174,7 +173,7 @@ describe('get', () => { {limit: 5} ); - expect(resp).to.be.a('array'); + assert(Array.isArray(resp)); }); it('should have an overidable limit', async () => { @@ -183,14 +182,14 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? LIMIT 5' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; const resp = await dare.get('test', basic_fields, {id}, {limit: 5}); - expect(resp).to.be.a('array'); - expect(resp).to.eql([basic_record]); + assert(Array.isArray(resp)); + assert.deepStrictEqual(resp, [basic_record]); }); it('should have an overidable limit and start', async () => { @@ -199,7 +198,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? LIMIT 5 OFFSET 4' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; @@ -209,34 +208,36 @@ describe('get', () => { {id}, {limit: 5, start: 4} ); - expect(resp).to.be.a('array'); - expect(resp).to.eql([basic_record]); + assert(Array.isArray(resp)); + assert.deepStrictEqual(resp, [basic_record]); }); - it('should throw an error if limit is invalid', () => { + it('should throw an error if limit is invalid', async () => { const test = dare.get('test', basic_fields, {id}, {limit: 0}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_LIMIT); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_LIMIT); return true; }); }); - it('should throw an error if limit is invalid', () => { + it('should throw an error if limit is invalid', async () => { const test = dare.get('test', basic_fields, {id}, {limit: null}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_LIMIT); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_LIMIT); return true; }); }); - it('should throw an error where no limit was defined and an empty resultset was returned.', () => { + it('should throw an error where no limit was defined and an empty resultset was returned.', async () => { dare.execute = async () => []; const test = dare.get('test', basic_fields, {id}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.NOT_FOUND); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.NOT_FOUND); + return true; + }); }); it('should return value of notfound where no limit was defined and an empty resultset was returned.', async () => { @@ -251,7 +252,7 @@ describe('get', () => { {notfound} ); - expect(value).to.equal(notfound); + assert.strictEqual(value, notfound); }); it('should passthrough an orderby', async () => { @@ -260,7 +261,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? ORDER BY a.id LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; @@ -274,7 +275,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? ORDER BY a.id LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; @@ -288,7 +289,7 @@ describe('get', () => { sql, 'SELECT a.id, a.name FROM test a WHERE a.id = ? ORDER BY a.id DESC LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; @@ -305,7 +306,7 @@ describe('get', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{_count: 10}]; }; @@ -317,7 +318,7 @@ describe('get', () => { {orderby: 'date'} ); - expect(resp).to.eql({_count: 10}); + assert.deepStrictEqual(resp, {_count: 10}); }); it('should use functions in the orderby', async () => { @@ -330,7 +331,7 @@ describe('get', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{_count: 10}]; }; @@ -342,23 +343,25 @@ describe('get', () => { {orderby: 'DATE(created)'} ); - expect(resp).to.eql({_count: 10}); + assert.deepStrictEqual(resp, {_count: 10}); }); - it('should throw an error if fields is an empty array', () => { + it('should throw an error if fields is an empty array', async () => { const test = dare.get('test', [], {id}, {groupby: 'id'}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); - it('should throw an error if fields are a scalar value', () => { + it('should throw an error if fields are a scalar value', async () => { const test = dare.get('test', true, {id}, {groupby: 'id'}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); return true; }); }); it('should let us pass through SQL Functions', async () => { @@ -367,7 +370,7 @@ describe('get', () => { sql, 'SELECT count(a.*) AS "_count" FROM test a WHERE a.id = ? GROUP BY a.name LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [{id}]; }; @@ -378,7 +381,7 @@ describe('get', () => { {groupby: 'name'} ); - expect(resp).to.eql({id}); + assert.deepStrictEqual(resp, {id}); }); it('should interpret _count as COUNT(*)', async () => { @@ -390,14 +393,14 @@ describe('get', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{_count: 10}]; }; const resp = await dare.get('test', ['_count']); - expect(resp).to.eql({_count: 10}); + assert.deepStrictEqual(resp, {_count: 10}); }); it('should use the special field _count as a label for orderby reference', async () => { @@ -410,7 +413,7 @@ describe('get', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{_count: 10}]; }; @@ -419,7 +422,7 @@ describe('get', () => { orderby: '_count', }); - expect(resp).to.eql({_count: 10}); + assert.deepStrictEqual(resp, {_count: 10}); }); it('should interpret _group as a shortcut to the groupby', async () => { @@ -432,7 +435,7 @@ describe('get', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{_count: 10}]; }; @@ -443,7 +446,7 @@ describe('get', () => { groupby: 'DATE(created_time)', }); - expect(resp).to.eql({_count: 10}); + assert.deepStrictEqual(resp, {_count: 10}); }); }); @@ -475,15 +478,15 @@ describe('get', () => { SELECT 100 AS "show_100", null AS "show_null", "Text string 123" AS "show_text", CONCAT("Hello", "World") AS "show_function_text", a.name AS "name" FROM test a WHERE a.id = ? LIMIT 1 ` ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [basic_record]; }; const resp = await dare.get('test', basic_fields, {id}); - expect(resp).to.be.a('object'); - expect(resp).to.eql(basic_record); + assert.strictEqual(typeof resp, "object"); + assert.strictEqual(resp, basic_record); }); }); @@ -500,8 +503,8 @@ describe('get', () => { }, }); - expect(resp).to.have.property('name', 'Jupiter'); - expect(resp).to.have.property('age', 4); + assert.strictEqual(resp.name, 'Jupiter'); + assert.strictEqual(resp.age, 4); }); it('execute should be able to call addRow instead of returning an array', async () => { @@ -524,10 +527,10 @@ describe('get', () => { }, }); - expect(resp).to.equal(undefined); + assert.strictEqual(resp, undefined); - expect(data[0]).to.have.property('name', 'Jupiter'); - expect(data[0]).to.have.property('age', 4); + assert.strictEqual(data[0].name, 'Jupiter'); + assert.strictEqual(data[0].age, 4); }); }); diff --git a/test/specs/getCount.spec.js b/test/specs/getCount.spec.js index 9eacfbe9..0bfe3a06 100644 --- a/test/specs/getCount.spec.js +++ b/test/specs/getCount.spec.js @@ -1,8 +1,9 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions import sqlEqual from '../lib/sql-equal.js'; +import {describe, it, beforeEach} from 'node:test'; const id = 1; describe('getCount', () => { @@ -16,8 +17,8 @@ describe('getCount', () => { }; }); - it('should contain the function dare.getCount', () => { - expect(dare.getCount).to.be.a('function'); + it('should contain the function dare.getCount', async () => { + assert.strictEqual(typeof dare.getCount, 'function'); }); it('should generate a SELECT statement and execute dare.execute', async () => { @@ -26,13 +27,13 @@ describe('getCount', () => { sql, 'SELECT COUNT(DISTINCT a._rowid) AS "count" FROM test a WHERE a.id = ? LIMIT 1' ); - expect(values).to.deep.equal([id]); + assert.deepStrictEqual(values, [id]); return [{count}]; }; const resp = await dare.getCount('test', {id}); - expect(resp).to.eql(count); + assert.strictEqual(resp, count); }); it('should remove the groupby to the fields section', async () => { @@ -44,7 +45,7 @@ describe('getCount', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{count}]; }; @@ -55,7 +56,7 @@ describe('getCount', () => { groupby: 'DATE(created_time)', }); - expect(resp).to.eql(count); + assert.strictEqual(resp, count); }); it('should apply multiple groupby', async () => { @@ -67,7 +68,7 @@ describe('getCount', () => { `; sqlEqual(sql, expected); - expect(values).to.deep.equal([]); + assert.deepStrictEqual(values, []); return [{count}]; }; @@ -80,7 +81,7 @@ describe('getCount', () => { limit: 10, }); - expect(resp).to.eql(count); + assert.strictEqual(resp, count); }); it('should not mutate the request object', async () => { @@ -98,10 +99,10 @@ describe('getCount', () => { await dare.getCount(request); // Check shallow clone - expect(request).to.deep.equal(original); + assert.deepStrictEqual(request, original); // Check deep clone - expect(request).to.have.deep.property('fields', ['id', 'name']); - expect(request).to.have.deep.property('orderby', ['name']); + assert.deepStrictEqual(request.fields, ['id', 'name']); + assert.deepStrictEqual(request.orderby, ['name']); }); }); diff --git a/test/specs/get_unique_alias.spec.js b/test/specs/get_unique_alias.spec.js index 87995a41..37b6120d 100644 --- a/test/specs/get_unique_alias.spec.js +++ b/test/specs/get_unique_alias.spec.js @@ -1,17 +1,18 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; +import {describe, it} from 'node:test'; describe('get_unique_alias', () => { - it('should always return a unique alphabet character or a quoted value', () => { + it('should always return a unique alphabet character or a quoted value', async () => { const dare = new Dare(); for (let i = 0; i <= 26 * 26; i++) { const alias = dare.get_unique_alias(); - expect(alias).to.match(/^[a-z]|(?`)[a-z]{2,}\k$/); + assert.match(alias, /^[a-z]|(?`)[a-z]{2,}\k$/); } // Expect the next one to throw an error - expect(() => dare.get_unique_alias()).to.throw(); + assert.throws(() => dare.get_unique_alias()); }); }); diff --git a/test/specs/groupby_reducer.spec.js b/test/specs/groupby_reducer.spec.js index b5e6b7f4..e2d51875 100644 --- a/test/specs/groupby_reducer.spec.js +++ b/test/specs/groupby_reducer.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset */ import groupby_reducer from '../../src/format/groupby_reducer.js'; +import {describe, it} from 'node:test'; describe('Groupby Reducer', () => { describe('should split the current fields belonging to the current and joined tables', () => { @@ -42,12 +43,12 @@ describe('Groupby Reducer', () => { const f = input.reduce(reducer, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f).to.eql(expected); + assert.deepStrictEqual(f, expected); if (expect_join_fields) { - expect(joined.b_table.groupby).to.eql(expect_join_fields); + assert.deepStrictEqual(joined.b_table.groupby, expect_join_fields); } else { - expect(joined).to.not.have.property('b_table'); + assert.ok(!('b_table' in joined)); } }); }); diff --git a/test/specs/init.spec.js b/test/specs/init.spec.js index 56d6ceda..87f612ee 100644 --- a/test/specs/init.spec.js +++ b/test/specs/init.spec.js @@ -2,14 +2,15 @@ * @import {QueryOptions} from '../../src/index.js' */ -import {expect} from 'chai'; +import assert from 'node:assert'; +import {describe, it, beforeEach} from 'node:test'; import Dare, {DareError} from '../../src/index.js'; import clone from 'tricks/object/clone.js'; describe('Dare', () => { it('should be a constructor', () => { const dare = new Dare(); - expect(dare.constructor).to.eql(Dare); + assert.strictEqual(dare.constructor, Dare); }); it('should define default options', () => { @@ -19,19 +20,20 @@ describe('Dare', () => { const dare = new Dare({ models, }); - expect(dare.options).to.have.property('models', models); + assert.strictEqual(dare.options.models, models); }); it('should export the DareError object', () => { - expect(Dare.DareError).to.eql(DareError); + assert.strictEqual(Dare.DareError, DareError); }); - it('should throw errors if dare.execute is not defined', () => { + it('should throw errors if dare.execute is not defined', async () => { const dare = new Dare(); const test = dare.sql('SELECT 1=1'); - return expect(test).to.be.eventually.rejectedWith( + await assert.rejects( + test, DareError, 'Define dare.execute to continue' ); @@ -49,7 +51,7 @@ describe('Dare', () => { fields: ['name'], }); - expect(resp).to.have.property('name', 'Jupiter'); + assert.strictEqual(resp.name, 'Jupiter'); }); describe('dare.use to extend the instance', () => { @@ -84,14 +86,14 @@ describe('Dare', () => { }); // Check the child assigned new values - expect(dareChild.options).to.have.property('limit', 100); + assert.strictEqual(dareChild.options.limit, 100); // Check the child retains parent properties - expect(dareChild.options).to.have.property('models'); - expect(dareChild.execute).to.equal(dare.execute); + assert.ok('models' in dareChild.options); + assert.strictEqual(dareChild.execute, dare.execute); // Check the parent was not affected by the child configuration - expect(dare.options).to.not.have.property('limit'); + assert.ok(!('limit' in dare.options)); }); it('should inherit but not leak when extending schema', () => { @@ -117,20 +119,16 @@ describe('Dare', () => { const dare2 = dare.use(options2); // Should not share same objects as instance it extended - expect(dare.options.models.users).to.not.equal( - dare2.options.models.users - ); + assert.notStrictEqual(dare.options.models.users, dare2.options.models.users); // Should not mutate instance it extended - // eslint-disable-next-line no-unused-expressions - expect(dare.options.models.different).to.be.undefined; + + assert.strictEqual(dare.options.models.different, undefined); - expect(dare.options.models.users.schema.name.writable).to.not.equal( - dare2.options.models.users.schema.name.writable - ); + assert.notStrictEqual(dare.options.models.users.schema.name.writable, dare2.options.models.users.schema.name.writable); // Should merge settings for field definitiions... e.g. - expect(dare2.options.models.users.schema).to.deep.equal({ + assert.deepStrictEqual(dare2.options.models.users.schema, { name: { type: 'string', writable: false, @@ -138,10 +136,10 @@ describe('Dare', () => { }); // Should not mutate the inheritted options - expect(options).to.deep.equal(options_cloned); + assert.deepStrictEqual(options, options_cloned); // Should not mutate the new options input - expect(options2).to.deep.equal(options2_cloned); + assert.deepStrictEqual(options2, options2_cloned); }); }); }); diff --git a/test/specs/join_handler.spec.js b/test/specs/join_handler.spec.js index bbad16cd..e1a0deba 100644 --- a/test/specs/join_handler.spec.js +++ b/test/specs/join_handler.spec.js @@ -1,6 +1,7 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import joinHandler from '../../src/format/join_handler.js'; +import {describe, it, beforeEach} from 'node:test'; describe('join_handler', () => { let dare; @@ -13,11 +14,11 @@ describe('join_handler', () => { dare = dare.use(); }); - it('join handler should be defined in instances of Dare', () => { - expect(joinHandler).to.be.a('function'); + it('join handler should be defined in instances of Dare', async () => { + assert.strictEqual(typeof joinHandler, 'function'); }); - it('should return an array of objects which describe the join between the two tables', () => { + it('should return an array of objects which describe the join between the two tables', async () => { // Given a relationship between dare.options = { models: { @@ -40,9 +41,9 @@ describe('join_handler', () => { const join = joinHandler(child_object, parent_object, dare); - expect(child_object).to.eql(join); + assert.strictEqual(child_object, join); - expect(child_object).to.deep.equal({ + assert.deepStrictEqual(child_object, { alias: 'child', table: 'child', join_conditions: { @@ -52,7 +53,7 @@ describe('join_handler', () => { }); }); - it('should return many=false when the table to be joined contains the key for the other', () => { + it('should return many=false when the table to be joined contains the key for the other', async () => { // Given a relationship between dare.options = { models: { @@ -75,9 +76,9 @@ describe('join_handler', () => { const join = joinHandler(parent_object, child_object, dare); - expect(parent_object).to.eql(join); + assert.strictEqual(parent_object, join); - expect(parent_object).to.deep.equal({ + assert.deepStrictEqual(parent_object, { alias: 'parent', table: 'parent', join_conditions: { @@ -87,7 +88,7 @@ describe('join_handler', () => { }); }); - it('should deduce any extra join to complete the relationship `infer_intermediate_models=true`', () => { + it('should deduce any extra join to complete the relationship `infer_intermediate_models=true`', async () => { // Given a relationship between dare.options = { models: { @@ -118,7 +119,7 @@ describe('join_handler', () => { const join = joinHandler(child_object, grandparent_object, dare); - expect(join).to.deep.equal({ + assert.deepStrictEqual(join, { table: 'parent', join_conditions: { grand_id: 'gid', @@ -140,7 +141,7 @@ describe('join_handler', () => { dareInst ); - expect(null_join).to.deep.equal(null); + assert.deepStrictEqual(null_join, null); } // But this is limited to only one intermediary table, not two @@ -156,10 +157,10 @@ describe('join_handler', () => { dare ); - expect(no_join).to.deep.equal(null); + assert.deepStrictEqual(no_join, null); }); - it('should not infer_intermediate_join using a common key (defined on named models)', () => { + it('should not infer_intermediate_join using a common key (defined on named models)', async () => { // Given a relationship between dare.options = { models: { @@ -191,10 +192,10 @@ describe('join_handler', () => { const no_join = joinHandler(person, comment, dare); - expect(no_join).to.deep.equal(null); + assert.deepStrictEqual(no_join, null); }); - it('should not infer_intermediate_join using a common key (defined on link models)', () => { + it('should not infer_intermediate_join using a common key (defined on link models)', async () => { // Given a relationship between dare.options = { models: { @@ -220,10 +221,10 @@ describe('join_handler', () => { const no_join = joinHandler(person, comment, dare); - expect(no_join).to.deep.equal(null); + assert.deepStrictEqual(no_join, null); }); - it('should use the shortcuts to infer the connecting model', () => { + it('should use the shortcuts to infer the connecting model', async () => { const dareInst = dare.use({ infer_intermediate_models: false, models: { @@ -254,7 +255,7 @@ describe('join_handler', () => { const join = joinHandler(grandparent_object, child_object, dareInst); - expect(join).to.deep.equal({ + assert.deepStrictEqual(join, { table: 'parent', join_conditions: { id: 'parent_id', @@ -293,7 +294,7 @@ describe('join_handler', () => { }; }); - it('message.recipient, message.author: using referenced aliases', () => { + it('message.recipient, message.author: using referenced aliases', async () => { const recipient = { table: 'recipient', }; @@ -305,7 +306,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const recipient_join = joinHandler(recipient, message, dare); - expect(recipient_join).to.deep.equal({ + assert.deepStrictEqual(recipient_join, { table: 'recipient', join_conditions: { id: 'to_id', @@ -320,7 +321,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const author_join = joinHandler(author, message, dare); - expect(author_join).to.deep.equal({ + assert.deepStrictEqual(author_join, { table: 'author', join_conditions: { id: 'from_id', @@ -329,7 +330,7 @@ describe('join_handler', () => { }); }); - it('author.message.recipient: using referenced aliases', () => { + it('author.message.recipient: using referenced aliases', async () => { /* * In this example we have a many to many relationship * Where author and recipient are both aliases of person @@ -349,7 +350,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const author_join = joinHandler(message, author, dare); - expect(author_join).to.deep.equal({ + assert.deepStrictEqual(author_join, { table: 'message', join_conditions: { from_id: 'id', @@ -360,7 +361,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const recipient_join = joinHandler(message, recipient, dare); - expect(recipient_join).to.deep.equal({ + assert.deepStrictEqual(recipient_join, { table: 'message', join_conditions: { to_id: 'id', @@ -369,7 +370,7 @@ describe('join_handler', () => { }); }); - it('messageB.recipient: using unreferenced aliases', () => { + it('messageB.recipient: using unreferenced aliases', async () => { dare.options.models.messageB = { schema: { to_id: ['recipient.id'], @@ -388,7 +389,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const recipient_join = joinHandler(recipient, messageB, dare); - expect(recipient_join).to.deep.equal({ + assert.deepStrictEqual(recipient_join, { table: 'recipient', join_conditions: { id: 'to_id', @@ -397,7 +398,7 @@ describe('join_handler', () => { }); }); - it('recipient.messageB: using unreferenced aliases', () => { + it('recipient.messageB: using unreferenced aliases', async () => { dare.options.models.message = { schema: { from_id: ['author.id'], @@ -416,7 +417,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const recipient_join = joinHandler(join_object, root_object, dare); - expect(recipient_join).to.deep.equal({ + assert.deepStrictEqual(recipient_join, { table: 'message', join_conditions: { to_id: 'id', @@ -425,7 +426,7 @@ describe('join_handler', () => { }); }); - it('should return null if there is no way to join the models', () => { + it('should return null if there is no way to join the models', async () => { /* * We already know from options.table_alias this is the same as a person * Redefine @@ -443,7 +444,7 @@ describe('join_handler', () => { // Join the recipient table based upon the const recipient_join = joinHandler(recipient, message, dare); - expect(recipient_join).to.equal(null); + assert.strictEqual(recipient_join, null); }); }); }); diff --git a/test/specs/orderby_reducer.spec.js b/test/specs/orderby_reducer.spec.js index 04dd17c5..3fb6f768 100644 --- a/test/specs/orderby_reducer.spec.js +++ b/test/specs/orderby_reducer.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset */ import orderby_reducer from '../../src/format/orderby_reducer.js'; +import {describe, it} from 'node:test'; describe('Orderby Reducer', () => { describe('should split the current fields belonging to the current and joined tables', () => { @@ -57,12 +58,12 @@ describe('Orderby Reducer', () => { const f = input.reduce(reducer, []); // Expect the formatted list of fields to be identical to the inputted value - expect(f).to.eql(expected); + assert.deepStrictEqual(f, expected); if (expect_join_fields) { - expect(joined.b_table.orderby).to.eql(expect_join_fields); + assert.deepStrictEqual(joined.b_table.orderby, expect_join_fields); } else { - expect(joined).to.not.have.property('b_table'); + assert.ok(!('b_table' in joined)); } }); }); diff --git a/test/specs/orderby_unwrap.spec.js b/test/specs/orderby_unwrap.spec.js index e5eaeba7..bcdab37d 100644 --- a/test/specs/orderby_unwrap.spec.js +++ b/test/specs/orderby_unwrap.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset */ import orderby_unwrap from '../../src/utils/orderby_unwrap.js'; +import {describe, it} from 'node:test'; describe('utils/orderby_unwrap', () => { // Should unwrap SQL Formating to underlying column name @@ -30,7 +31,7 @@ describe('utils/orderby_unwrap', () => { const unwrapped = orderby_unwrap(input); // Expect the formatted list of fields to be identical to the inputted value - expect(unwrapped).to.eql(output); + assert.deepStrictEqual(unwrapped, output); }); }); }); diff --git a/test/specs/patch.spec.js b/test/specs/patch.spec.js index 9caeb322..b1c664e8 100644 --- a/test/specs/patch.spec.js +++ b/test/specs/patch.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions @@ -6,6 +6,7 @@ import sqlEqual from '../lib/sql-equal.js'; import DareError from '../../src/utils/error.js'; import SQL, {raw} from 'sql-template-tag'; +import {describe, it, beforeEach} from 'node:test'; const id = 1; const name = 'name'; @@ -22,8 +23,8 @@ describe('patch', () => { }; }); - it('should contain the function dare.patch', () => { - expect(dare.patch).to.be.a('function'); + it('should contain the function dare.patch', async () => { + assert.strictEqual(typeof dare.patch, 'function'); }); it('should generate an UPDATE statement and execute dare.execute', async () => { @@ -33,23 +34,21 @@ describe('patch', () => { sql, 'UPDATE test a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([name, id, 1]); + assert.deepStrictEqual(values, [name, id, 1]); return {success: true}; }; const resp = await dare.patch('test', {id}, {name}); - expect(resp).to.have.property('success', true); + assert.strictEqual(resp.success, true); }); - it('should throw an exception if affectedRows: 0', () => { + it('should throw an exception if affectedRows: 0', async () => { dare.sql = async () => ({affectedRows: 0}); const test = dare.patch('groups', {id: 20_000}, {name}); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.NOT_FOUND); + await assert.rejects(test, DareError); }); it('should throw an exception if affectedRows: 0', async () => { @@ -64,7 +63,7 @@ describe('patch', () => { {notfound} ); - expect(test).to.equal(notfound); + assert.strictEqual(test, notfound); }); describe('validate formatting of input values', () => { @@ -78,7 +77,7 @@ describe('patch', () => { sql, 'UPDATE test a SET a.`input` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([input, id, 1]); + assert.deepStrictEqual(values, [input, id, 1]); return {success: true}; }; @@ -105,12 +104,7 @@ describe('patch', () => { body: {name: input}, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'name' does not accept objects as values" - ) - .and.have.property('code', DareError.INVALID_VALUE); + await assert.rejects(call, DareError); }); }); @@ -136,12 +130,7 @@ describe('patch', () => { body: {meta: given}, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'meta' must be an object" - ) - .and.have.property('code', DareError.INVALID_VALUE); + await assert.rejects(call, DareError); }); }); @@ -159,7 +148,7 @@ describe('patch', () => { sql, 'UPDATE test a SET a.`meta` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([meta, id, 1]); + assert.deepStrictEqual(values, [meta, id, 1]); return {success: true}; }; @@ -172,7 +161,7 @@ describe('patch', () => { }); }); - it('should apply schema.field.setFunction', () => { + it('should apply schema.field.setFunction', async () => { dare.options.models = { test: { schema: { @@ -194,7 +183,7 @@ describe('patch', () => { sql, 'UPDATE test a SET a.`meta` = JSON_MERGE_PATCH(a.`meta`, ?) WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([JSON.stringify(meta), id, 1]); + assert.deepStrictEqual(values, [JSON.stringify(meta), id, 1]); return {success: true}; }; @@ -215,7 +204,7 @@ describe('patch', () => { sql, 'UPDATE test a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([name, id, limit]); + assert.deepStrictEqual(values, [name, id, limit]); return {success: true}; }; @@ -235,7 +224,7 @@ describe('patch', () => { sql, 'UPDATE IGNORE test a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([name, id, 1]); + assert.deepStrictEqual(values, [name, id, 1]); return {success: true}; }; @@ -254,7 +243,7 @@ describe('patch', () => { sql, 'UPDATE tablename a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([name, id, 1]); + assert.deepStrictEqual(values, [name, id, 1]); return {success: true}; }; @@ -279,7 +268,7 @@ describe('patch', () => { sql, 'UPDATE tbl a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([newName, id, 1]); + assert.deepStrictEqual(values, [newName, id, 1]); return {success: true}; }; @@ -308,7 +297,7 @@ describe('patch', () => { sql, 'UPDATE tbl a SET a.`name` = ? WHERE a.id = ? LIMIT ?' ); - expect(values).to.deep.equal([newName, id, 1]); + assert.deepStrictEqual(values, [newName, id, 1]); return {success: true}; }; @@ -345,7 +334,7 @@ describe('patch', () => { body: {name}, }); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); it('should not exectute if the opts.skip request is marked', async () => { @@ -365,7 +354,7 @@ describe('patch', () => { body: {name}, }); - expect(resp).to.eql(skip); + assert.strictEqual(resp, skip); }); it('should allow complex filters', async () => { @@ -374,7 +363,7 @@ describe('patch', () => { sql, 'UPDATE tbl a SET a.`name` = ? WHERE a.id = ? AND (NOT a.number < ? OR a.number IS NULL) LIMIT ?' ); - expect(values).to.deep.equal(['andrew', 1, '100', 1]); + assert.deepStrictEqual(values, ['andrew', 1, '100', 1]); return {success: true}; }; @@ -408,7 +397,7 @@ describe('patch', () => { body: {name: 'andrew'}, }); - expect(test).to.have.property('affectedRows', 1); + assert.strictEqual(test.affectedRows, 1); }); describe('DB Engine specific tests', () => { @@ -417,7 +406,7 @@ describe('patch', () => { dareInst.execute = async ({sql, values}) => { sqlEqual(sql, 'UPDATE tbl a SET "name" = ? WHERE a.id = ?'); - expect(values).to.deep.equal([name, id]); + assert.deepStrictEqual(values, [name, id]); return {success: true}; }; diff --git a/test/specs/post.spec.js b/test/specs/post.spec.js index 76cf98b9..86cff9e1 100644 --- a/test/specs/post.spec.js +++ b/test/specs/post.spec.js @@ -1,10 +1,11 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; // Test Generic DB functions import sqlEqual from '../lib/sql-equal.js'; import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; describe('post', () => { let dare; @@ -18,19 +19,19 @@ describe('post', () => { }; }); - it('should contain the function dare.post', () => { - expect(dare.post).to.be.a('function'); + it('should contain the function dare.post', async () => { + assert.strictEqual(typeof dare.post, 'function'); }); it('should generate an INSERT statement and execute dare.execute', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'INSERT INTO test (`id`) VALUES (?)'); - expect(values).to.deep.equal([1]); + assert.deepStrictEqual(values, [1]); return {id: 1}; }; const resp = await dare.post('test', {id: 1}); - expect(resp).to.have.property('id', 1); + assert.strictEqual(resp.id, 1); }); it('should accept an Array of records to insert', async () => { @@ -42,7 +43,7 @@ describe('post', () => { VALUES (?, ?, DEFAULT), (?, ?, ?) ` ); - expect(values).to.deep.equal([1, '1', 2, '2', 'extra']); + assert.deepStrictEqual(values, [1, '1', 2, '2', 'extra']); return []; }; @@ -61,13 +62,13 @@ describe('post', () => { sql, 'INSERT INTO test (`id`) VALUES (?) ON DUPLICATE KEY UPDATE test._rowid=test._rowid' ); - expect(values).to.deep.equal([1]); + assert.deepStrictEqual(values, [1]); return {}; }; await dare.post('test', {id: 1}, {duplicate_keys: 'ignore'}); - expect(called).to.eql(1); + assert.strictEqual(called, 1); }); it('should accept option.ignore=true', async () => { @@ -76,13 +77,13 @@ describe('post', () => { dare.execute = async ({sql, values}) => { called = 1; sqlEqual(sql, 'INSERT IGNORE INTO test (`id`) VALUES (?)'); - expect(values).to.deep.equal([1]); + assert.deepStrictEqual(values, [1]); return {}; }; await dare.post('test', {id: 1}, {ignore: true}); - expect(called).to.eql(1); + assert.strictEqual(called, 1); }); it('should accept option.update=[field1, field2, ...fieldn]', async () => { @@ -94,7 +95,7 @@ describe('post', () => { sql, 'INSERT INTO test (`id`, `name`, `age`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `name`=VALUES(`name`), `age`=VALUES(`age`)' ); - expect(values).to.deep.equal([1, 'name', 38]); + assert.deepStrictEqual(values, [1, 'name', 38]); return {}; }; @@ -104,14 +105,14 @@ describe('post', () => { {duplicate_keys_update: ['name', 'age']} ); - expect(called).to.eql(1); + assert.strictEqual(called, 1); }); it('should understand a request object', async () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'INSERT INTO test (`name`) VALUES (?)'); - expect(values).to.deep.equal(['name']); + assert.deepStrictEqual(values, ['name']); return {success: true}; }; @@ -125,7 +126,7 @@ describe('post', () => { it('should trigger pre handler, options.post.[table]', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'INSERT INTO tbl (`name`) VALUES (?)'); - expect(values).to.deep.equal(['andrew']); + assert.deepStrictEqual(values, ['andrew']); return {success: true}; }; @@ -147,7 +148,7 @@ describe('post', () => { it('should trigger pre handler, options.post.default, and wait for Promise to resolve', async () => { dare.execute = async ({sql, values}) => { sqlEqual(sql, 'INSERT INTO tbl (`name`) VALUES (?)'); - expect(values).to.deep.equal(['andrew']); + assert.deepStrictEqual(values, ['andrew']); return {success: true}; }; @@ -183,7 +184,7 @@ describe('post', () => { body: {name: 'name'}, }); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); it('should not exectute if the opts.skip request is marked', async () => { @@ -202,7 +203,7 @@ describe('post', () => { body: {name: 'name'}, }); - expect(resp).to.eql(skip); + assert.strictEqual(resp, skip); }); describe('validate formatting of input values', () => { @@ -218,7 +219,7 @@ describe('post', () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'INSERT INTO test (`name`) VALUES (?)'); - expect(values).to.deep.equal([input]); + assert.deepStrictEqual(values, [input]); return {success: true}; }; @@ -255,7 +256,7 @@ describe('post', () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'INSERT INTO test (`meta`) VALUES (?)'); - expect(values).to.deep.equal([output]); + assert.deepStrictEqual(values, [output]); return {success: true}; }; @@ -274,12 +275,12 @@ describe('post', () => { body: {name: given}, }); - return expect(call) - .to.be.eventually.rejectedWith( - DareError, - "Field 'name' does not accept objects as values" - ) - .and.have.property('code', DareError.INVALID_VALUE); + await assert.rejects(call, (error) => { + assert.ok(error instanceof DareError); + assert.match(error.message, /Field 'name' does not accept objects as values/); + assert.strictEqual(error.code, DareError.INVALID_VALUE); + return true; + }); }); }); @@ -300,7 +301,7 @@ describe('post', () => { dare.execute = async ({sql, values}) => { // Limit: 1 sqlEqual(sql, 'INSERT INTO test (`startDate`) VALUES (?)'); - expect(values).to.deep.equal(['2023-01-01']); + assert.deepStrictEqual(values, ['2023-01-01']); return {success: true}; }; @@ -326,7 +327,7 @@ describe('post', () => { sql, 'INSERT INTO test ("id", "name") VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET "name"=EXCLUDED."name" RETURNING id' ); - expect(values).to.deep.equal([1, 'name']); + assert.deepStrictEqual(values, [1, 'name']); return {success: true}; }; @@ -342,7 +343,7 @@ describe('post', () => { sql, 'INSERT INTO test ("id", "name") VALUES (?, ?) ON CONFLICT DO NOTHING RETURNING id' ); - expect(values).to.deep.equal([1, 'name']); + assert.deepStrictEqual(values, [1, 'name']); return {success: true}; }; diff --git a/test/specs/post_query.spec.js b/test/specs/post_query.spec.js index 56a9ad8a..b7b90cbd 100644 --- a/test/specs/post_query.spec.js +++ b/test/specs/post_query.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import DareError from '../../src/utils/error.js'; // Create a schema @@ -6,6 +6,7 @@ import options from '../data/options.js'; // Test Generic DB functions import sqlEqual from '../lib/sql-equal.js'; +import {describe, it, beforeEach} from 'node:test'; describe('post from query', () => { let dare; @@ -33,7 +34,7 @@ describe('post from query', () => { ON DUPLICATE KEY UPDATE comments._rowid=comments._rowid ` ); - expect(values).to.deep.equal(['Liz']); + assert.deepStrictEqual(values, ['Liz']); return {id: 1}; }; @@ -66,7 +67,7 @@ describe('post from query', () => { duplicate_keys: 'ignore', }); - expect(resp).to.have.property('id', 1); + assert.strictEqual(resp.id, 1); }); it('should throw an error if query fields include a nested structures', async () => { @@ -84,9 +85,11 @@ describe('post from query', () => { duplicate_keys: 'ignore', }); - await expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); it('should throw an error if query includes a generated function', async () => { @@ -99,8 +102,10 @@ describe('post from query', () => { duplicate_keys: 'ignore', }); - return expect(test) - .to.be.eventually.rejectedWith(DareError) - .and.have.property('code', DareError.INVALID_REQUEST); + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); }); diff --git a/test/specs/response_handler.spec.js b/test/specs/response_handler.spec.js index d7b3d137..3311dce4 100644 --- a/test/specs/response_handler.spec.js +++ b/test/specs/response_handler.spec.js @@ -1,6 +1,7 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import {getTargetPath} from '../../src/format/field_reducer.js'; +import {describe, it, beforeEach} from 'node:test'; describe('response_handler', () => { let dare; @@ -13,11 +14,11 @@ describe('response_handler', () => { dare = dare.use(); }); - it('response handler should be defined in instances of Dare', () => { - expect(dare).to.have.property('response_handler'); + it('response handler should be defined in instances of Dare', async () => { + assert.ok('response_handler' in dare); }); - it('should expand dot delimited field into a nested object', () => { + it('should expand dot delimited field into a nested object', async () => { const data = dare.response_handler([ { field: 'value', @@ -26,8 +27,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', assoc: { id: 1, @@ -36,7 +37,7 @@ describe('response_handler', () => { }); }); - it('should given a field with an array of fields in the title split the values', () => { + it('should given a field with an array of fields in the title split the values', async () => { const data = dare.response_handler([ { field: 'value', @@ -46,8 +47,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', assoc: { id: '1', @@ -58,7 +59,7 @@ describe('response_handler', () => { }); }); - it('should given a nested dataset', () => { + it('should given a nested dataset', async () => { const data = dare.response_handler([ { field: 'value', @@ -67,8 +68,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', collection: [ { @@ -91,7 +92,7 @@ describe('response_handler', () => { }); }); - it('should transform a deep linked nested', () => { + it('should transform a deep linked nested', async () => { const data = dare.response_handler([ { field: 'value', @@ -103,8 +104,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', asset: { id: 1, @@ -143,7 +144,7 @@ describe('response_handler', () => { }); }); - it('should transform a deep linked nested array with generated fields', () => { + it('should transform a deep linked nested array with generated fields', async () => { function handler(row) { return row.id + 2; } @@ -204,8 +205,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { generated: 3, field: 'value', asset: { @@ -235,7 +236,7 @@ describe('response_handler', () => { }); }); - it('should transform a nested arrays to single root level', () => { + it('should transform a nested arrays to single root level', async () => { const empty = 'empty'; function handler(row) { return row.id ? row.id + 2 : empty; @@ -295,8 +296,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { // @todo remove this b prop. b: [ { @@ -312,7 +313,7 @@ describe('response_handler', () => { }); }); - it('should return empty value if it cannot be interpretted', () => { + it('should return empty value if it cannot be interpretted', async () => { /* * Return a response field which is invalid * this could be because of GROUP_CONCAT_MAX_LENGTH or bad characters which have not been escaped by dare @@ -325,14 +326,14 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', collection: [], }); }); - it('should remove prop if value is empty', () => { + it('should remove prop if value is empty', async () => { /* * Return a response field which is invalid * this could be because of GROUP_CONCAT_MAX_LENGTH or bad characters which have not been escaped by dare @@ -344,13 +345,13 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { field: 'value', }); }); - it('should exclude a series of NULL fields, a side-effect of inline GROUP_CONCAT', () => { + it('should exclude a series of NULL fields, a side-effect of inline GROUP_CONCAT', async () => { // Return a response field which is invalid const data = dare.response_handler([ { @@ -360,14 +361,14 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { collection: [], field: 'value', }); }); - it('should return the field as is if the label is not consistant', () => { + it('should return the field as is if the label is not consistant', async () => { const item = { field: 'value', 'collection[id,name,assoc.id,assoc.name': '[["1","a","a1","aa"]]', @@ -375,8 +376,8 @@ describe('response_handler', () => { const data = dare.response_handler([item]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal(item); + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], item); }); describe('mysql 5.6', () => { @@ -387,7 +388,7 @@ describe('response_handler', () => { dareInst = dare.use({engine: 'mysql:5.6'}); }); - it('should exclude a series of empty strings, a side-effect of inline GROUP_CONCAT', () => { + it('should exclude a series of empty strings, a side-effect of inline GROUP_CONCAT', async () => { // Return a response field which is invalid const data = dareInst.response_handler([ { @@ -397,8 +398,8 @@ describe('response_handler', () => { }, ]); - expect(data).to.be.an('array'); - expect(data[0]).to.deep.equal({ + assert.ok(Array.isArray(data)); + assert.deepStrictEqual(data[0], { collection: [], field: 'value', }); @@ -417,11 +418,11 @@ describe('response_row_handler', () => { dare = dare.use(); }); - it('response handler should be defined in instances of Dare', () => { - expect(dare).to.not.have.property('response_row_handler'); + it('response handler should be defined in instances of Dare', async () => { + assert.ok(!('response_row_handler' in dare)); }); - it('should allow additional formatting with response_row_handler', () => { + it('should allow additional formatting with response_row_handler', async () => { // Define a new response_row_handler dare.response_row_handler = item => { // Adds "prefix" to item.fiele @@ -439,9 +440,10 @@ describe('response_row_handler', () => { }, ]); - expect(data).to.be.an('array').and.to.have.lengthOf(1); + assert.ok(Array.isArray(data)) + assert.strictEqual(data.length, 1, 'Expected data to have length 1'); - expect(data[0]).to.deep.equal({ + assert.deepStrictEqual(data[0], { field: 'prefixvalue', assoc: { id: 1, @@ -450,7 +452,7 @@ describe('response_row_handler', () => { }); }); - it('should return empty array if response_row_handler returns undefined', () => { + it('should return empty array if response_row_handler returns undefined', async () => { // Define a new response_row_handler to return nothing dare.response_row_handler = () => { // Does nothing... @@ -464,7 +466,8 @@ describe('response_row_handler', () => { }, ]); - // eslint-disable-next-line no-unused-expressions - expect(data).to.be.an('array').that.is.empty; + + assert.ok(Array.isArray(data)); + assert.strictEqual(data.length, 0, 'Expected data to have length 0'); }); }); diff --git a/test/specs/schema.defaultValue.spec.js b/test/specs/schema.defaultValue.spec.js index 1b688e5e..7cd44421 100644 --- a/test/specs/schema.defaultValue.spec.js +++ b/test/specs/schema.defaultValue.spec.js @@ -1,7 +1,8 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import getFieldAttributes from '../../src/utils/field_attributes.js'; +import {describe, it, beforeEach} from 'node:test'; function spy(obj, func, callback) { const history = []; @@ -41,13 +42,13 @@ describe('schema.defaultValue', () => { describe('getFieldAttributes', () => { const field = 'field'; - it('defaultValue should not occur by default', () => { + it('defaultValue should not occur by default', async () => { const attr = getFieldAttributes(field, {}, dareInstance); - expect(attr).to.not.have.property('defaultValue'); + assert.ok(!('defaultValue' in attr)); }); [undefined, 1, null, 'string'].forEach(defaultValue => { - it(`should expand defaultValue, ${defaultValue}`, () => { + it(`should expand defaultValue, ${defaultValue}`, () => { const attr = getFieldAttributes( field, { @@ -60,7 +61,7 @@ describe('schema.defaultValue', () => { }, dareInstance ); - expect(attr).to.have.property('defaultValue', defaultValue); + assert.strictEqual(attr.defaultValue, defaultValue); }); }); }); @@ -83,7 +84,7 @@ describe('schema.defaultValue', () => { fields: ['id', 'name'], }); - expect(resp.join).to.have.property('status', defaultValue); + assert.strictEqual(resp.join.status, defaultValue); }); }); }); @@ -97,8 +98,8 @@ describe('schema.defaultValue', () => { }); const [{sql, values}] = history.at(0); - expect(sql).to.include('`status`'); - expect(values).to.include('active'); + assert(typeof sql === "string" ? sql.includes('`status`') : sql.indexOf('`status`') !== -1); + assert(typeof values === "string" ? values.includes('active') : values.indexOf('active') !== -1); }); it('should be overrideable', async () => { @@ -110,8 +111,8 @@ describe('schema.defaultValue', () => { }); const [{sql, values}] = history.at(0); - expect(sql).to.include('`status`'); - expect(values).to.include('overridden'); + assert(typeof sql === "string" ? sql.includes('`status`') : sql.indexOf('`status`') !== -1); + assert(typeof values === "string" ? values.includes('overridden') : values.indexOf('overridden') !== -1); }); it('should be overrideable, even with different formatting', async () => { @@ -128,10 +129,10 @@ describe('schema.defaultValue', () => { }); const [{sql, values}] = history.at(0); - expect(sql).to.include('`status`'); - expect(sql).to.not.include('Status'); - expect(values).to.include('overridden'); - expect(values).to.not.include('active'); + assert(typeof sql === "string" ? sql.includes('`status`') : sql.indexOf('`status`') !== -1); + assert(typeof sql === "string" ? !sql.includes('Status') : sql.indexOf('Status') === -1); + assert(typeof values === "string" ? values.includes('overridden') : values.indexOf('overridden') !== -1); + assert(typeof values === "string" ? !values.includes('active') : values.indexOf('active') === -1); }); it('should be removed', async () => { @@ -147,9 +148,9 @@ describe('schema.defaultValue', () => { * This should be akin to removing the defaultValue too */ const [{sql, values}] = history.at(0); - expect(sql).to.include('`status`'); - expect(sql).to.include('DEFAULT'); - expect(values).to.not.include(undefined); + assert(typeof sql === "string" ? sql.includes('`status`') : sql.indexOf('`status`') !== -1); + assert(typeof sql === "string" ? sql.includes('DEFAULT') : sql.indexOf('DEFAULT') !== -1); + assert(typeof values === "string" ? !values.includes(undefined) : values.indexOf(undefined) === -1); }); it('should pass through just the defaultValue.post to validateInput handler', async () => { @@ -171,7 +172,7 @@ describe('schema.defaultValue', () => { ([, propName]) => propName === 'status' ); - expect(attr).to.have.property('defaultValue', 'active'); + assert.strictEqual(attr.defaultValue, 'active'); }); }); @@ -196,8 +197,8 @@ describe('schema.defaultValue', () => { const [{sql, values}] = history.at(0); - expect(sql).to.include('status = '); - expect(values).to.include(defaultValue); + assert(typeof sql === "string" ? sql.includes('status = ') : sql.indexOf('status = ') !== -1); + assert(typeof values === "string" ? values.includes(defaultValue) : values.indexOf(defaultValue) !== -1); }); ['filter', 'join'].forEach(condition => { @@ -221,9 +222,9 @@ describe('schema.defaultValue', () => { const [{sql, values}] = history.at(0); - expect(sql).to.include('status = '); - expect(values).to.not.include(defaultValue); - expect(values).to.include('boom'); + assert(typeof sql === "string" ? sql.includes('status = ') : sql.indexOf('status = ') !== -1); + assert(typeof values === "string" ? !values.includes(defaultValue) : values.indexOf(defaultValue) === -1); + assert(typeof values === "string" ? values.includes('boom') : values.indexOf('boom') !== -1); }); it(`should be overideable within a dare.${method}() call '${condition}' using an alias`, async () => { @@ -251,9 +252,9 @@ describe('schema.defaultValue', () => { const [{sql, values}] = history.at(0); - expect(sql).to.include('status = '); - expect(values).to.not.include(defaultValue); - expect(values).to.include('boom'); + assert(typeof sql === "string" ? sql.includes('status = ') : sql.indexOf('status = ') !== -1); + assert(typeof values === "string" ? !values.includes(defaultValue) : values.indexOf(defaultValue) === -1); + assert(typeof values === "string" ? values.includes('boom') : values.indexOf('boom') !== -1); }); it(`should be undefinedable within a dare.${method}() call '${condition}'`, async () => { @@ -280,9 +281,9 @@ describe('schema.defaultValue', () => { * TODO: Should not include filters where the values are undefined * This should be akin to removing the defaultValue too */ - expect(sql).to.include('status = '); - expect(values).to.not.include(defaultValue); - expect(values).to.include(undefined); + assert(typeof sql === "string" ? sql.includes('status = ') : sql.indexOf('status = ') !== -1); + assert(typeof values === "string" ? !values.includes(defaultValue) : values.indexOf(defaultValue) === -1); + assert(typeof values === "string" ? values.includes(undefined) : values.indexOf(undefined) !== -1); }); }); }); diff --git a/test/specs/schema_override.spec.js b/test/specs/schema_override.spec.js index 4fef5a28..aa0ee053 100644 --- a/test/specs/schema_override.spec.js +++ b/test/specs/schema_override.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; +import {describe, it, beforeEach} from 'node:test'; describe('schema override', () => { let dare; @@ -37,7 +38,7 @@ describe('schema override', () => { const callBeforeOverride = dare.patch(patchOptions); - await expect(callBeforeOverride).to.be.eventually.rejected; + await assert.rejects(callBeforeOverride); const callAfterOverride = dare.patch({ ...patchOptions, @@ -52,7 +53,7 @@ describe('schema override', () => { }, }); - await expect(callAfterOverride).to.be.eventually.fulfilled; + await assert.doesNotReject(callAfterOverride); }); }); @@ -68,7 +69,7 @@ describe('schema override', () => { const callBeforeOverride = dare.post(postOptions); - await expect(callBeforeOverride).to.be.eventually.rejected; + await assert.rejects(callBeforeOverride); const callAfterOverride = dare.post({ ...postOptions, @@ -83,7 +84,7 @@ describe('schema override', () => { }, }); - await expect(callAfterOverride).to.be.eventually.fulfilled; + await assert.doesNotReject(callAfterOverride); }); }); }); diff --git a/test/specs/sql.spec.js b/test/specs/sql.spec.js index afd6c127..068a3baa 100644 --- a/test/specs/sql.spec.js +++ b/test/specs/sql.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; +import {describe, it, beforeEach} from 'node:test'; describe('sql', () => { let dare; @@ -10,26 +11,26 @@ describe('sql', () => { dare = new Dare(); dare.execute = async ({sql, values}) => { - expect(sql).to.equal(query); + assert.strictEqual(sql, query); return values[0]; }; }); - it('should contain the function dare.sql', () => { - expect(dare.sql).to.be.a('function'); + it('should contain the function dare.sql', async () => { + assert.strictEqual(typeof dare.sql, 'function'); }); it('deprecated: should trigger execute from a string', async () => { const res = await dare.sql(query, values); - expect(res).to.eql(values[0]); + assert.deepStrictEqual(res, values[0]); }); it('should trigger execute from an Object', async () => { const res = await dare.sql({sql: query, values}); - expect(res).to.eql(1); + assert.strictEqual(res, 1); }); - it('should trigger execute and reject a promise', () => { + it('should trigger execute and reject a promise', async () => { const msg = 'test'; dare.execute = async () => { @@ -38,6 +39,6 @@ describe('sql', () => { const test = dare.sql({sql: query}); - return expect(test).to.be.eventually.rejectedWith(Error, msg); + await assert.rejects(test, Error, msg); }); }); diff --git a/test/specs/unwrap_field.spec.js b/test/specs/unwrap_field.spec.js index fc4543c9..2079ef3e 100644 --- a/test/specs/unwrap_field.spec.js +++ b/test/specs/unwrap_field.spec.js @@ -1,4 +1,4 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; /* * Field Reducer * Extract the fields from the current dataset @@ -6,6 +6,7 @@ import {expect} from 'chai'; import unwrap_field from '../../src/utils/unwrap_field.js'; import DareError from '../../src/utils/error.js'; +import {describe, it} from 'node:test'; describe('utils/unwrap_field', () => { /* @@ -57,7 +58,7 @@ describe('utils/unwrap_field', () => { const unwrapped = unwrap_field(test); // Expect the formatted list of fields to be identical to the inputted value - expect(unwrapped.field).to.eql('field'); + assert.strictEqual(unwrapped.field, 'field'); }); }); @@ -101,7 +102,7 @@ describe('utils/unwrap_field', () => { ].forEach(test => { it(`errors: ${JSON.stringify(test)}`, () => { // Expect the field expression unwrapping to throw a Dare Error - expect(unwrap_field.bind(null, test)).to.throw(DareError); + assert.throws(unwrap_field.bind(null, test), DareError); }); }); }); diff --git a/test/specs/utils_error.spec.js b/test/specs/utils_error.spec.js index e71e2b49..ca38afb1 100644 --- a/test/specs/utils_error.spec.js +++ b/test/specs/utils_error.spec.js @@ -1,4 +1,5 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; +import {describe, it} from 'node:test'; /* * Field Reducer * Extract the fields from the current dataset @@ -12,8 +13,8 @@ describe('utils/error', () => { const error = new DareError(DareError.INVALID_REFERENCE); // Expect the formatted list of fields to be identical to the inputted value - expect(error).to.have.property('code', 'INVALID_REFERENCE'); - expect(error).to.have.property('status', 400); - expect(error).to.have.property('message', 'Invalid request'); + assert.strictEqual(error.code, 'INVALID_REFERENCE'); + assert.strictEqual(error.status, 400); + assert.strictEqual(error.message, 'Invalid request'); }); }); diff --git a/test/specs/utils_extend.spec.js b/test/specs/utils_extend.spec.js index 00e07d76..2e6cc0a0 100644 --- a/test/specs/utils_extend.spec.js +++ b/test/specs/utils_extend.spec.js @@ -1,5 +1,6 @@ import assert from 'node:assert/strict'; import extend from '../../src/utils/extend.js'; +import {describe, it} from 'node:test'; /* * Extend @@ -7,7 +8,7 @@ import extend from '../../src/utils/extend.js'; */ describe('utils/extend', () => { - it('should recursively extend an object', () => { + it('should recursively extend an object', async () => { const obj = { a: { b: { @@ -39,14 +40,14 @@ describe('utils/extend', () => { ); }); - it('should not extend prototype', () => { + it('should not extend prototype', async () => { // Should not extend the the default prototype object... extend({}, JSON.parse('{"__proto__": {"devMode": true}}')); assert.ok(!{}.devMode, 'Prototype should not be extended'); }); - it('should extend properties with values including; scalars, arrays, functions to be replaced', () => { + it('should extend properties with values including; scalars, arrays, functions to be replaced', async () => { const obj = { propString: 'string', propNumber: 0, diff --git a/test/specs/utils_format_datetime.spec.js b/test/specs/utils_format_datetime.spec.js index 6410d957..b99ed2ad 100644 --- a/test/specs/utils_format_datetime.spec.js +++ b/test/specs/utils_format_datetime.spec.js @@ -1,7 +1,8 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; // Format Input Dates import format_datetime from '../../src/utils/format_datetime.js'; +import {describe, it} from 'node:test'; describe('utils/format_datetime', () => { // Should create date ranges from years/months/days... @@ -26,7 +27,7 @@ describe('utils/format_datetime', () => { const formatted = format_datetime(input); // Expect the formatted list of fields to be identical to the inputted value - expect(formatted).to.eql(expected); + assert.strictEqual(formatted, expected); }); }); @@ -36,7 +37,7 @@ describe('utils/format_datetime', () => { const formatted = format_datetime(input); // Expect the formatted list of fields to be identical to the inputted value - expect(formatted).to.eql(input); + assert.strictEqual(formatted, input); }); }); }); diff --git a/test/specs/utils_group_concat.spec.js b/test/specs/utils_group_concat.spec.js index 56772f31..c3f02047 100644 --- a/test/specs/utils_group_concat.spec.js +++ b/test/specs/utils_group_concat.spec.js @@ -1,8 +1,9 @@ /* eslint quotes: ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }]*/ -import {expect} from 'chai'; +import assert from 'node:assert'; // Test Generic DB functions import group_concat from '../../src/utils/group_concat.js'; +import {describe, it} from 'node:test'; const rowid = '_rowid'; @@ -12,11 +13,11 @@ const MYSQL_57 = 'mysql:5.7.40'; [MYSQL_57, MYSQL_56, POSTGRES].forEach(DB_ENGINE => { describe(`utils/group_concat: (mysql ${DB_ENGINE})`, () => { - it('should return a function', () => { - expect(group_concat).to.be.a('function'); + it('should return a function', async () => { + assert.strictEqual(typeof group_concat, 'function'); }); - it('should reduce an array of fields to a GROUP_CONCAT statement', () => { + it('should reduce an array of fields to a GROUP_CONCAT statement', async () => { const gc = group_concat({ fields: [ { @@ -40,11 +41,11 @@ const MYSQL_57 = 'mysql:5.7.40'; [MYSQL_56]: `CONCAT('[', GROUP_CONCAT(IF(a._rowid IS NOT NULL, CONCAT_WS('', '[', '"', REPLACE(REPLACE(table.a, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ',', '"', REPLACE(REPLACE(table.b, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ']'), NULL)), ']')`, }[DB_ENGINE || 'default']; - expect(gc.expression).to.eql(expectSQLEqual); - expect(gc.label).to.eql('collection[a,b]'); + assert.strictEqual(gc.expression, expectSQLEqual); + assert.deepStrictEqual(gc.label, 'collection[a,b]'); }); - it('should not wrap fields which are marked as aggregating the row', () => { + it('should not wrap fields which are marked as aggregating the row', async () => { const gc = group_concat({ fields: [ { @@ -66,11 +67,11 @@ const MYSQL_57 = 'mysql:5.7.40'; [MYSQL_56]: `CONCAT_WS('', '[', '"', REPLACE(REPLACE(table.a, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ',', '"', REPLACE(REPLACE(table.b, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ']')`, }[DB_ENGINE || 'default']; - expect(gc.expression).to.eql(expectSQLEqual); - expect(gc.label).to.eql('a,b'); + assert.strictEqual(gc.expression, expectSQLEqual); + assert.strictEqual(gc.label, 'a,b'); }); - it('should return a single value if one is given and is an aggregate', () => { + it('should return a single value if one is given and is an aggregate', async () => { const gc = group_concat({ fields: [ { @@ -82,11 +83,11 @@ const MYSQL_57 = 'mysql:5.7.40'; engine: DB_ENGINE, }); - expect(gc.expression).to.eql('table.a'); - expect(gc.label).to.eql('a'); + assert.strictEqual(gc.expression, 'table.a'); + assert.strictEqual(gc.label, 'a'); }); - it('should return an array of values for many results', () => { + it('should return an array of values for many results', async () => { const gc = group_concat({ fields: [ { @@ -106,12 +107,12 @@ const MYSQL_57 = 'mysql:5.7.40'; [MYSQL_56]: `CONCAT('[', GROUP_CONCAT(IF(a._rowid IS NOT NULL, CONCAT_WS('', '[', '"', REPLACE(REPLACE(table.a, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ']'), NULL)), ']')`, }[DB_ENGINE || 'default']; - expect(gc.expression).to.eql(expectSQLEqual); + assert.strictEqual(gc.expression, expectSQLEqual); - expect(gc.label).to.eql('collection[a]'); + assert.deepStrictEqual(gc.label, 'collection[a]'); }); - it('should infer from the label whether results are implicitly aggregated', () => { + it('should infer from the label whether results are implicitly aggregated', async () => { const gc = group_concat({ fields: [ { @@ -123,8 +124,8 @@ const MYSQL_57 = 'mysql:5.7.40'; engine: DB_ENGINE, }); - expect(gc.expression).to.eql('table.a'); - expect(gc.label).to.eql('a'); + assert.strictEqual(gc.expression, 'table.a'); + assert.strictEqual(gc.label, 'a'); const gc_many = group_concat({ fields: [ @@ -147,8 +148,8 @@ const MYSQL_57 = 'mysql:5.7.40'; [MYSQL_56]: `CONCAT_WS('', '[', '"', REPLACE(REPLACE(table.a, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ',', '"', REPLACE(REPLACE(table.b, '\\\\', '\\\\\\\\'), '"', '\\\\"'), '"', ']')`, }[DB_ENGINE || 'default']; - expect(gc_many.expression).to.eql(expectSQLEqual); - expect(gc_many.label).to.eql('a,b'); + assert.strictEqual(gc_many.expression, expectSQLEqual); + assert.strictEqual(gc_many.label, 'a,b'); }); }); }); diff --git a/test/specs/utils_validate_field.spec.js b/test/specs/utils_validate_field.spec.js index 7be4cfaa..7967cc8a 100644 --- a/test/specs/utils_validate_field.spec.js +++ b/test/specs/utils_validate_field.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import validate_alias from '../../src/utils/validate_field.js'; +import {describe, it} from 'node:test'; describe('validate field alias', () => { ['field', 'Field', 'AB_'].forEach(key => { @@ -10,7 +11,7 @@ describe('validate field alias', () => { ['use rs', 'users(1', '*', 'a.*'].forEach(key => { it(`should not accept ${key} as a valid field references`, () => { - expect(() => validate_alias(key)).to.throw(Error); + assert.throws(() => validate_alias(key), Error); }); }); }); diff --git a/test/specs/utils_validate_label.spec.js b/test/specs/utils_validate_label.spec.js index 1276e806..14631ff7 100644 --- a/test/specs/utils_validate_label.spec.js +++ b/test/specs/utils_validate_label.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import validate_label from '../../src/utils/validate_label.js'; +import {describe, it} from 'node:test'; describe('validate field label', () => { ['field', 'Field', 'AB_'].forEach(key => { @@ -10,7 +11,7 @@ describe('validate field label', () => { ['"', "'", '`', '?'].forEach(key => { it(`should not accept ${key} as a valid field label`, () => { - expect(() => validate_label(key)).to.throw(Error); + assert.throws(() => validate_label(key), Error); }); }); }); diff --git a/test/specs/validateInput.spec.js b/test/specs/validateInput.spec.js index 11213cea..a38ba7bc 100644 --- a/test/specs/validateInput.spec.js +++ b/test/specs/validateInput.spec.js @@ -2,8 +2,9 @@ * @import {Schema} from '../../src/index.js' */ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; +import {describe, it, beforeEach} from 'node:test'; describe('validateInput', () => { let dare; @@ -61,15 +62,12 @@ describe('validateInput', () => { body: {age: 'one'}, }); - return expect(test).to.be.eventually.rejectedWith( - Error, - 'name is a required field' - ); + await assert.rejects(test, Error); }); ['post', 'patch'].forEach(method => { describe(method, () => { - it('should proceed if validateInput is not defined', () => { + it('should proceed if validateInput is not defined', async () => { // Should not be called... dare.execute = () => ({}); @@ -105,10 +103,7 @@ describe('validateInput', () => { body: {age: 'one'}, }); - return expect(test).to.be.eventually.rejectedWith( - Error, - 'age should be a number' - ); + await assert.rejects(test, Error); }); it('should pass through undefined for fieldAttributes when the field is not defined in the schema', async () => { @@ -130,10 +125,7 @@ describe('validateInput', () => { body: {hello: "i shouldn't be here"}, }); - return expect(test).to.be.eventually.rejectedWith( - Error, - 'hello is unknown' - ); + await assert.rejects(test, Error); }); it('should parse falsy fieldDefinitions', async () => { @@ -161,10 +153,7 @@ describe('validateInput', () => { body: {password: '!@£RTYU'}, }); - return expect(test).to.be.eventually.rejectedWith( - Error, - 'password is immutable' - ); + await assert.rejects(test, Error); }); it('should use the default field definition when no other field matches the current model', async () => { @@ -201,10 +190,7 @@ describe('validateInput', () => { body: {hello: "i shouldn't be here"}, }); - return expect(test).to.be.eventually.rejectedWith( - Error, - 'hello is immutable' - ); + await assert.rejects(test, Error); }); }); }); diff --git a/test/specs/validate_alias.spec.js b/test/specs/validate_alias.spec.js index 7996ec6c..da1ca0e2 100644 --- a/test/specs/validate_alias.spec.js +++ b/test/specs/validate_alias.spec.js @@ -1,5 +1,6 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import validate_alias from '../../src/utils/validate_alias.js'; +import {describe, it} from 'node:test'; describe('validate table alias', () => { ['users', 'users$1', 'users_table', 'usersTable'].forEach(key => { @@ -10,7 +11,7 @@ describe('validate table alias', () => { ['use rs', 'users(1'].forEach(key => { it(`should not accept ${key} as a valid table references`, () => { - expect(() => validate_alias(key)).to.throw(Error); + assert.throws(() => validate_alias(key), Error); }); }); }); diff --git a/test/specs/validate_body.spec.js b/test/specs/validate_body.spec.js index 934edb5c..369ec1ef 100644 --- a/test/specs/validate_body.spec.js +++ b/test/specs/validate_body.spec.js @@ -1,6 +1,7 @@ -import {expect} from 'chai'; +import assert from 'node:assert'; import Dare from '../../src/index.js'; import DareError from '../../src/utils/error.js'; +import {describe, it, beforeEach} from 'node:test'; describe('validate_body', () => { let dare; @@ -17,7 +18,7 @@ describe('validate_body', () => { ['post', 'patch'].forEach(method => { describe(`${method} should throw an invalid_request on the following`, () => { [{}, [], null, 1, 'string'].forEach(body => { - it(JSON.stringify(body), () => { + it(JSON.stringify(body), async () => { const test = dare[method]({ table: 'tbl', filter: { @@ -26,12 +27,15 @@ describe('validate_body', () => { body, }); - return expect(test) - .to.be.eventually.rejectedWith( - DareError, + await assert.rejects(test, (error) => { + assert(error instanceof DareError); + assert.match( + error.message, /^The body .*? is invalid$/ - ) - .and.have.property('code', DareError.INVALID_REQUEST); + ); + assert.strictEqual(error.code, DareError.INVALID_REQUEST); + return true; + }); }); }); });