Skip to content

Commit

Permalink
modify tmp mocha poc
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici committed Mar 11, 2024
1 parent c8ee344 commit dc675e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/mocha-test-plugin/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"require": "ts-node/register/files",
"file": "./test/setup.ts",
"ignore": ["test/fixture-projects/**/*", "test/update-snapshots.ts"],
"timeout": 10000
}
6 changes: 4 additions & 2 deletions packages/mocha-test-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@
"eslint-plugin-no-only-tests": "3.0.0",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "workspace:^2.17.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^10.8.0",
"typescript": "~5.0.0"
},
"peerDependencies": {
"hardhat": "^2.17.0"
"hardhat": "^2.20.2",
"mocha": "^10.2.0"
},
"dependencies": {
"find-up": "^2.1.0",
"mocha": "^10.2.0"
"hardhat-gas-reporter": "^1.0.8"
}
}
35 changes: 21 additions & 14 deletions packages/mocha-test-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@ import findup from "find-up";
import { HardhatConfig } from "hardhat/types/config";
import { readFileSync } from "node:fs";

const defaultMochaOptions = {
// timeout: 10000,
};

// pnpm run build && pnpm unpublish hardhat --force --registry=http://localhost:4873/ && pnpm publish --registry http://localhost:4873 --no-git-checks --force
// pnpm run build && pnpm unpublish @nomicfoundation/mocha-test-plugin --force --registry=http://localhost:4873/ && pnpm publish --registry http://localhost:4873 --no-git-checks --force

let testsAlreadyRun = false;

export async function runTests(
parallel: boolean,
bail: boolean,
testFiles: string[] = [],
grep?: string,
hhConfig?: HardhatConfig
testFiles: string[],
hhConfig: HardhatConfig,
grep?: string
): Promise<number> {
// TODO: remove
console.debug("[DEBUG]: using mocha test module");
console.debug("[DEBUG]: using mocha test module - gas");
console.log((hhConfig as any).gasReporter.enabled);

// console.log(`parallel: ${parallel}`);
// console.log(`bail: ${bail}`);
// // console.log(`testFiles: ${testFiles}`);
// console.log(`grep: ${grep}`);

const { default: Mocha } = await import("mocha");
type MochaOptions = Mocha.MochaOptions;

// const mochaConfig: MochaOptions =
// hhConfig.test?.config !== undefined ? { ...hhConfig.test.config } : {};

// TODO: hack for gas reporter
const mochaConfig: MochaOptions =
hhConfig?.test?.customTestConfig !== undefined
? { ...hhConfig.test.customTestConfig }
: defaultMochaOptions;
hhConfig.test?.config !== undefined
? { ...hhConfig.test.config, ...(hhConfig as any).mocha }
: { ...(hhConfig as any).mocha };

if (grep !== undefined) {
mochaConfig.grep = grep;
Expand All @@ -52,6 +55,9 @@ export async function runTests(
const mocha = new Mocha(mochaConfig);
testFiles.forEach((file) => mocha.addFile(file));

console.log(`------timeout ${mocha.options.timeout}`);
console.log(`------require ${mocha.options.require}`);

// if the project is of type "module" or if there's some ESM test file,
// we call loadFilesAsync to enable Mocha's ESM support
const projectPackageJson = await getProjectPackageJson();
Expand All @@ -72,6 +78,7 @@ export async function runTests(

// This instructs Mocha to use the more verbose file loading infrastructure
// which supports both ESM and CJS

await mocha.loadFilesAsync();
}

Expand Down

0 comments on commit dc675e5

Please sign in to comment.