Skip to content

Commit c476f5f

Browse files
committed
Setup mocha for testing with chai and ts-node
1 parent 485ff08 commit c476f5f

File tree

7 files changed

+1869
-626
lines changed

7 files changed

+1869
-626
lines changed

.mocharc.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
require: "ts-node/register",
3+
loader: ["ts-node/esm", "./.pnp.loader.mjs"],
4+
spec: ["test/**/*.spec.*"],
5+
watchFiles: ["src"],
6+
};

.yarn/sdks/eslint/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint",
3-
"version": "8.55.0-sdk",
3+
"version": "8.56.0-sdk",
44
"main": "./lib/api.js",
55
"type": "commonjs",
66
"bin": {

eslint.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { fileURLToPath } from "url";
88

99
const allFiles = "**/*.?(c|m){js,ts}";
1010
const jsFiles = "**/*.?(c|m)js";
11+
const commonFiles = "**/*.c{js,ts}";
1112

1213
const rootDir = dirname(fileURLToPath(import.meta.url));
1314
const compat = new FlatCompat({ baseDirectory: rootDir });
@@ -43,4 +44,15 @@ export default [
4344
reportUnusedDisableDirectives: true,
4445
},
4546
},
47+
{
48+
files: [commonFiles],
49+
languageOptions: {
50+
sourceType: "commonjs",
51+
globals: globals.commonjs,
52+
},
53+
},
54+
{
55+
files: ["test/**/*.spec.?(c|m)ts"],
56+
languageOptions: { globals: globals.mocha },
57+
},
4658
];

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"type": "github",
2626
"url": "https://github.com/sponsors/steverep"
2727
},
28-
"packageManager": "yarn@4.0.2",
28+
"packageManager": "yarn@4.1.1",
2929
"engines": {
3030
"node": ">=16"
3131
},
@@ -41,6 +41,7 @@
4141
"format": "prettier --cache --write .",
4242
"lint": "yarn dedupe --check && eslint --cache . && prettier --cache --check .",
4343
"build": "tsc",
44+
"test": "mocha",
4445
"clean": "rm -rf dist",
4546
"prepublish": "yarn run lint",
4647
"prepack": "yarn run build",
@@ -57,16 +58,21 @@
5758
"@eslint/eslintrc": "^2.1.4",
5859
"@eslint/js": "^8.56.0",
5960
"@types/babel__core": "^7.20.5",
61+
"@types/chai": "^4",
6062
"@types/eslint-config-prettier": "^6.11.3",
6163
"@types/eslint__eslintrc": "^2.1.1",
6264
"@types/eslint__js": "^8.42.3",
63-
"@types/node": "^20.10.4",
65+
"@types/mocha": "^10",
66+
"@types/node": "^20.11.25",
6467
"@typescript-eslint/eslint-plugin": "^6.14.0",
6568
"@typescript-eslint/parser": "^6.14.0",
69+
"chai": "^4",
6670
"eslint": "^8.56.0",
6771
"eslint-config-prettier": "^9.1.0",
6872
"globals": "^13.24.0",
73+
"mocha": "^10.3.0",
6974
"prettier": "^3.1.1",
75+
"ts-node": "^10.9.2",
7076
"typescript": "^5.3.3",
7177
"webpack": "^5.89.0"
7278
}

tsconfig-lint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
3-
"include": ["src/**/*", "test/**/*", "*.config.js"],
3+
"include": ["src/**/*", "test/**/*", "*.config.js", ".*rc.cjs"],
44
"compilerOptions": {
55
"noEmit": true
66
}

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
"noPropertyAccessFromIndexSignature": true,
2727
// Completeness
2828
"skipLibCheck": true
29+
},
30+
"ts-node": {
31+
"esm": true,
32+
"transpileOnly": true
2933
}
3034
}

0 commit comments

Comments
 (0)