-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Mocha test plugin #5598
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
Merged
Merged
Mocha test plugin #5598
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b1ab3a
mocha test plugin
zoeyTM fbe02dd
misc fixes for PR feedback
zoeyTM 361a596
config resolution hook, unit test, and type fixes
zoeyTM 5cc481d
update all fixture project tests to use hardhat-test-utils version
zoeyTM 2f16b74
Update v-next/hardhat-mocha-test-runner/src/hookHandlers/config.ts
zoeyTM 55f1f31
add config validation test
zoeyTM 9e776ec
export hre reset function for plugin testing
zoeyTM 06c7f9b
add mocha issue to error descriptor
zoeyTM 7ee9f04
create hre locally in test
zoeyTM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import assert from "node:assert/strict"; | ||
import { describe, it } from "mocha"; | ||
zoeyTM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe("Mocha test", () => { | ||
it("should work", () => { | ||
assert.equal(1 + 1, 2); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import assert from "node:assert/strict"; | ||
import { describe, it } from "mocha"; | ||
|
||
import hre from "@ignored/hardhat-vnext"; | ||
|
||
describe("Other mocha test", () => { | ||
it("should have the example task", () => { | ||
assert.ok(hre.tasks.getTask("example")); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { createConfig } = require("../../config-v-next/eslint.cjs"); | ||
|
||
module.exports = createConfig(__filename); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Node modules | ||
/node_modules | ||
|
||
# Compilation output | ||
/dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
/dist | ||
CHANGELOG.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Nomic Foundation | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Hardhat's `mocha` test runner | ||
|
||
This package includes Hardhat's `mocha` test runner. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "@ignored/hardhat-vnext-mocha-test-runner", | ||
"version": "3.0.0-next.2", | ||
"description": "A mocha test runner", | ||
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-mocha-test-runner", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/NomicFoundation/hardhat", | ||
"directory": "v-next/hardhat-mocha-test-runner" | ||
}, | ||
"author": "Nomic Foundation", | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/src/index.js" | ||
}, | ||
"keywords": [ | ||
"ethereum", | ||
"smart-contracts", | ||
"hardhat" | ||
], | ||
"scripts": { | ||
"lint": "pnpm prettier --check && pnpm eslint", | ||
"lint:fix": "pnpm prettier --write && pnpm eslint --fix", | ||
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"prettier": "prettier \"**/*.{ts,js,md,json}\"", | ||
"test": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
"pretest": "pnpm build", | ||
"build": "tsc --build .", | ||
"prepublishOnly": "pnpm build", | ||
"clean": "rimraf dist" | ||
}, | ||
"files": [ | ||
"dist/src/", | ||
"src/", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"devDependencies": { | ||
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0", | ||
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2", | ||
"@nomicfoundation/hardhat-test-utils": "workspace:^", | ||
"@types/mocha": ">=9.1.0", | ||
"@types/node": "^20.14.9", | ||
"@typescript-eslint/eslint-plugin": "^7.7.1", | ||
"@typescript-eslint/parser": "^7.7.1", | ||
"eslint": "8.57.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-no-only-tests": "3.1.0", | ||
"expect-type": "^0.19.0", | ||
"prettier": "3.2.5", | ||
"rimraf": "^5.0.5", | ||
"typescript": "~5.5.0", | ||
"typescript-eslint": "7.7.1" | ||
}, | ||
"dependencies": { | ||
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.2", | ||
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2", | ||
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2", | ||
"@ignored/hardhat-vnext-zod-utils": "workspace:^3.0.0-next.2", | ||
"mocha": "^10.0.0", | ||
"tsx": "^4.11.0", | ||
"zod": "^3.23.8" | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
v-next/hardhat-mocha-test-runner/src/hookHandlers/config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import type { ConfigHooks } from "@ignored/hardhat-vnext/types/hooks"; | ||
|
||
import { validateUserConfigZodType } from "@ignored/hardhat-vnext-zod-utils"; | ||
import { z } from "zod"; | ||
|
||
const mochaConfigType = z.object({ | ||
allowUncaught: z.boolean().optional(), | ||
asyncOnly: z.boolean().optional(), | ||
bail: z.boolean().optional(), | ||
checkLeaks: z.boolean().optional(), | ||
color: z.boolean().optional(), | ||
delay: z.boolean().optional(), | ||
diff: z.boolean().optional(), | ||
dryRun: z.boolean().optional(), | ||
failZero: z.boolean().optional(), | ||
fgrep: z.string().optional(), | ||
forbidOnly: z.boolean().optional(), | ||
forbidPending: z.boolean().optional(), | ||
fullTrace: z.boolean().optional(), | ||
globals: z.array(z.string()).optional(), | ||
grep: z.string().optional(), | ||
growl: z.boolean().optional(), | ||
inlineDiffs: z.boolean().optional(), | ||
invert: z.boolean().optional(), | ||
noHighlighting: z.boolean().optional(), | ||
reporter: z.string().optional(), | ||
reporterOptions: z.any().optional(), | ||
retries: z.number().optional(), | ||
slow: z.number().optional(), | ||
timeout: z.union([z.number(), z.string()]).optional(), | ||
ui: z | ||
.union([ | ||
z.literal("bdd"), | ||
z.literal("tdd"), | ||
z.literal("qunit"), | ||
z.literal("exports"), | ||
]) | ||
.optional(), | ||
parallel: z.boolean().optional(), | ||
jobs: z.number().optional(), | ||
rootHooks: z | ||
.object({ | ||
afterAll: z.union([z.function(), z.array(z.function())]).optional(), | ||
beforeAll: z.union([z.function(), z.array(z.function())]).optional(), | ||
afterEach: z.union([z.function(), z.array(z.function())]).optional(), | ||
beforeEach: z.union([z.function(), z.array(z.function())]).optional(), | ||
}) | ||
.optional(), | ||
require: z.array(z.string()).optional(), | ||
isWorker: z.boolean().optional(), | ||
}); | ||
|
||
const userConfigType = z.object({ | ||
mocha: z.optional(mochaConfigType), | ||
}); | ||
|
||
export default async (): Promise<Partial<ConfigHooks>> => { | ||
const handlers: Partial<ConfigHooks> = { | ||
validateUserConfig: async (userConfig) => { | ||
return validateUserConfigZodType(userConfig, userConfigType); | ||
}, | ||
resolveUserConfig: async ( | ||
userConfig, | ||
resolveConfigurationVariable, | ||
next, | ||
) => { | ||
const resolvedConfig = await next( | ||
userConfig, | ||
resolveConfigurationVariable, | ||
); | ||
|
||
return { | ||
...resolvedConfig, | ||
mocha: { | ||
timeout: 40000, | ||
...resolvedConfig.mocha, | ||
...userConfig.mocha, | ||
zoeyTM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
return handlers; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.