Skip to content

Commit 0ce2718

Browse files
committed
Test fixes
1 parent 6e10edd commit 0ce2718

File tree

8 files changed

+106
-58
lines changed

8 files changed

+106
-58
lines changed

v-next/core/src/internal/hre.ts

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ async function resolveUserConfig(
196196
tasks: config.tasks ?? [],
197197
paths: {
198198
root: projectRoot,
199+
cache: config.paths?.cache ?? "", // TODO: resolve cache path
200+
artifacts: config.paths?.artifacts ?? "", // TODO: resolve artifacts path
199201
},
200202
};
201203

v-next/core/src/types/config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ export interface HardhatUserConfig {
5252
/**
5353
* The different paths that conform a Hardhat project.
5454
*/
55-
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- TODO: add the paths
56-
export interface ProjectPathsUserConfig {}
55+
export interface ProjectPathsUserConfig {
56+
root?: string;
57+
cache?: string;
58+
artifacts?: string;
59+
}
5760

5861
/**
5962
* The resolved Hardhat configuration.

v-next/core/test/internal/configuration-variables/configuration-variables.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe("ResolvedConfigurationVariable", () => {
2626
plugins: [],
2727
paths: {
2828
root: projectRoot,
29+
cache: "",
30+
artifacts: "",
2931
},
3032
},
3133
hooks: hookManager,

v-next/core/test/internal/hook-manager.ts

+28
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ describe("HookManager", () => {
103103
plugins: [],
104104
paths: {
105105
root: projectRoot,
106+
cache: "",
107+
artifacts: "",
106108
},
107109
},
108110
hooks: hookManager,
@@ -171,6 +173,8 @@ describe("HookManager", () => {
171173
tasks: [],
172174
paths: {
173175
root: projectRoot,
176+
cache: "",
177+
artifacts: "",
174178
},
175179
};
176180

@@ -224,6 +228,8 @@ describe("HookManager", () => {
224228
tasks: [],
225229
paths: {
226230
root: projectRoot,
231+
cache: "",
232+
artifacts: "",
227233
},
228234
};
229235

@@ -327,6 +333,8 @@ describe("HookManager", () => {
327333
plugins: [],
328334
paths: {
329335
root: projectRoot,
336+
cache: "",
337+
artifacts: "",
330338
},
331339
},
332340
hooks: hookManager,
@@ -345,6 +353,8 @@ describe("HookManager", () => {
345353
tasks: [],
346354
paths: {
347355
root: projectRoot,
356+
cache: "",
357+
artifacts: "",
348358
},
349359
};
350360

@@ -429,6 +439,8 @@ describe("HookManager", () => {
429439
tasks: [],
430440
paths: {
431441
root: projectRoot,
442+
cache: "",
443+
artifacts: "",
432444
},
433445
};
434446

@@ -550,6 +562,8 @@ describe("HookManager", () => {
550562
plugins: [],
551563
paths: {
552564
root: projectRoot,
565+
cache: "",
566+
artifacts: "",
553567
},
554568
},
555569
hooks: hookManager,
@@ -642,6 +656,8 @@ describe("HookManager", () => {
642656
tasks: [],
643657
paths: {
644658
root: projectRoot,
659+
cache: "",
660+
artifacts: "",
645661
},
646662
};
647663

@@ -684,6 +700,8 @@ describe("HookManager", () => {
684700
plugins: [],
685701
paths: {
686702
root: projectRoot,
703+
cache: "",
704+
artifacts: "",
687705
},
688706
},
689707
hooks: hookManager,
@@ -700,6 +718,8 @@ describe("HookManager", () => {
700718
tasks: [],
701719
paths: {
702720
root: projectRoot,
721+
cache: "",
722+
artifacts: "",
703723
},
704724
};
705725

@@ -718,6 +738,8 @@ describe("HookManager", () => {
718738
tasks: [],
719739
paths: {
720740
root: projectRoot,
741+
cache: "",
742+
artifacts: "",
721743
},
722744
};
723745

@@ -801,6 +823,8 @@ describe("HookManager", () => {
801823
tasks: [],
802824
paths: {
803825
root: projectRoot,
826+
cache: "",
827+
artifacts: "",
804828
},
805829
};
806830

@@ -843,6 +867,8 @@ describe("HookManager", () => {
843867
plugins: [],
844868
paths: {
845869
root: projectRoot,
870+
cache: "",
871+
artifacts: "",
846872
},
847873
},
848874
hooks: hookManager,
@@ -1002,6 +1028,8 @@ function buildMockHardhatRuntimeEnvironment(
10021028
plugins: [],
10031029
paths: {
10041030
root: projectRoot,
1031+
cache: "",
1032+
artifacts: "",
10051033
},
10061034
},
10071035
tasks: mockTaskManager,

v-next/core/test/internal/user-interruptions/user-interruptions-manager.ts

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ describe("UserInterruptionManager", () => {
3030
plugins: [],
3131
paths: {
3232
root: projectRoot,
33+
cache: "",
34+
artifacts: "",
3335
},
3436
},
3537
globalOptions: {},
@@ -74,6 +76,8 @@ describe("UserInterruptionManager", () => {
7476
plugins: [],
7577
paths: {
7678
root: projectRoot,
79+
cache: "",
80+
artifacts: "",
7781
},
7882
},
7983
globalOptions: {},
@@ -120,6 +124,8 @@ describe("UserInterruptionManager", () => {
120124
plugins: [],
121125
paths: {
122126
root: projectRoot,
127+
cache: "",
128+
artifacts: "",
123129
},
124130
},
125131
globalOptions: {},

v-next/hardhat/test/internal/builtin-plugins/clean/task-action.ts

+61-55
Original file line numberDiff line numberDiff line change
@@ -17,96 +17,102 @@ import { createHardhatRuntimeEnvironment } from "../../../../src/hre.js";
1717
import cleanAction from "../../../../src/internal/builtin-plugins/clean/task-action.js";
1818
import { useFixtureProject } from "../../../helpers/project.js";
1919

20-
function assertCleanBehavior(global: boolean, globalCacheDir: string) {
21-
it("should empty the cache dir", async () => {
22-
const cacheContents = await readdir(path.join(process.cwd(), "cache"));
23-
assert.ok(cacheContents.length === 0, "Cache dir is not empty");
24-
});
25-
26-
it("should remove the artifacts dir", async () => {
27-
assert.ok(
28-
exists(path.join(process.cwd(), "artifacts")),
29-
"Artifacts dir does not exist",
30-
);
31-
});
32-
33-
if (global) {
34-
it("should empty the global cache dir when the global flag is true", async () => {
20+
let hre: HardhatRuntimeEnvironment;
21+
let globalCacheDir: string;
22+
let cacheDir: string;
23+
let artifactsDir: string;
24+
25+
function assertCleanBehavior(global: boolean) {
26+
it("should clean the cache and artifacts directories", async () => {
27+
await cleanAction({ global }, hre);
28+
29+
// If the cache dir exists, it should be empty
30+
if (await exists(cacheDir)) {
31+
const cacheContents = await readdir(cacheDir);
32+
assert.ok(cacheContents.length === 0, "Cache dir is not empty");
33+
}
34+
35+
// The artifacts dir should not exist
36+
assert.ok(!(await exists(artifactsDir)), "Artifacts dir exists");
37+
38+
// If the global cache dir exists, it should be empty if the global flag is
39+
// true, and not empty otherwise
40+
if (await exists(globalCacheDir)) {
3541
const globalCacheContents = await readdir(globalCacheDir);
36-
assert.ok(
37-
globalCacheContents.length === 0,
38-
"Global cache dir is not empty",
39-
);
40-
});
41-
} else {
42-
it("should not empty the global cache dir when the global flag is false", async () => {
43-
const globalCacheContents = await readdir(globalCacheDir);
44-
assert.ok(globalCacheContents.length > 0, "Global cache dir is empty");
45-
});
46-
}
42+
if (global) {
43+
assert.ok(
44+
globalCacheContents.length === 0,
45+
"Global cache dir is not empty",
46+
);
47+
} else {
48+
assert.ok(
49+
globalCacheContents.length > 0,
50+
"Global cache dir is empty when it shouldn't be",
51+
);
52+
}
53+
}
54+
});
4755
}
4856

4957
describe("clean/task-action", () => {
50-
let hre: HardhatRuntimeEnvironment;
51-
let globalCacheDir: string;
52-
53-
before(async function () {
54-
hre = await createHardhatRuntimeEnvironment({});
55-
globalCacheDir = await getCacheDir();
56-
});
57-
5858
describe("cleanAction", () => {
5959
useFixtureProject("loaded-config");
6060

61+
before(async function () {
62+
globalCacheDir = await getCacheDir();
63+
cacheDir = path.join(process.cwd(), "cache");
64+
artifactsDir = path.join(process.cwd(), "artifacts");
65+
hre = await createHardhatRuntimeEnvironment({
66+
// TODO remove this once cache and artifacts are resolved in the config
67+
paths: { cache: cacheDir, artifacts: artifactsDir },
68+
});
69+
});
70+
6171
describe("when cache and artifact dirs don't exist", async () => {
6272
beforeEach(async () => {
6373
await remove(globalCacheDir);
64-
await remove(path.join(process.cwd(), "cache"));
65-
await remove(path.join(process.cwd(), "artifacts"));
74+
await remove(cacheDir);
75+
await remove(artifactsDir);
6676
});
6777

68-
await cleanAction({ global: true }, hre);
69-
assertCleanBehavior(true, globalCacheDir);
78+
assertCleanBehavior(true);
7079
});
7180

7281
describe("when cache and artifact are empty dirs", async () => {
7382
beforeEach(async () => {
7483
await remove(globalCacheDir);
75-
await remove(path.join(process.cwd(), "cache"));
76-
await remove(path.join(process.cwd(), "artifacts"));
77-
await getCacheDir(); // Recreate the cache dir
78-
await mkdir(path.join(process.cwd(), "cache"));
79-
await mkdir(path.join(process.cwd(), "artifacts"));
84+
await remove(cacheDir);
85+
await remove(artifactsDir);
86+
await getCacheDir(); // Calling this recreates the cache dir
87+
await mkdir(cacheDir);
88+
await mkdir(artifactsDir);
8089
});
8190

82-
await cleanAction({ global: true }, hre);
83-
assertCleanBehavior(true, globalCacheDir);
91+
assertCleanBehavior(true);
8492
});
8593

8694
describe("when cache and artifact dirs aren't empty", async () => {
8795
beforeEach(async () => {
8896
await remove(globalCacheDir);
89-
await remove(path.join(process.cwd(), "cache"));
90-
await remove(path.join(process.cwd(), "artifacts"));
91-
await getCacheDir(); // Recreate the cache dir
97+
await remove(cacheDir);
98+
await remove(artifactsDir);
99+
await getCacheDir(); // Calling this recreates the cache dir
92100
await writeUtf8File(path.join(globalCacheDir, "a"), "");
93-
await writeUtf8File(path.join(process.cwd(), "cache", "a"), "");
94-
await writeUtf8File(path.join(process.cwd(), "artifacts", "a"), "");
101+
await writeUtf8File(path.join(cacheDir, "a"), "");
102+
await writeUtf8File(path.join(artifactsDir, "a"), "");
95103
});
96104

97-
await cleanAction({ global: true }, hre);
98-
assertCleanBehavior(true, globalCacheDir);
105+
assertCleanBehavior(true);
99106
});
100107

101108
describe("when global flag is false", async () => {
102109
beforeEach(async () => {
103110
await remove(globalCacheDir);
104-
await getCacheDir(); // Recreate the cache dir
111+
await getCacheDir(); // Calling this recreates the cache dir
105112
await writeUtf8File(path.join(globalCacheDir, "a"), "");
106113
});
107114

108-
await cleanAction({ global: false }, hre);
109-
assertCleanBehavior(false, globalCacheDir);
115+
assertCleanBehavior(false);
110116
});
111117
});
112118
});

v-next/hardhat/test/internal/builtin-plugins/run/task-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createHardhatRuntimeEnvironment } from "../../../../src/hre.js";
99
import runScriptWithHardhat from "../../../../src/internal/builtin-plugins/run/task-action.js";
1010
import { useFixtureProject } from "../../../helpers/project.js";
1111

12-
describe("runScriptWithHardhat", function () {
12+
describe("run/task-action", function () {
1313
let hre: HardhatRuntimeEnvironment;
1414

1515
before(async function () {

v-next/hardhat/test/internal/cli/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Usage: hardhat [GLOBAL OPTIONS] <TASK> [SUBTASK] [TASK OPTIONS] [--] [TASK ARGUM
222222
223223
AVAILABLE TASKS:
224224
225+
clean Clears the cache and deletes all artifacts
225226
example Example task
226227
run Runs a user-defined script after compiling the project
227228
task A task that uses arg1

0 commit comments

Comments
 (0)