Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate to typescript & support chai@v5 #177

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] }
}
}