Skip to content

Add support tests for project root resolution #6043

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 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is necessary to ensure the folder is created.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is necessary to ensure the folder is created.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
60 changes: 60 additions & 0 deletions v-next/hardhat/test/internal/hre-intialization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import path from "node:path";
import { afterEach, describe, it } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";
Expand Down Expand Up @@ -26,6 +27,65 @@ describe("HRE intialization", () => {
});

describe("createHardhatRuntimeEnvironment", () => {
describe("resolved project root", () => {
describe("no path param is passed", () => {
describe("the cwd does not contain a package file", () => {
useFixtureProject("resolve-project-root/no-path-param/folder");

it("should search for a package file in the parent directory", async () => {
const expectedPath = path.join(process.cwd(), "..");

const hre = await createHardhatRuntimeEnvironment({});

assert.equal(hre.config.paths.root, expectedPath);
});
});

describe("the cwd contains a package file", () => {
useFixtureProject("resolve-project-root/no-path-param");

it("should find the package file in the cwd", async () => {
const hre = await createHardhatRuntimeEnvironment({});

assert.equal(hre.config.paths.root, process.cwd());
});
});
});

describe("the path param is passed", () => {
describe("the path passed as param does not contain a package file", () => {
useFixtureProject("resolve-project-root/with-path-param");

it("should search for a package file in the parent directory", async () => {
const hre = await createHardhatRuntimeEnvironment(
{},
{},
`${process.cwd()}/folder-no-package`,
);

assert.equal(hre.config.paths.root, process.cwd());
});
});

describe("the path passed as param contains a package file", () => {
useFixtureProject("resolve-project-root/with-path-param");

it("should find the package file at the specified path", async () => {
const hre = await createHardhatRuntimeEnvironment(
{},
{},
`${process.cwd()}/folder-with-package`,
);

assert.equal(
hre.config.paths.root,
path.join(process.cwd(), "folder-with-package"),
);
});
});
});
});

it("should include the built-in plugins", async () => {
const hre = await createHardhatRuntimeEnvironment({});

Expand Down
Loading