Просмотр исходного кода

chore: removes rimraf and updates tests

e22m4u 2 недель назад
Родитель
Сommit
8fe2662f79
5 измененных файлов с 11 добавлено и 6 удалено
  1. 3 0
      build-cjs.js
  2. 1 1
      dist/cjs/index.cjs
  3. 1 2
      package.json
  4. 2 1
      src/create-spy.js
  5. 4 2
      src/create-spy.spec.js

+ 3 - 0
build-cjs.js

@@ -1,6 +1,9 @@
+import {rmSync} from 'node:fs';
 import * as esbuild from 'esbuild';
 import packageJson from './package.json' with {type: 'json'};
 
+rmSync('./dist/cjs', {recursive: true, force: true});
+
 await esbuild.build({
   entryPoints: ['src/index.js'],
   outfile: 'dist/cjs/index.cjs',

+ 1 - 1
dist/cjs/index.cjs

@@ -75,7 +75,7 @@ function _parseSpyArgs(target, methodNameOrImplFromSpy, customImplForMethodFromS
     }
     if (methodNameOrImplFromSpy === void 0 && typeof target !== "function") {
       throw new TypeError(
-        `Attempted to spy on a ${typeof target} which is not a function.`
+        "Attempted to spy on a non-function value. To spy on an object method, you must provide the method name as the second argument."
       );
     }
     throw new Error(

+ 1 - 2
package.json

@@ -33,7 +33,7 @@
     "format": "prettier --write \"./src/**/*.js\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha",
     "test:coverage": "npm run lint && c8 --reporter=text mocha",
-    "build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
+    "build:cjs": "node --no-warnings=ExperimentalWarning build-cjs.js",
     "prepare": "husky"
   },
   "devDependencies": {
@@ -51,7 +51,6 @@
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
     "prettier": "~3.6.2",
-    "rimraf": "~6.1.0",
     "typescript": "~5.9.3"
   }
 }

+ 2 - 1
src/create-spy.js

@@ -105,7 +105,8 @@ function _parseSpyArgs(
     // и имя метода не предоставлено
     if (methodNameOrImplFromSpy === undefined && typeof target !== 'function') {
       throw new TypeError(
-        `Attempted to spy on a ${typeof target} which is not a function.`,
+        'Attempted to spy on a non-function value. To spy on an object method, ' +
+          'you must provide the method name as the second argument.',
       );
     }
     // генерация общей ошибки для

+ 4 - 2
src/create-spy.spec.js

@@ -25,11 +25,13 @@ describe('createSpy', function () {
       // без указания имени метода
       expect(() => createSpy({})).to.throw(
         TypeError,
-        'Attempted to spy on a object which is not a function.',
+        'Attempted to spy on a non-function value. To spy on an object method, ' +
+          'you must provide the method name as the second argument.',
       );
       expect(() => createSpy(123)).to.throw(
         TypeError,
-        'Attempted to spy on a number which is not a function.',
+        'Attempted to spy on a non-function value. To spy on an object method, ' +
+          'you must provide the method name as the second argument.',
       );
     });