Skip to content

Commit dd9d352

Browse files
committed
mocha test plugin
1 parent b9828c1 commit dd9d352

19 files changed

+376
-1
lines changed

pnpm-lock.yaml

+79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/example-project/hardhat.config.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
HardhatUserConfig,
99
} from "@ignored/hardhat-vnext/config";
1010
import HardhatNodeTestRunner from "@ignored/hardhat-vnext-node-test-runner";
11+
import HardhatMochaTestRunner from "@ignored/hardhat-vnext-mocha-test-runner";
1112

1213
const exampleEmptyTask = emptyTask("empty", "An example empty task").build();
1314

@@ -102,8 +103,18 @@ const config: HardhatUserConfig = {
102103
exampleEmptySubtask,
103104
greeting,
104105
],
105-
plugins: [pluginExample, HardhatNodeTestRunner],
106+
plugins: [
107+
pluginExample,
108+
HardhatMochaTestRunner,
109+
// if testing node plugin, use the following line instead
110+
// HardhatNodeTestRunner,
111+
],
106112
privateKey: configVariable("privateKey"),
113+
paths: {
114+
tests: "test/mocha",
115+
// if testing node plugin, use the following line instead
116+
// tests: "test/node",
117+
},
107118
};
108119

109120
export default config;

v-next/example-project/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
},
2323
"devDependencies": {
2424
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.3",
25+
"@ignored/hardhat-vnext-mocha-test-runner": "workspace:^3.0.0-next.2",
2526
"@ignored/hardhat-vnext-node-test-runner": "workspace:^3.0.0-next.2",
27+
"@types/mocha": ">=9.1.0",
2628
"@types/node": "^20.14.9",
29+
"mocha": "^10.0.0",
2730
"prettier": "3.2.5",
2831
"typescript": "~5.5.0"
2932
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "mocha";
3+
4+
describe("Mocha test", () => {
5+
it("should work", () => {
6+
assert.equal(1 + 1, 2);
7+
});
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "mocha";
3+
4+
// import hre from "@ignored/hardhat-vnext";
5+
6+
// describe("Other mocha test", () => {
7+
// it("should have the example task", () => {
8+
// assert.ok(hre.tasks.getTask("example"));
9+
// });
10+
// });
11+
12+
describe("Other mocha test", () => {
13+
it("should have the example task", () => {
14+
assert.ok(true);
15+
});
16+
});

v-next/hardhat-errors/src/descriptors.ts

+7
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,12 @@ Please double check your script's path.`,
472472
473473
Please check Hardhat's output for more details.`,
474474
},
475+
TEST_TASK_ESM_TESTS_RUN_TWICE: {
476+
number: 602,
477+
messageTemplate: `Your project uses ESM and you've programmatically run your tests twice. This is not supported yet.`,
478+
websiteTitle: "Running tests twice in an ESM project",
479+
websiteDescription:
480+
'You have run your tests twice programmatically and your project is an ESM project (you have `"type": "module"` in your `package.json`, or some of your files have the `.mjs` extension). This is not supported by Mocha yet.',
481+
},
475482
},
476483
} as const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createConfig } = require("../../config-v-next/eslint.cjs");
2+
3+
module.exports = createConfig(__filename);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node modules
2+
/node_modules
3+
4+
# Compilation output
5+
/dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
/dist
3+
CHANGELOG.md
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Nomic Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hardhat's `mocha` test runner
2+
3+
This package includes Hardhat's `mocha` test runner.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "@ignored/hardhat-vnext-mocha-test-runner",
3+
"version": "3.0.0-next.2",
4+
"description": "A mocha test runner",
5+
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-mocha-test-runner",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/NomicFoundation/hardhat",
9+
"directory": "v-next/hardhat-mocha-test-runner"
10+
},
11+
"author": "Nomic Foundation",
12+
"license": "MIT",
13+
"type": "module",
14+
"exports": {
15+
".": "./dist/src/index.js"
16+
},
17+
"keywords": [
18+
"ethereum",
19+
"smart-contracts",
20+
"hardhat"
21+
],
22+
"scripts": {
23+
"lint": "pnpm prettier --check && pnpm eslint",
24+
"lint:fix": "pnpm prettier --write && pnpm eslint --fix",
25+
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
26+
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
27+
"test": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
28+
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
29+
"pretest": "pnpm build",
30+
"build": "tsc --build .",
31+
"prepublishOnly": "pnpm build",
32+
"clean": "rimraf dist"
33+
},
34+
"files": [
35+
"dist/src/",
36+
"src/",
37+
"CHANGELOG.md",
38+
"LICENSE",
39+
"README.md"
40+
],
41+
"devDependencies": {
42+
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
43+
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
44+
"@nomicfoundation/hardhat-test-utils": "workspace:^",
45+
"@types/mocha": ">=9.1.0",
46+
"@types/node": "^20.14.9",
47+
"@typescript-eslint/eslint-plugin": "^7.7.1",
48+
"@typescript-eslint/parser": "^7.7.1",
49+
"eslint": "8.57.0",
50+
"eslint-config-prettier": "9.1.0",
51+
"eslint-import-resolver-typescript": "^3.6.1",
52+
"eslint-plugin-import": "2.29.1",
53+
"eslint-plugin-no-only-tests": "3.1.0",
54+
"expect-type": "^0.19.0",
55+
"prettier": "3.2.5",
56+
"rimraf": "^5.0.5",
57+
"typescript": "~5.5.0",
58+
"typescript-eslint": "7.7.1"
59+
},
60+
"dependencies": {
61+
"@ignored/hardhat-vnext-core": "workspace:^3.0.0-next.2",
62+
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
63+
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
64+
"mocha": "^10.0.0",
65+
"tsx": "^4.11.0"
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { HardhatPlugin } from "@ignored/hardhat-vnext-core/types/plugins";
2+
3+
import { task } from "@ignored/hardhat-vnext-core/config";
4+
5+
const hardhatPlugin: HardhatPlugin = {
6+
id: "test",
7+
tasks: [
8+
task("test", "Runs tests using the Mocha test runner")
9+
.addVariadicArgument({
10+
name: "testFiles",
11+
description: "An optional list of files to test",
12+
defaultValue: [],
13+
})
14+
.setAction(import.meta.resolve("./task-action.js"))
15+
.build(),
16+
],
17+
};
18+
19+
export default hardhatPlugin;

0 commit comments

Comments
 (0)