Skip to content

Commit

Permalink
hh core POC tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici committed Mar 11, 2024
1 parent dc675e5 commit 86f2ea0
Show file tree
Hide file tree
Showing 8 changed files with 1,487 additions and 111 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hardhat",
"version": "2.21.0",
"version": "2.21.3",
"author": "Nomic Labs LLC",
"license": "MIT",
"homepage": "https://hardhat.org",
Expand Down
14 changes: 8 additions & 6 deletions packages/hardhat-core/src/builtin-tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { showForkRecommendationsBannerIfNecessary } from "../internal/hardhat-ne
import { pluralize } from "../internal/util/strings";
import { getAllFilesMatching } from "../internal/util/fs-utils";

import { RunTests } from "../types/builtin-tasks/test";
import {
TASK_COMPILE,
TASK_TEST,
Expand Down Expand Up @@ -78,7 +79,7 @@ subtask(TASK_TEST_RUN_MOCHA_TESTS)
},
{ config }
) => {
let runTests;
let runTests: RunTests;

// TODO: remove
console.debug("[DEBUG]: HH CORE: using test module");
Expand All @@ -87,16 +88,17 @@ subtask(TASK_TEST_RUN_MOCHA_TESTS)
if (config?.test?.modulePath !== undefined) {
runTests = (await import(config.test.modulePath)).runTests;
} else {
const defaultTestPackage = "@nomicfoundation/mocha-test-plugin";
console.log("--------------mocha test plugin");
const defaultTestPackage = "@nomicfoundation/mocha-test-plugin"; // TODO
runTests = (await import(defaultTestPackage)).runTests;
}

const testFailures = await runTests(
taskArgs.parallel,
taskArgs.bail,
taskArgs.testFiles,
taskArgs.grep,
config
config,
taskArgs.grep
);

return testFailures;
Expand Down Expand Up @@ -150,9 +152,9 @@ task(TASK_TEST, "Runs mocha tests")

const files = await run(TASK_TEST_GET_TEST_FILES, { testFiles });

await run(TASK_TEST_SETUP_TEST_ENVIRONMENT);
await run(TASK_TEST_SETUP_TEST_ENVIRONMENT); // TODO: remove?

await run(TASK_TEST_RUN_SHOW_FORK_RECOMMENDATIONS);
await run(TASK_TEST_RUN_SHOW_FORK_RECOMMENDATIONS); // TODO: check what it does

const testFailures = await run(TASK_TEST_RUN_MOCHA_TESTS, {
testFiles: files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function resolveConfig(
paths: resolveProjectPaths(userConfigPath, userConfig.paths),
networks: resolveNetworksConfig(userConfig.networks),
solidity: resolveSolidityConfig(userConfig),
test: userConfig.test, // TODO: is this necessary? It is included automatically above
// test: userConfig.test, // TODO: is this necessary? It is included automatically above
};
}

Expand Down
9 changes: 9 additions & 0 deletions packages/hardhat-core/src/types/builtin-tasks/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { HardhatConfig } from "../config";

export type RunTests = (
parallel: boolean,
bail: boolean,
testFiles: string[],
hhConfig: HardhatConfig,
grep?: string
) => Promise<number>;
10 changes: 5 additions & 5 deletions packages/hardhat-core/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ export interface SolidityConfig {
// Hardhat config
interface Test {
modulePath?: string;
pathToTests?: string | string[];
timeout?: number;
parallel?: boolean;
bail?: boolean;
// pathToTests?: string | string[];
// timeout?: number;
// parallel?: boolean;
// bail?: boolean;
// Here, users can insert all their custom test options, which will be used in their testing plugin
customTestConfig?: Record<string, any>;
config?: Record<string, any>;
}

export interface HardhatUserConfig {
Expand Down
10 changes: 10 additions & 0 deletions packages/hardhat-core/test/builtin-tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { expectHardhatErrorAsync } from "../helpers/errors";
// calls with the same argument, and each `it` should have its own fixture
// project.

// ---------------------------- TODO
// use predefined plugin
// use custom plugin - script
// use custom plugin - module
// be sure that alle the files to tests are collected
// be sure to pass all the args specified in the API: parallel, bail, files, config, grep
// be sure to return the result returned by the API

// --------------------------- TODO

describe("test task (CJS)", function () {
describe("default config project", function () {
useFixtureProject("test-task/minimal-config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ describe("Config resolution", () => {
});
});

describe("Mocha config resolution", () => {
// TODO: move these tests in the mocha-test-plugin
describe("Test config resolution", () => {
// TODO: check that test config is resolved correctly
// it("Should set a default time and leave the rest as is", () => {
// const config = resolveConfig(__filename, { mocha: { bail: true } });
// assert.equal(config.mocha!.timeout, defaultMochaOptions.timeout);
Expand Down

0 comments on commit 86f2ea0

Please sign in to comment.