From 3933f0d7d29a658e129ec9ee2d8ce95bfe65df62 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Fri, 2 Feb 2024 00:35:40 +0800 Subject: [PATCH] test: migrate to ts --- .mocharc.yml | 9 +++++++++ package.json | 6 ++++-- test/.mocharc.yml | 1 - test/{index.js => index.ts} | 6 ++---- tsconfig.json | 21 +++++++++++---------- 5 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 .mocharc.yml delete mode 100644 test/.mocharc.yml rename test/{index.js => index.ts} (97%) diff --git a/.mocharc.yml b/.mocharc.yml new file mode 100644 index 0000000..17785de --- /dev/null +++ b/.mocharc.yml @@ -0,0 +1,9 @@ +reporter: spec +loader: + # - ts-node/esm +require: + - ts-node/register + - chai/register-should.js + +spec: ["test/*.ts"] +watch-files: ["lib"] diff --git a/package.json b/package.json index 7cc0d55..d2f85a1 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc -b", "clean": "tsc -b --clean", "eslint": "eslint .", - "test": "mocha test/index.js --require ts-node/register", + "test": "mocha", "test-cov": "c8 --reporter=lcovonly npm run test" }, "files": [ @@ -30,10 +30,12 @@ "js-yaml": "^4.1.0" }, "devDependencies": { + "@types/chai": "^4.3.11", "@types/js-yaml": "^4.0.5", + "@types/mocha": "^10.0.6", "@types/node": "^18.11.7", "c8": "^9.1.0", - "chai": "^4.3.6", + "chai": "^5.0.0", "eslint": "^8.23.1", "eslint-config-hexo": "^5.0.0", "mocha": "^10.0.0", 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/index.ts similarity index 97% rename from test/index.js rename to test/index.ts index c7d2df5..786f62f 100644 --- a/test/index.js +++ b/test/index.ts @@ -1,9 +1,7 @@ -'use strict'; -const should = require('chai').should(); // eslint-disable-line +const yfm = require('../lib/front_matter.ts'); describe('Front-matter', () => { - const yfm = require('../lib/front_matter.ts'); describe('split', () => { it('not string', () => { @@ -373,7 +371,7 @@ describe('Front-matter', () => { ].join('\n'); const data = yfm.parse(str); - parseInt(data.date.getTime() / 1000, 10).should.eql(parseInt(unixTime / 1000, 10)); + parseInt(String(data.date.getTime() / 1000), 10).should.eql(parseInt(String(unixTime / 1000), 10)); }); }); diff --git a/tsconfig.json b/tsconfig.json index c2b1773..f6fa18c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,14 +6,15 @@ "outDir": "dist", "declaration": true, "esModuleInterop": true, - "types": [ - "node" - ] + "types": ["node"] }, - "include": [ - "lib/front_matter.ts" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "include": ["lib/front_matter.ts"], + "exclude": ["node_modules"], + + "ts-node": { + "transpileOnly": true, + "compilerOptions": { + "types": ["node", "mocha", "chai"] + } + } +}