Skip to content

Commit

Permalink
test: migrate to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Feb 2, 2024
1 parent 7ebae8e commit 3933f0d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
reporter: spec
loader:
# - ts-node/esm
require:
- ts-node/register
- chai/register-should.js

spec: ["test/*.ts"]
watch-files: ["lib"]
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion test/.mocharc.yml

This file was deleted.

6 changes: 2 additions & 4 deletions test/index.js → test/index.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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));
});
});

Expand Down
21 changes: 11 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"outDir": "dist",
"declaration": true,
"esModuleInterop": true,
"types": [
"node"
]
"types": ["node"]
},
"include": [
"lib/front_matter.ts"
],
"exclude": [
"node_modules"
]
}
"include": ["lib/front_matter.ts"],
"exclude": ["node_modules"],

"ts-node": {
"transpileOnly": true,
"compilerOptions": {
"types": ["node", "mocha", "chai"]
}
}
}

0 comments on commit 3933f0d

Please sign in to comment.