Skip to content

Commit

Permalink
test: migrate to typescript & use chai@v5 (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored Feb 14, 2024
1 parent 43912de commit bfff812
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
reporter: spec
parallel: false
require:
- "ts-node/register"
- "chai/register-should.js"
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/.eslintrc → test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "hexo/test",
"extends": "hexo/ts-test",
"rules": {
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-empty-function": 0
}
}
}
1 change: 0 additions & 1 deletion test/.mocharc.yml

This file was deleted.

11 changes: 4 additions & 7 deletions test/index.js → test/log.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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', () => {
Expand Down
18 changes: 8 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
"outDir": "dist",
"declaration": true,
"esModuleInterop": true,
"types": [
"node"
]
"types": ["node"]
},
"include": [
"lib/log.ts"
],
"exclude": [
"node_modules"
]
}
"include": ["lib/log.ts"],
"exclude": ["node_modules"],
"ts-node": {
"transpileOnly": true,
"compilerOptions": { "types": ["node", "mocha", "chai"] }
}
}

0 comments on commit bfff812

Please sign in to comment.