Skip to content
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
3 changes: 2 additions & 1 deletion packages/hardhat-ignition/src/internal/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ const taskDeploy: NewTaskActionFunction<TaskDeployArguments> = async (
);
}

const noTests = hre.config.solidity.splitTestsCompilation;
await hre.tasks.getTask("build").run({
quiet: true,
noTests: true,
noTests,
defaultBuildProfile: "production",
});

Expand Down
3 changes: 2 additions & 1 deletion packages/hardhat-ignition/src/internal/tasks/visualize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const visualizeTask: NewTaskActionFunction<TaskVisualizeArguments> = async (
{ noOpen, modulePath }: { noOpen: boolean; modulePath: string },
hre: HardhatRuntimeEnvironment,
) => {
await hre.tasks.getTask("build").run({ noTests: true, quiet: true });
const noTests = hre.config.solidity.splitTestsCompilation;
await hre.tasks.getTask("build").run({ noTests, quiet: true });

const userModule = await loadModule(hre.config.paths.ignition, modulePath);

Expand Down
95 changes: 95 additions & 0 deletions packages/hardhat-ignition/test/deploy/build-invocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

import { assert } from "chai";
import { overrideTask } from "hardhat/config";
import { createHardhatRuntimeEnvironment } from "hardhat/hre";

import hardhatIgnitionPlugin from "../../src/index.js";

describe("deploy - build invocation", function () {
function buildArgCaptor() {
const buildArgs: any[] = [];
const buildOverride = overrideTask("build")
.setAction(async () => ({
default: async (args: any, _hre, runSuper) => {
buildArgs.push(args);
return runSuper(args);
},
}))
.build();
return { buildArgs, buildOverride };
}

function getProjectConfig() {
const projectPath = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"../fixture-projects",
"minimal",
);

const configPath = path.join(projectPath, "hardhat.config.js");

return { projectPath, configPath };
}

it("should call build without noTests when splitTestsCompilation is false", async function () {
const { buildArgs, buildOverride } = buildArgCaptor();
const { projectPath, configPath } = getProjectConfig();

const { default: userConfig } = await import(
pathToFileURL(configPath).href
);

const hre = await createHardhatRuntimeEnvironment(
{
...userConfig,
plugins: [hardhatIgnitionPlugin],
tasks: [buildOverride],
},
{ config: configPath },
projectPath,
);

await hre.tasks.getTask(["ignition", "deploy"]).run({
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
});

assert.equal(buildArgs.length, 1);
assert.equal(buildArgs[0].noTests, false);
assert.equal(buildArgs[0].defaultBuildProfile, "production");
assert.equal(buildArgs[0].quiet, true);
});

it("should call build with noTests when splitTestsCompilation is true", async function () {
const { buildArgs, buildOverride } = buildArgCaptor();
const { projectPath, configPath } = getProjectConfig();

const { default: userConfig } = await import(
pathToFileURL(configPath).href
);

const hre = await createHardhatRuntimeEnvironment(
{
...userConfig,
solidity: {
...userConfig.solidity,
splitTestsCompilation: true,
},
plugins: [hardhatIgnitionPlugin],
tasks: [buildOverride],
},
{ config: configPath },
projectPath,
);

await hre.tasks.getTask(["ignition", "deploy"]).run({
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
});

assert.equal(buildArgs.length, 1);
assert.equal(buildArgs[0].noTests, true);
assert.equal(buildArgs[0].defaultBuildProfile, "production");
assert.equal(buildArgs[0].quiet, true);
});
});
95 changes: 95 additions & 0 deletions packages/hardhat-ignition/test/plan/build-invocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

import { assert } from "chai";
import { overrideTask } from "hardhat/config";
import { createHardhatRuntimeEnvironment } from "hardhat/hre";

import hardhatIgnitionPlugin from "../../src/index.js";

describe("visualize - build invocation", function () {
function buildArgCaptor() {
const buildArgs: any[] = [];
const buildOverride = overrideTask("build")
.setAction(async () => ({
default: async (args: any) => {
buildArgs.push(args);
return { contractRootPaths: [], testRootPaths: [] };
},
}))
.build();
return { buildArgs, buildOverride };
}

function getProjectConfig() {
const projectPath = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"../fixture-projects",
"minimal",
);

const configPath = path.join(projectPath, "hardhat.config.js");

return { projectPath, configPath };
}

it("should call build without noTests when splitTestsCompilation is false", async function () {
const { buildArgs, buildOverride } = buildArgCaptor();
const { projectPath, configPath } = getProjectConfig();

const { default: userConfig } = await import(
pathToFileURL(configPath).href
);

const hre = await createHardhatRuntimeEnvironment(
{
...userConfig,
plugins: [hardhatIgnitionPlugin],
tasks: [buildOverride],
},
{ config: configPath },
projectPath,
);

await hre.tasks.getTask(["ignition", "visualize"]).run({
noOpen: true,
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
});

assert.equal(buildArgs.length, 1);
assert.equal(buildArgs[0].noTests, false);
assert.equal(buildArgs[0].quiet, true);
});

it("should call build with noTests when splitTestsCompilation is true", async function () {
const { buildArgs, buildOverride } = buildArgCaptor();
const { projectPath, configPath } = getProjectConfig();

const { default: userConfig } = await import(
pathToFileURL(configPath).href
);

const hre = await createHardhatRuntimeEnvironment(
{
...userConfig,
solidity: {
...userConfig.solidity,
splitTestsCompilation: true,
},
plugins: [hardhatIgnitionPlugin],
tasks: [buildOverride],
},
{ config: configPath },
projectPath,
);

await hre.tasks.getTask(["ignition", "visualize"]).run({
noOpen: true,
modulePath: path.join(projectPath, "ignition", "modules", "MyModule.js"),
});

assert.equal(buildArgs.length, 1);
assert.equal(buildArgs[0].noTests, true);
assert.equal(buildArgs[0].quiet, true);
});
});
Loading