From bfff8122b67e40eb9f2d0f6abde9445333965228 Mon Sep 17 00:00:00 2001 From: Uiolee <22849383+uiolee@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:01:21 +0800 Subject: [PATCH] test: migrate to typescript & use chai@v5 (#177) --- .eslintrc => .eslintrc.json | 0 .mocharc.yml | 5 +++++ package.json | 25 +++++++++++++------------ test/{.eslintrc => .eslintrc.json} | 4 ++-- test/.mocharc.yml | 1 - test/{index.js => log.spec.ts} | 11 ++++------- tsconfig.json | 18 ++++++++---------- 7 files changed, 32 insertions(+), 32 deletions(-) rename .eslintrc => .eslintrc.json (100%) create mode 100644 .mocharc.yml rename test/{.eslintrc => .eslintrc.json} (78%) delete mode 100644 test/.mocharc.yml rename test/{index.js => log.spec.ts} (97%) diff --git a/.eslintrc b/.eslintrc.json similarity index 100% rename from .eslintrc rename to .eslintrc.json diff --git a/.mocharc.yml b/.mocharc.yml new file mode 100644 index 0000000..4f70d55 --- /dev/null +++ b/.mocharc.yml @@ -0,0 +1,5 @@ +reporter: spec +parallel: false +require: + - "ts-node/register" + - "chai/register-should.js" diff --git a/package.json b/package.json index 9631813..6388374 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,7 @@ "build": "tsc -b", "clean": "tsc -b --clean", "eslint": "eslint .", - "pretest": "npm run clean && npm run build", - "test": "mocha test/index.js --require ts-node/register", + "test": "mocha test/*.spec.ts", "test-cov": "nyc --reporter=lcovonly npm test" }, "files": [ @@ -31,17 +30,19 @@ ], "license": "MIT", "devDependencies": { - "@types/node": "^18.7.18", - "@types/rewire": "^2.5.28", - "chai": "^4.1.2", - "eslint": "^8.23.1", + "@types/chai": "^4.3.11", + "@types/mocha": "^10.0.6", + "@types/node": "^14.18.63", + "@types/rewire": "^2.5.30", + "chai": "^5.0.3", + "eslint": "^8.56.0", "eslint-config-hexo": "^5.0.0", - "mocha": "^10.0.0", - "nyc": "^15.0.0", - "rewire": "^6.0.0", - "sinon": "^15.0.2", - "ts-node": "^10.9.1", - "typescript": "^5.0.3" + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "rewire": "^7.0.0", + "sinon": "^17.0.1", + "ts-node": "^10.9.2", + "typescript": "^5.3.3" }, "engines": { "node": ">=14" diff --git a/test/.eslintrc b/test/.eslintrc.json similarity index 78% rename from test/.eslintrc rename to test/.eslintrc.json index 98f8095..7aacca6 100644 --- a/test/.eslintrc +++ b/test/.eslintrc.json @@ -1,7 +1,7 @@ { - "extends": "hexo/test", + "extends": "hexo/ts-test", "rules": { "@typescript-eslint/no-var-requires": 0, "@typescript-eslint/no-empty-function": 0 } -} \ No newline at end of file +} diff --git a/test/.mocharc.yml b/test/.mocharc.yml deleted file mode 100644 index 3b6c175..0000000 --- a/test/.mocharc.yml +++ /dev/null @@ -1 +0,0 @@ -reporter: spec diff --git a/test/index.js b/test/log.spec.ts similarity index 97% rename from test/index.js rename to test/log.spec.ts index 1a0fe18..9248169 100644 --- a/test/index.js +++ b/test/log.spec.ts @@ -1,8 +1,7 @@ -'use strict'; -require('chai').should(); -const rewire = require('rewire'); -const sinon = require('sinon'); +import rewire from 'rewire'; +import sinon from 'sinon'; +import { logger } from '../lib/log'; const noop = () => {}; const fakeConsole = { @@ -23,15 +22,13 @@ const fakeProcess = { } }; -/* eslint node/no-missing-require: 0 */ -const { logger } = require('../dist/log'); describe('hexo-log', () => { let loggerModule; beforeEach(() => { sinon.restore(); - loggerModule = rewire('../dist/log.js'); + loggerModule = rewire('../lib/log'); }); it('add alias for levels', () => { diff --git a/tsconfig.json b/tsconfig.json index 2680bd7..a644945 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,14 +6,12 @@ "outDir": "dist", "declaration": true, "esModuleInterop": true, - "types": [ - "node" - ] + "types": ["node"] }, - "include": [ - "lib/log.ts" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "include": ["lib/log.ts"], + "exclude": ["node_modules"], + "ts-node": { + "transpileOnly": true, + "compilerOptions": { "types": ["node", "mocha", "chai"] } + } +}