From 46a4701b63db857e5aa8cf32b8531578dcf295f4 Mon Sep 17 00:00:00 2001 From: Aleksei Androsov Date: Mon, 29 Apr 2024 13:20:04 +0300 Subject: [PATCH] Add eslint-plugin-jest (#60) --- .eslintrc.js | 23 +- .github/workflows/eslint.yml | 2 +- .github/workflows/tests.yml | 2 +- .github/workflows/ts-compile.yml | 2 +- jest.config.js | 2 + package-lock.json | 333 +++++++++++++++++- package.json | 1 + tests/array_block.test.js | 2 +- tests/cancel.test.js | 45 +-- tests/first_block.test.js | 6 +- tests/function_block.test.js | 12 +- tests/http_block.test.js | 4 +- tests/object_block.test.js | 4 +- tests/options.after.test.js | 10 +- tests/options.before.test.js | 14 +- tests/options.cache.test.js | 26 +- tests/options.deps.test.js | 10 +- tests/options.error.test.js | 8 +- tests/options.params.test.js | 2 +- tests/pipe_block.test.js | 8 +- tests/request.test.js | 8 +- tests/strip_null_and_undefined_values.test.js | 4 +- 22 files changed, 442 insertions(+), 86 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4f85c47..6616596 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,28 @@ module.exports = { - extends: 'plugin:nop/nop', + extends: [ + 'plugin:nop/nop', + 'eslint:recommended', + ], + plugins: [ + 'jest', + ], env: { jest: true, }, + rules: { + 'jest/consistent-test-it': [ 'error', { + fn: 'it', + withinDescribe: 'it', + } ], + 'jest/expect-expect': [ 'error', { assertFunctionNames: [ 'expect' ] } ], + 'jest/no-alias-methods': 'error', + 'jest/no-disabled-tests': 'error', + 'jest/no-focused-tests': 'error', + 'jest/no-identical-title': 'error', + 'jest/prefer-to-contain': 'error', + 'jest/prefer-to-have-length': 'error', + 'jest/no-large-snapshots': [ 'error', { maxSize: 500 } ], + 'jest/valid-expect': 'error', + }, }; diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index ea0773d..a8647e4 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f98bc34..fd17146 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x] + node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ts-compile.yml b/.github/workflows/ts-compile.yml index 3e7ec3b..eeb692d 100644 --- a/.github/workflows/ts-compile.yml +++ b/.github/workflows/ts-compile.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 diff --git a/jest.config.js b/jest.config.js index 317140f..45d4e10 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,5 +4,7 @@ module.exports = { '/tests/server.js', '/tests/helpers.js', ], + testEnvironment: 'node', + testRunner: 'jest-circus/runner', }; diff --git a/package-lock.json b/package-lock.json index 5769913..323ecae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@types/node": "^20.12.7", "eslint": "^8.57.0", + "eslint-plugin-jest": "^28.3.0", "eslint-plugin-nop": "0.0.3", "jest": "^29.7.0", "ts-node": "^10.9.2", @@ -1530,6 +1531,12 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, "node_modules/@types/node": { "version": "20.12.7", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", @@ -1539,6 +1546,12 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/semver": { + "version": "7.5.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", + "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", + "dev": true + }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -1560,6 +1573,196 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz", + "integrity": "sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.21.0.tgz", + "integrity": "sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==", + "dev": true, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz", + "integrity": "sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "9.0.3", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/@typescript-eslint/utils": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.21.0.tgz", + "integrity": "sha512-NfWVaC8HP9T8cbKQxHcsJBY5YE1O33+jpMwN45qzWWaPDZgLIbo12toGMWnmhvCpd3sIxkpDw3Wv1B3dYrbDQQ==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@types/json-schema": "^7.0.12", + "@types/semver": "^7.5.0", + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/typescript-estree": "6.21.0", + "semver": "^7.5.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz", + "integrity": "sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -1685,6 +1888,15 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -2083,9 +2295,9 @@ } }, "node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -2155,6 +2367,18 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -2276,6 +2500,31 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-jest": { + "version": "28.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.3.0.tgz", + "integrity": "sha512-5LjCSSno8E+IUCOX4hJiIb/upPIgpkaDEcaN/40gOcw26t/5UTLHFc4JdxKjOOvGTh0XdCu+fNr0fpOVNvcxMA==", + "dev": true, + "dependencies": { + "@typescript-eslint/utils": "^6.0.0" + }, + "engines": { + "node": "^16.10.0 || ^18.12.0 || >=20.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0", + "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", + "jest": "*" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + }, + "jest": { + "optional": true + } + } + }, "node_modules/eslint-plugin-nop": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/eslint-plugin-nop/-/eslint-plugin-nop-0.0.3.tgz", @@ -2485,6 +2734,34 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "node_modules/fast-glob": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -2686,6 +2963,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -3776,6 +4073,15 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/micromatch": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", @@ -4010,6 +4316,15 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -4486,6 +4801,18 @@ "node": ">=8.0" } }, + "node_modules/ts-api-utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "dev": true, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", diff --git a/package.json b/package.json index c822023..980e87b 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@types/node": "^20.12.7", "eslint": "^8.57.0", + "eslint-plugin-jest": "^28.3.0", "eslint-plugin-nop": "0.0.3", "jest": "^29.7.0", "ts-node": "^10.9.2", diff --git a/tests/array_block.test.js b/tests/array_block.test.js index 78ade7e..0309534 100644 --- a/tests/array_block.test.js +++ b/tests/array_block.test.js @@ -295,7 +295,7 @@ describe( 'de.array', () => { } catch ( e ) { expect( e ).toBe( abort_error ); - expect( action_foo_spy.mock.calls.length ).toBe( 0 ); + expect( action_foo_spy.mock.calls ).toHaveLength( 0 ); expect( action_bar_spy.mock.calls[ 0 ][ 0 ] ).toBe( abort_error ); } } ); diff --git a/tests/cancel.test.js b/tests/cancel.test.js index ba8ad89..e9a133e 100644 --- a/tests/cancel.test.js +++ b/tests/cancel.test.js @@ -4,7 +4,7 @@ const de = require( '../lib' ); describe( 'de.Cancel', () => { - test( 'cancel', () => { + it( 'cancel', () => { const cancel = new de.Cancel(); const spy = jest.fn(); @@ -18,7 +18,7 @@ describe( 'de.Cancel', () => { expect( spy.mock.calls[ 0 ][ 0 ] ).toBe( error ); } ); - test( 'cancel with plain object', () => { + it( 'cancel with plain object', () => { const cancel = new de.Cancel(); const spy = jest.fn(); @@ -34,7 +34,7 @@ describe( 'de.Cancel', () => { expect( reason.error.id ).toBe( error.id ); } ); - test( 'cancel after cancel', () => { + it( 'cancel after cancel', () => { const cancel = new de.Cancel(); const spy = jest.fn(); @@ -49,10 +49,10 @@ describe( 'de.Cancel', () => { } ); cancel.cancel( error2 ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); - test( 'cancel after close', () => { + it( 'cancel after close', () => { const cancel = new de.Cancel(); const spy = jest.fn(); @@ -65,10 +65,10 @@ describe( 'de.Cancel', () => { } ); cancel.cancel( error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); - test( 'throw_if_cancelled #1', () => { + it( 'throw_if_cancelled #1', () => { const cancel = new de.Cancel(); const error = de.error( { @@ -85,13 +85,14 @@ describe( 'de.Cancel', () => { } } ); - test( 'throw_if_cancelled #2', () => { - const cancel = new de.Cancel(); - - cancel.throw_if_cancelled(); + it( 'throw_if_cancelled #2', () => { + expect( () => { + const cancel = new de.Cancel(); + cancel.throw_if_cancelled(); + } ).not.toThrow(); } ); - test( 'subscribe after close', () => { + it( 'subscribe after close', () => { const cancel = new de.Cancel(); cancel.close(); @@ -99,10 +100,10 @@ describe( 'de.Cancel', () => { const spy = jest.fn(); cancel.subscribe( spy ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); - test( 'subscribe after cancel', () => { + it( 'subscribe after cancel', () => { const cancel = new de.Cancel(); const error = de.error( { @@ -116,7 +117,7 @@ describe( 'de.Cancel', () => { expect( spy.mock.calls[ 0 ][ 0 ] ).toBe( error ); } ); - test( 'get_promise', async () => { + it( 'get_promise', async () => { const cancel = new de.Cancel(); const promise = cancel.get_promise(); @@ -137,7 +138,7 @@ describe( 'de.Cancel', () => { } } ); - test( 'get_promise after cancel', async () => { + it( 'get_promise after cancel', async () => { const cancel = new de.Cancel(); const error = de.error( { @@ -154,7 +155,7 @@ describe( 'de.Cancel', () => { } } ); - test( 'child canceled after parent cancel', () => { + it( 'child canceled after parent cancel', () => { const parent_cancel = new de.Cancel(); const child_cancel = parent_cancel.create(); @@ -169,7 +170,7 @@ describe( 'de.Cancel', () => { expect( spy.mock.calls[ 0 ][ 0 ] ).toBe( error ); } ); - test( 'child closed if parent was closed #1', () => { + it( 'child closed if parent was closed #1', () => { const parent_cancel = new de.Cancel(); parent_cancel.close(); const child_cancel = parent_cancel.create(); @@ -182,10 +183,10 @@ describe( 'de.Cancel', () => { } ); parent_cancel.cancel( error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); - test( 'child closed if parent was closed #2', () => { + it( 'child closed if parent was closed #2', () => { const parent_cancel = new de.Cancel(); parent_cancel.close(); const child_cancel = parent_cancel.create(); @@ -198,10 +199,10 @@ describe( 'de.Cancel', () => { } ); child_cancel.cancel( error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); - test( 'child cancelled if parent was cancelled #1', () => { + it( 'child cancelled if parent was cancelled #1', () => { const parent_cancel = new de.Cancel(); const error = de.error( { id: 'SOME_ERROR', diff --git a/tests/first_block.test.js b/tests/first_block.test.js index 37e1686..1d27f61 100644 --- a/tests/first_block.test.js +++ b/tests/first_block.test.js @@ -27,7 +27,7 @@ describe( 'de.first', () => { expect( result ).toBe( result_1 ); expect( spy_1.mock.calls[ 0 ][ 0 ].deps.prev ).toEqual( [] ); - expect( spy_2.mock.calls.length ).toEqual( 0 ); + expect( spy_2.mock.calls ).toHaveLength( 0 ); } ); it( 'first block throws', async () => { @@ -60,7 +60,7 @@ describe( 'de.first', () => { const result = await de.run( block ); expect( result ).toBe( result_2 ); - expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev.length ).toBe( 1 ); + expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev ).toHaveLength( 1 ); expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev[ 0 ] ).toBe( error_1 ); } ); @@ -97,7 +97,7 @@ describe( 'de.first', () => { } catch ( e ) { expect( de.is_error( e ) ).toBe( true ); expect( e.error.id ).toBe( de.ERROR_ID.ALL_BLOCKS_FAILED ); - expect( e.error.reason.length ).toBe( 2 ); + expect( e.error.reason ).toHaveLength( 2 ); expect( e.error.reason[ 0 ] ).toBe( error_1 ); expect( e.error.reason[ 1 ] ).toBe( error_2 ); } diff --git a/tests/function_block.test.js b/tests/function_block.test.js index 960dfd0..3eef9c1 100644 --- a/tests/function_block.test.js +++ b/tests/function_block.test.js @@ -11,7 +11,7 @@ const { describe( 'de.func', () => { - test( 'resolves with value', async () => { + it( 'resolves with value', async () => { const data = { foo: 42, }; @@ -23,7 +23,7 @@ describe( 'de.func', () => { expect( result ).toBe( data ); } ); - test( 'resolves with promise', async () => { + it( 'resolves with promise', async () => { const data = { foo: 42, }; @@ -39,7 +39,7 @@ describe( 'de.func', () => { expect( result ).toBe( data ); } ); - test( 'resolves with block', async () => { + it( 'resolves with block', async () => { const data = { foo: 42, }; @@ -53,7 +53,7 @@ describe( 'de.func', () => { } ); // Самый простой способ вычислить факториал! - test( 'recursion', async () => { + it( 'recursion', async () => { const block = de.func( { block: ( { params } ) => { if ( params.n === 1 ) { @@ -83,7 +83,7 @@ describe( 'de.func', () => { expect( result ).toBe( 120 ); } ); - test( 'rejects with de.error', async () => { + it( 'rejects with de.error', async () => { const error = de.error( { id: 'SOME_ERROR', } ); @@ -100,7 +100,7 @@ describe( 'de.func', () => { } ); - test( 'cancellable', async () => { + it( 'cancellable', async () => { const block = get_result_block( null, 100 ); const cancel = new de.Cancel(); diff --git a/tests/http_block.test.js b/tests/http_block.test.js index 9577f4a..296504c 100644 --- a/tests/http_block.test.js +++ b/tests/http_block.test.js @@ -1246,8 +1246,8 @@ describe( 'http', () => { await de.run( block ); - expect( spy_1.mock.calls.length ).toBe( 0 ); - expect( spy_2.mock.calls.length ).toBe( 1 ); + expect( spy_1.mock.calls ).toHaveLength( 0 ); + expect( spy_2.mock.calls ).toHaveLength( 1 ); } ); it( 'default parse_body', async () => { diff --git a/tests/object_block.test.js b/tests/object_block.test.js index efc3b51..1a1e4d4 100644 --- a/tests/object_block.test.js +++ b/tests/object_block.test.js @@ -184,7 +184,7 @@ describe( 'de.object', () => { } } ); - it( 'two subblocks, one required failed #1', async () => { + it( 'two subblocks, one required failed #2', async () => { const error_foo = de.error( { id: 'SOME_ERROR', } ); @@ -312,7 +312,7 @@ describe( 'de.object', () => { } catch ( e ) { expect( e ).toBe( abort_error ); - expect( action_foo_spy.mock.calls.length ).toBe( 0 ); + expect( action_foo_spy.mock.calls ).toHaveLength( 0 ); expect( action_bar_spy.mock.calls[ 0 ][ 0 ] ).toBe( abort_error ); } } ); diff --git a/tests/options.after.test.js b/tests/options.after.test.js index 4c13018..602430e 100644 --- a/tests/options.after.test.js +++ b/tests/options.after.test.js @@ -49,7 +49,7 @@ describe( 'options.after', () => { await de.run( block ); } catch ( e ) { - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -67,7 +67,7 @@ describe( 'options.after', () => { const result = await de.run( block ); expect( result ).toBe( after_result ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'after throws', async () => { @@ -262,7 +262,7 @@ describe( 'options.after', () => { } catch ( e ) { expect( e ).toBe( error ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } } ); @@ -285,7 +285,7 @@ describe( 'options.after', () => { await de.run( child ); const calls = spy.mock.calls; - expect( calls.length ).toBe( 2 ); + expect( calls ).toHaveLength( 2 ); expect( calls[ 0 ][ 0 ] ).toBe( 'PARENT' ); expect( calls[ 1 ][ 0 ] ).toBe( 'CHILD' ); } ); @@ -314,7 +314,7 @@ describe( 'options.after', () => { } catch ( e ) { expect( e ).toBe( parent_after_error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); diff --git a/tests/options.before.test.js b/tests/options.before.test.js index 6a91e14..0c9b6e2 100644 --- a/tests/options.before.test.js +++ b/tests/options.before.test.js @@ -40,7 +40,7 @@ describe( 'options.before', () => { const result = await de.run( block ); expect( result ).toBe( before_result ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); it( 'before throws, action never called', async () => { @@ -62,7 +62,7 @@ describe( 'options.before', () => { } catch ( e ) { expect( e ).toBe( before_error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -83,7 +83,7 @@ describe( 'options.before', () => { } catch ( e ) { expect( e ).toBe( before_error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -141,7 +141,7 @@ describe( 'options.before', () => { const result = await de.run( block ); expect( result ).toBe( before_result ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); it( 'before returns undefined', async () => { @@ -210,7 +210,7 @@ describe( 'options.before', () => { await de.run( child ); const calls = spy.mock.calls; - expect( calls.length ).toBe( 2 ); + expect( calls ).toHaveLength( 2 ); expect( calls[ 0 ][ 0 ] ).toBe( 'CHILD' ); expect( calls[ 1 ][ 0 ] ).toBe( 'PARENT' ); } ); @@ -231,7 +231,7 @@ describe( 'options.before', () => { const result = await de.run( child ); expect( result ).toBe( child_before_result ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); it.each( [ null, false, 0, '', 42, 'foo', {} ] )( 'child returns undefined, parent returns %j', async ( parent_before_result ) => { @@ -321,7 +321,7 @@ describe( 'options.before', () => { } catch ( e ) { expect( e ).toBe( child_before_error ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); diff --git a/tests/options.cache.test.js b/tests/options.cache.test.js index 218a408..7b25d33 100644 --- a/tests/options.cache.test.js +++ b/tests/options.cache.test.js @@ -71,7 +71,7 @@ describe( 'options.cache, options.key, options.maxage', () => { expect( result_1 ).toBe( block_value ); expect( result_2 ).toBe( block_value ); - expect( spy.mock.calls.length ).toBe( 2 ); + expect( spy.mock.calls ).toHaveLength( 2 ); } ); @@ -95,7 +95,7 @@ describe( 'options.cache, options.key, options.maxage', () => { expect( result_1 ).toBe( block_value ); expect( result_2 ).toBe( block_value ); - expect( spy.mock.calls.length ).toBe( 2 ); + expect( spy.mock.calls ).toHaveLength( 2 ); } ); @@ -121,7 +121,7 @@ describe( 'options.cache, options.key, options.maxage', () => { expect( result_1 ).toBe( block_value ); expect( result_2 ).toBe( block_value ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'key is a function, cache expired, real second run', async () => { @@ -144,7 +144,7 @@ describe( 'options.cache, options.key, options.maxage', () => { await de.run( block ); - expect( spy.mock.calls.length ).toBe( 2 ); + expect( spy.mock.calls ).toHaveLength( 2 ); } ); it( 'key is a function and returns undefined', async () => { @@ -166,7 +166,7 @@ describe( 'options.cache, options.key, options.maxage', () => { const result = await de.run( block ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); expect( result ).toBe( data ); } ); @@ -191,7 +191,7 @@ describe( 'options.cache, options.key, options.maxage', () => { expect( result_1 ).toBe( block_value ); expect( result_2 ).toBe( block_value ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'cache.get throws', async () => { @@ -214,7 +214,7 @@ describe( 'options.cache, options.key, options.maxage', () => { await de.run( block ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'cache.get returns promise that rejects, block has deps', async () => { @@ -259,7 +259,7 @@ describe( 'options.cache, options.key, options.maxage', () => { const r = await de.run( block ); expect( r ).toEqual( { foo: null, bar: null } ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'cache.set throws', async () => { @@ -279,7 +279,9 @@ describe( 'options.cache, options.key, options.maxage', () => { }, } ); - await de.run( block ); + await expect( async () => { + await de.run( block ); + } ).not.toThrow(); } ); it( 'cache.get returns rejected promise', async () => { @@ -302,7 +304,7 @@ describe( 'options.cache, options.key, options.maxage', () => { await de.run( block ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } ); it( 'cache.set returns rejected promise', async () => { @@ -322,7 +324,9 @@ describe( 'options.cache, options.key, options.maxage', () => { }, } ); - await de.run( block ); + await expect( async () => { + await de.run( block ); + } ).not.toThrow(); } ); } ); diff --git a/tests/options.deps.test.js b/tests/options.deps.test.js index b2c9e55..1d3e30d 100644 --- a/tests/options.deps.test.js +++ b/tests/options.deps.test.js @@ -150,7 +150,7 @@ describe( 'options.deps', () => { const calls = spy.mock.calls; - expect( calls.length ).toBe( 2 ); + expect( calls ).toHaveLength( 2 ); expect( calls[ 0 ][ 0 ] ).toBe( 'FOO' ); expect( calls[ 1 ][ 0 ] ).toBe( 'BAR' ); } ); @@ -186,7 +186,7 @@ describe( 'options.deps', () => { const calls = spy.mock.calls; - expect( calls.length ).toBe( 2 ); + expect( calls ).toHaveLength( 2 ); expect( calls[ 0 ][ 0 ] ).toBe( 'FOO' ); expect( calls[ 1 ][ 0 ] ).toBe( 'BAR' ); } ); @@ -230,7 +230,7 @@ describe( 'options.deps', () => { const calls = spy.mock.calls; - expect( calls.length ).toBe( 3 ); + expect( calls ).toHaveLength( 3 ); expect( calls[ 0 ][ 0 ] ).toBe( 'FOO' ); expect( calls[ 1 ][ 0 ] ).toBe( 'BAR' ); expect( calls[ 2 ][ 0 ] ).toBe( 'QUU' ); @@ -274,7 +274,7 @@ describe( 'options.deps', () => { const calls = spy.mock.calls; - expect( calls.length ).toBe( 3 ); + expect( calls ).toHaveLength( 3 ); expect( calls[ 2 ][ 0 ] ).toBe( 'QUU' ); } ); @@ -315,7 +315,7 @@ describe( 'options.deps', () => { const calls = spy.mock.calls; - expect( calls.length ).toBe( 3 ); + expect( calls ).toHaveLength( 3 ); expect( calls[ 0 ][ 0 ] ).toBe( 'FOO' ); expect( calls[ 1 ][ 0 ] ).toBe( 'BAR' ); expect( calls[ 2 ][ 0 ] ).toBe( 'QUU' ); diff --git a/tests/options.error.test.js b/tests/options.error.test.js index de9a704..b07b47c 100644 --- a/tests/options.error.test.js +++ b/tests/options.error.test.js @@ -47,7 +47,7 @@ describe( 'options.error', () => { await de.run( block ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); it( 'returns another error', async () => { @@ -92,7 +92,7 @@ describe( 'options.error', () => { } catch ( e ) { expect( de.is_error( e ) ).toBe( true ); expect( e.error.id ).toBe( 'ReferenceError' ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } } ); @@ -120,7 +120,7 @@ describe( 'options.error', () => { } catch ( e ) { expect( e ).toBe( error_2 ); - expect( spy.mock.calls.length ).toBe( 1 ); + expect( spy.mock.calls ).toHaveLength( 1 ); } } ); @@ -173,7 +173,7 @@ describe( 'options.error', () => { const result = await de.run( block_2 ); expect( result ).toBe( value ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } ); it( 'first throws, second gets error from first', async () => { diff --git a/tests/options.params.test.js b/tests/options.params.test.js index d156e49..72d20b8 100644 --- a/tests/options.params.test.js +++ b/tests/options.params.test.js @@ -92,7 +92,7 @@ describe( 'options.params', () => { } catch ( e ) { expect( de.is_error( e ) ).toBe( true ); expect( e.error.id ).toBe( de.ERROR_ID.INVALID_OPTIONS_PARAMS ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); diff --git a/tests/pipe_block.test.js b/tests/pipe_block.test.js index edadc9d..bb47410 100644 --- a/tests/pipe_block.test.js +++ b/tests/pipe_block.test.js @@ -43,9 +43,9 @@ describe( 'de.pipe', () => { const result = await de.run( block ); expect( spy_1.mock.calls[ 0 ][ 0 ].deps.prev ).toEqual( [] ); - expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev.length ).toBe( 1 ); + expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev ).toHaveLength( 1 ); expect( spy_2.mock.calls[ 0 ][ 0 ].deps.prev[ 0 ] ).toBe( result_1 ); - expect( spy_3.mock.calls[ 0 ][ 0 ].deps.prev.length ).toBe( 2 ); + expect( spy_3.mock.calls[ 0 ][ 0 ].deps.prev ).toHaveLength( 2 ); expect( spy_3.mock.calls[ 0 ][ 0 ].deps.prev[ 0 ] ).toBe( result_1 ); expect( spy_3.mock.calls[ 0 ][ 0 ].deps.prev[ 1 ] ).toBe( result_2 ); expect( spy_1.mock.calls[ 0 ][ 0 ].deps.prev ).not.toBe( spy_2.mock.calls[ 0 ][ 0 ].deps.prev ); @@ -79,7 +79,7 @@ describe( 'de.pipe', () => { } catch ( e ) { expect( e ).toBe( error ); - expect( spy_2.mock.calls.length ).toBe( 0 ); + expect( spy_2.mock.calls ).toHaveLength( 0 ); } } ); @@ -109,7 +109,7 @@ describe( 'de.pipe', () => { } catch ( e ) { expect( e ).toBe( error ); - expect( spy_1.mock.calls.length ).toBe( 1 ); + expect( spy_1.mock.calls ).toHaveLength( 1 ); } } ); diff --git a/tests/request.test.js b/tests/request.test.js index f58cda7..41b8c3e 100644 --- a/tests/request.test.js +++ b/tests/request.test.js @@ -466,7 +466,7 @@ describe( 'request', () => { } catch ( error ) { expect( de.is_error( error ) ).toBe( true ); expect( error.error.status_code ).toBe( status_code ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -518,7 +518,7 @@ describe( 'request', () => { } catch ( error ) { expect( de.is_error( error ) ).toBe( true ); expect( error.error.status_code ).toBe( status_code ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -546,7 +546,7 @@ describe( 'request', () => { } catch ( error ) { expect( de.is_error( error ) ).toBe( true ); expect( error.error.status_code ).toBe( status_code ); - expect( spy.mock.calls.length ).toBe( 0 ); + expect( spy.mock.calls ).toHaveLength( 0 ); } } ); @@ -832,7 +832,7 @@ describe( 'request', () => { expect( result2.timestamps.socket === result2.timestamps.tcp_connection ).toBe( true ); } ); - it( 'is an object', async () => { + it( 'is an http.Agent instance', async () => { const path = get_path(); fake.add( path, { diff --git a/tests/strip_null_and_undefined_values.test.js b/tests/strip_null_and_undefined_values.test.js index a08a9c3..437ec0e 100644 --- a/tests/strip_null_and_undefined_values.test.js +++ b/tests/strip_null_and_undefined_values.test.js @@ -2,7 +2,7 @@ const strip_null_and_undefined_values = require( '../lib/strip_null_and_undefine describe( 'strip_null_and_undefined_values', () => { - test( 'returns copy', () => { + it( 'returns copy', () => { const obj = { a: 'a', b: 'b', @@ -13,7 +13,7 @@ describe( 'strip_null_and_undefined_values', () => { expect( stripped ).not.toBe( obj ); } ); - test( 'strip null and undefined', () => { + it( 'strip null and undefined', () => { const obj = { a: undefined, b: null,