From 335472badbb2672ed0964a2414f9e839475f5086 Mon Sep 17 00:00:00 2001 From: Mehdi <9340937+meduzen@users.noreply.github.com> Date: Mon, 8 Apr 2024 22:34:42 +0200 Subject: [PATCH] Lint tests using `eslint-vitest-plugin` Also adds commented `all` Vitest ESLintconfig for later testing purpose. --- eslint.config.js | 19 ++++++- package.json | 3 +- pnpm-lock.yaml | 120 ++++++++++++++++++++++++++------------------ tests/index.test.js | 6 +-- 4 files changed, 95 insertions(+), 53 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 16718af..7a2b32a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,9 +1,9 @@ import tseslint from 'typescript-eslint' import js from '@eslint/js' +import vitest from 'eslint-plugin-vitest' export default tseslint.config( js.configs.recommended, - { files: ['**/*.js'], languageOptions: { @@ -64,4 +64,21 @@ export default tseslint.config( 'template-tag-spacing': [2, 'always'], }, }, + { + files: ['**/*.test.js'], + plugins: { vitest }, + rules: { + ...vitest.configs.recommended.rules, + // ...vitest.configs.all.rules, // worth testing from time to timeā€¦ + // 'vitest/consistent-test-it': 0, + 'vitest/no-test-return-statement': 1, + // 'vitest/prefer-expect-assertions': 0, // when testing `vitest.configs.all.rules` + 'vitest/require-to-throw-message': 1, + }, + languageOptions: { + globals: { + ...vitest.environments.env.globals, + }, + }, + }, ) diff --git a/package.json b/package.json index 2c54400..59b7870 100644 --- a/package.json +++ b/package.json @@ -54,10 +54,11 @@ "@vitest/coverage-v8": "^1.4.0", "@vitest/ui": "^1.4.0", "eslint": "^9.0.0", + "eslint-plugin-vitest": "0.4.2-beta.5", "size-limit": "^11.1.2", "tsd": "^0.31.0", "typescript": "^5.4.4", - "typescript-eslint": "^7.5.0", + "typescript-eslint": "^7.6.0", "vitest": "^1.4.0" }, "pnpm": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9832928..bb37ead 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,6 +24,9 @@ devDependencies: eslint: specifier: ^9.0.0 version: 9.0.0 + eslint-plugin-vitest: + specifier: 0.4.2-beta.5 + version: 0.4.2-beta.5(eslint@9.0.0)(typescript@5.4.4)(vitest@1.4.0) size-limit: specifier: ^11.1.2 version: 11.1.2 @@ -34,8 +37,8 @@ devDependencies: specifier: ^5.4.4 version: 5.4.4 typescript-eslint: - specifier: ^7.5.0 - version: 7.5.0(eslint@9.0.0)(typescript@5.4.4) + specifier: ^7.6.0 + version: 7.6.0(eslint@9.0.0)(typescript@5.4.4) vitest: specifier: ^1.4.0 version: 1.4.0(@vitest/ui@1.4.0) @@ -576,7 +579,7 @@ packages: size-limit: 11.1.2 dependencies: esbuild: 0.20.2 - nanoid: 5.0.6 + nanoid: 5.0.7 size-limit: 11.1.2 dev: true @@ -635,8 +638,8 @@ packages: resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} dev: true - /@typescript-eslint/eslint-plugin@7.5.0(@typescript-eslint/parser@7.5.0)(eslint@9.0.0)(typescript@5.4.4): - resolution: {integrity: sha512-HpqNTH8Du34nLxbKgVMGljZMG0rJd2O9ecvr2QLYp+7512ty1j42KnsFwspPXg1Vh8an9YImf6CokUBltisZFQ==} + /@typescript-eslint/eslint-plugin@7.6.0(@typescript-eslint/parser@7.6.0)(eslint@9.0.0)(typescript@5.4.4): + resolution: {integrity: sha512-gKmTNwZnblUdnTIJu3e9kmeRRzV2j1a/LUO27KNNAnIC5zjy1aSvXSRp4rVNlmAoHlQ7HzX42NbKpcSr4jF80A==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: '@typescript-eslint/parser': ^7.0.0 @@ -647,11 +650,11 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.5.0(eslint@9.0.0)(typescript@5.4.4) - '@typescript-eslint/scope-manager': 7.5.0 - '@typescript-eslint/type-utils': 7.5.0(eslint@9.0.0)(typescript@5.4.4) - '@typescript-eslint/utils': 7.5.0(eslint@9.0.0)(typescript@5.4.4) - '@typescript-eslint/visitor-keys': 7.5.0 + '@typescript-eslint/parser': 7.6.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/scope-manager': 7.6.0 + '@typescript-eslint/type-utils': 7.6.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/utils': 7.6.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/visitor-keys': 7.6.0 debug: 4.3.4 eslint: 9.0.0 graphemer: 1.4.0 @@ -664,8 +667,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@7.5.0(eslint@9.0.0)(typescript@5.4.4): - resolution: {integrity: sha512-cj+XGhNujfD2/wzR1tabNsidnYRaFfEkcULdcIyVBYcXjBvBKOes+mpMBP7hMpOyk+gBcfXsrg4NBGAStQyxjQ==} + /@typescript-eslint/parser@7.6.0(eslint@9.0.0)(typescript@5.4.4): + resolution: {integrity: sha512-usPMPHcwX3ZoPWnBnhhorc14NJw9J4HpSXQX4urF2TPKG0au0XhJoZyX62fmvdHONUkmyUe74Hzm1//XA+BoYg==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 @@ -674,10 +677,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 7.5.0 - '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) - '@typescript-eslint/visitor-keys': 7.5.0 + '@typescript-eslint/scope-manager': 7.6.0 + '@typescript-eslint/types': 7.6.0 + '@typescript-eslint/typescript-estree': 7.6.0(typescript@5.4.4) + '@typescript-eslint/visitor-keys': 7.6.0 debug: 4.3.4 eslint: 9.0.0 typescript: 5.4.4 @@ -685,16 +688,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager@7.5.0: - resolution: {integrity: sha512-Z1r7uJY0MDeUlql9XJ6kRVgk/sP11sr3HKXn268HZyqL7i4cEfrdFuSSY/0tUqT37l5zT0tJOsuDP16kio85iA==} + /@typescript-eslint/scope-manager@7.6.0: + resolution: {integrity: sha512-ngttyfExA5PsHSx0rdFgnADMYQi+Zkeiv4/ZxGYUWd0nLs63Ha0ksmp8VMxAIC0wtCFxMos7Lt3PszJssG/E6w==} engines: {node: ^18.18.0 || >=20.0.0} dependencies: - '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/visitor-keys': 7.5.0 + '@typescript-eslint/types': 7.6.0 + '@typescript-eslint/visitor-keys': 7.6.0 dev: true - /@typescript-eslint/type-utils@7.5.0(eslint@9.0.0)(typescript@5.4.4): - resolution: {integrity: sha512-A021Rj33+G8mx2Dqh0nMO9GyjjIBK3MqgVgZ2qlKf6CJy51wY/lkkFqq3TqqnH34XyAHUkq27IjlUkWlQRpLHw==} + /@typescript-eslint/type-utils@7.6.0(eslint@9.0.0)(typescript@5.4.4): + resolution: {integrity: sha512-NxAfqAPNLG6LTmy7uZgpK8KcuiS2NZD/HlThPXQRGwz6u7MDBWRVliEEl1Gj6U7++kVJTpehkhZzCJLMK66Scw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 @@ -703,8 +706,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) - '@typescript-eslint/utils': 7.5.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/typescript-estree': 7.6.0(typescript@5.4.4) + '@typescript-eslint/utils': 7.6.0(eslint@9.0.0)(typescript@5.4.4) debug: 4.3.4 eslint: 9.0.0 ts-api-utils: 1.3.0(typescript@5.4.4) @@ -713,13 +716,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types@7.5.0: - resolution: {integrity: sha512-tv5B4IHeAdhR7uS4+bf8Ov3k793VEVHd45viRRkehIUZxm0WF82VPiLgHzA/Xl4TGPg1ZD49vfxBKFPecD5/mg==} + /@typescript-eslint/types@7.6.0: + resolution: {integrity: sha512-h02rYQn8J+MureCvHVVzhl69/GAfQGPQZmOMjG1KfCl7o3HtMSlPaPUAPu6lLctXI5ySRGIYk94clD/AUMCUgQ==} engines: {node: ^18.18.0 || >=20.0.0} dev: true - /@typescript-eslint/typescript-estree@7.5.0(typescript@5.4.4): - resolution: {integrity: sha512-YklQQfe0Rv2PZEueLTUffiQGKQneiIEKKnfIqPIOxgM9lKSZFCjT5Ad4VqRKj/U4+kQE3fa8YQpskViL7WjdPQ==} + /@typescript-eslint/typescript-estree@7.6.0(typescript@5.4.4): + resolution: {integrity: sha512-+7Y/GP9VuYibecrCQWSKgl3GvUM5cILRttpWtnAu8GNL9j11e4tbuGZmZjJ8ejnKYyBRb2ddGQ3rEFCq3QjMJw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: typescript: '*' @@ -727,12 +730,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/visitor-keys': 7.5.0 + '@typescript-eslint/types': 7.6.0 + '@typescript-eslint/visitor-keys': 7.6.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 - minimatch: 9.0.3 + minimatch: 9.0.4 semver: 7.6.0 ts-api-utils: 1.3.0(typescript@5.4.4) typescript: 5.4.4 @@ -740,8 +743,8 @@ packages: - supports-color dev: true - /@typescript-eslint/utils@7.5.0(eslint@9.0.0)(typescript@5.4.4): - resolution: {integrity: sha512-3vZl9u0R+/FLQcpy2EHyRGNqAS/ofJ3Ji8aebilfJe+fobK8+LbIFmrHciLVDxjDoONmufDcnVSF38KwMEOjzw==} + /@typescript-eslint/utils@7.6.0(eslint@9.0.0)(typescript@5.4.4): + resolution: {integrity: sha512-x54gaSsRRI+Nwz59TXpCsr6harB98qjXYzsRxGqvA5Ue3kQH+FxS7FYU81g/omn22ML2pZJkisy6Q+ElK8pBCA==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 @@ -749,9 +752,9 @@ packages: '@eslint-community/eslint-utils': 4.4.0(eslint@9.0.0) '@types/json-schema': 7.0.15 '@types/semver': 7.5.8 - '@typescript-eslint/scope-manager': 7.5.0 - '@typescript-eslint/types': 7.5.0 - '@typescript-eslint/typescript-estree': 7.5.0(typescript@5.4.4) + '@typescript-eslint/scope-manager': 7.6.0 + '@typescript-eslint/types': 7.6.0 + '@typescript-eslint/typescript-estree': 7.6.0(typescript@5.4.4) eslint: 9.0.0 semver: 7.6.0 transitivePeerDependencies: @@ -759,11 +762,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys@7.5.0: - resolution: {integrity: sha512-mcuHM/QircmA6O7fy6nn2w/3ditQkj+SgtOc8DW3uQ10Yfj42amm2i+6F2K4YAOPNNTmE6iM1ynM6lrSwdendA==} + /@typescript-eslint/visitor-keys@7.6.0: + resolution: {integrity: sha512-4eLB7t+LlNUmXzfOu1VAIAdkjbu5xNSerURS9X/S5TUKWFRpXRQZbmtPqgKmYx8bj3J0irtQXSiWAOY82v+cgw==} engines: {node: ^18.18.0 || >=20.0.0} dependencies: - '@typescript-eslint/types': 7.5.0 + '@typescript-eslint/types': 7.6.0 eslint-visitor-keys: 3.4.3 dev: true @@ -1190,6 +1193,27 @@ packages: supports-hyperlinks: 2.3.0 dev: true + /eslint-plugin-vitest@0.4.2-beta.5(eslint@9.0.0)(typescript@5.4.4)(vitest@1.4.0): + resolution: {integrity: sha512-+KgsqDasq94KUNc0qHw9J5sPmuPdRqwkSSXfSbboYPFasWwdoxixR0ArQt4CTjER2j9tRik4Kd6Ldf4aMFb0JA==} + engines: {node: ^18.0.0 || >= 20.0.0} + peerDependencies: + '@typescript-eslint/eslint-plugin': '*' + eslint: ^8.57.0 || ^9.0.0 + vitest: '*' + peerDependenciesMeta: + '@typescript-eslint/eslint-plugin': + optional: true + vitest: + optional: true + dependencies: + '@typescript-eslint/utils': 7.6.0(eslint@9.0.0)(typescript@5.4.4) + eslint: 9.0.0 + vitest: 1.4.0(@vitest/ui@1.4.0) + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /eslint-rule-docs@1.1.235: resolution: {integrity: sha512-+TQ+x4JdTnDoFEXXb3fDvfGOwnyNV7duH8fXWTPD1ieaBmB8omj7Gw/pMBBu4uI2uJCCU8APDaQJzWuXnTsH4A==} dev: true @@ -1846,8 +1870,8 @@ packages: brace-expansion: 1.1.11 dev: true - /minimatch@9.0.3: - resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + /minimatch@9.0.4: + resolution: {integrity: sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==} engines: {node: '>=16 || 14 >=14.17'} dependencies: brace-expansion: 2.0.1 @@ -1886,8 +1910,8 @@ packages: hasBin: true dev: true - /nanoid@5.0.6: - resolution: {integrity: sha512-rRq0eMHoGZxlvaFOUdK1Ev83Bd1IgzzR+WJ3IbDJ7QOSdAxYjlurSPqFs9s4lJg29RT6nPwizFtJhQS6V5xgiA==} + /nanoid@5.0.7: + resolution: {integrity: sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==} engines: {node: ^18 || >=20} hasBin: true dev: true @@ -2478,8 +2502,8 @@ packages: engines: {node: '>=8'} dev: true - /typescript-eslint@7.5.0(eslint@9.0.0)(typescript@5.4.4): - resolution: {integrity: sha512-eKhF39LRi2xYvvXh3h3S+mCxC01dZTIZBlka25o39i81VeQG+OZyfC4i2GEDspNclMRdXkg9uGhmvWMhjph2XQ==} + /typescript-eslint@7.6.0(eslint@9.0.0)(typescript@5.4.4): + resolution: {integrity: sha512-LY6vH6F1l5jpGqRtU+uK4+mOecIb4Cd4kaz1hAiJrgnNiHUA8wiw8BkJyYS+MRLM69F1QuSKwtGlQqnGl1Rc6w==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 @@ -2488,9 +2512,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 7.5.0(@typescript-eslint/parser@7.5.0)(eslint@9.0.0)(typescript@5.4.4) - '@typescript-eslint/parser': 7.5.0(eslint@9.0.0)(typescript@5.4.4) - '@typescript-eslint/utils': 7.5.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/eslint-plugin': 7.6.0(@typescript-eslint/parser@7.6.0)(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/parser': 7.6.0(eslint@9.0.0)(typescript@5.4.4) + '@typescript-eslint/utils': 7.6.0(eslint@9.0.0)(typescript@5.4.4) eslint: 9.0.0 typescript: 5.4.4 transitivePeerDependencies: diff --git a/tests/index.test.js b/tests/index.test.js index 6a68711..dd8a0d4 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -111,10 +111,10 @@ describe('duration', () => { const durationInDays = { d: 43 } test('is a function', () => expect(duration).toBeInstanceOf(Function)) - test('()', () => expect(() => duration(null)).toThrow()) + test('(null)', () => expect(() => duration(null)).toThrow(Error)) test('()', () => expect(duration()).toBe('PT0S')) test('empty object {}', () => expect(duration({})).toBe('PT0S')) - test('empty object {}', () => expect(duration({}, false)).toBe('PT0S')) + test('empty object {} and preserve excess value', () => expect(duration({}, false)).toBe('PT0S')) test('complete object', () => expect(duration(durationObject)).toBe('P3W5DT10H43M2.61S')) test('complete object with too high values', () => expect(duration(durationWithTooHighValues)).toBe('P5W6DT12H55M55.3S')) @@ -257,7 +257,7 @@ describe('DateTime class', () => { test(".to('month')", () => expect(twoWeeksAfterSummer.to('month')).toBe('2021-07')) test('weeks is changed when day changes', () => { summer.setDate(summer.getDate() + 14) - return expect(summer.getWeek()).toBe(29) + expect(summer.getWeek()).toBe(29) }) })