From 6a7be2746761df3b8d00ae537ca8c2d6092be3a5 Mon Sep 17 00:00:00 2001 From: Maksim Shylau Date: Sun, 28 Jun 2026 21:37:42 +0200 Subject: [PATCH] fix: lib bugs, drop dead import, add lightweight tooling - errors.js: NotImplementedError now respects the message argument that every stub passes (was hardcoded and ignored) - optional-test-extension.js: return the test callback's promise so async test failures are awaited by node:test instead of leaking - simple-chain.js: remove broken `decorateObject` import (not exported by lib, never used) - package.json: drop bogus `main: index.js` (no such file) - add .nvmrc, .editorconfig and a CI workflow running `npm test` Co-Authored-By: Claude Opus 4.8 --- .editorconfig | 13 +++++++++++++ .github/workflows/test.yml | 16 ++++++++++++++++ .nvmrc | 1 + lib/errors.js | 4 ++-- lib/optional-test-extension.js | 8 +++----- package.json | 1 - src/simple-chain.js | 1 - 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/test.yml create mode 100644 .nvmrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..bebb3456b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# https://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..5a0e69cdf9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: test + +on: + push: + branches: [master] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: npm test diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000000..2bd5a0a98a --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/lib/errors.js b/lib/errors.js index fa614231a9..919fd002e0 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -35,8 +35,8 @@ const isNotThrowingErrors = function (testFuncs) { const isNotImplementedError = (err) => err instanceof NotImplementedError; class NotImplementedError extends Error { - constructor() { - super('Not implemented'); + constructor(message = 'Not implemented') { + super(message); } } diff --git a/lib/optional-test-extension.js b/lib/optional-test-extension.js index a9499852df..ed8a652841 100644 --- a/lib/optional-test-extension.js +++ b/lib/optional-test-extension.js @@ -4,18 +4,16 @@ const { isNotImplementedError } = require('./errors.js'); function optionalTestExtension(title, cb, isAsyncTest) { test(title, (t) => { if (isAsyncTest) { - runAsyncTestCb(cb, t, title); - } else { - runSyncTestCb(cb, t, title); + return runAsyncTestCb(cb, t, title); } + return runSyncTestCb(cb, t, title); }); } -const runAsyncTestCb = (cb, t, title) => { +const runAsyncTestCb = (cb, t, title) => cb.call(t).catch((err) => { handleTestError(t, title, err); }); -}; const runSyncTestCb = (cb, t, title) => { try { diff --git a/package.json b/package.json index f30009c0b0..744c94fdf5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "basic-js", "version": "1.0.0", "description": "Tasks for mastering basics of JavaScript", - "main": "index.js", "engines": { "node": ">=22", "npm": ">=10" diff --git a/src/simple-chain.js b/src/simple-chain.js index 0a56326616..305c3146ff 100644 --- a/src/simple-chain.js +++ b/src/simple-chain.js @@ -1,4 +1,3 @@ -const { decorateObject } = require('../lib'); const { NotImplementedError } = require('../lib'); /**