forked from NomicFoundation/hardhat
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typescript-support.ts
109 lines (90 loc) · 3.15 KB
/
typescript-support.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { assert } from "chai";
import { TASK_TEST_GET_TEST_FILES } from "../../../src/builtin-tasks/task-names";
import { resetHardhatContext } from "../../../src/internal/reset";
import { useEnvironment } from "../../helpers/environment";
import { useFixtureProject } from "../../helpers/project";
import { expectHardhatError } from "../../helpers/errors";
import { ERRORS } from "../../../src/internal/core/errors-list";
import { getRealPath } from "../../../src/internal/util/fs-utils";
describe("Typescript support", function () {
describe("strict typescript config", function () {
useFixtureProject("broken-typescript-config-project");
it("Should fail if an implicit any is used and the tsconfig forbids them", function () {
// If we run this test in transpilation only mode, it will fail
this.skip();
assert.throws(
() => require("../../../src/internal/lib/hardhat-lib"),
"TS7006"
);
resetHardhatContext();
});
});
describe("hardhat.config.ts", function () {
useFixtureProject("typescript-project");
useEnvironment();
it("Should load the config", function () {
assert.isDefined(this.env.config.networks.network);
});
});
describe("hardhat.config.cts", function () {
useFixtureProject("typescript-esm-project");
useEnvironment();
it("Should load the config", function () {
assert.isDefined(this.env.config.networks.network);
});
});
describe("Typescript scripts", function () {
useFixtureProject("typescript-project");
useEnvironment();
it("Should run ts scripts", async function () {
await this.env.run("run", { script: "./script.ts", noCompile: true });
assert.equal(process.exitCode, 123);
(process as any).exitCode = undefined;
});
});
describe("Typescript tests", function () {
useFixtureProject("typescript-project");
useEnvironment();
it("Should see the TS test", async function () {
const tests: string[] = await this.env.run(TASK_TEST_GET_TEST_FILES, {
testFiles: [],
});
assert.deepEqual(tests.sort(), [
await getRealPath("test/js-test.js"),
await getRealPath("test/ts-test.ts"),
]);
});
});
});
describe("tsconfig param", function () {
useFixtureProject("typescript-project");
describe("When setting an incorrect tsconfig file", function () {
beforeEach(() => {
process.env.HARDHAT_TSCONFIG = "non-existent.ts";
});
afterEach(() => {
delete process.env.HARDHAT_TSCONFIG;
resetHardhatContext();
});
it("should fail to load hardhat", function () {
expectHardhatError(
() => require("../../../src/internal/lib/hardhat-lib"),
ERRORS.ARGUMENTS.INVALID_ENV_VAR_VALUE
);
});
});
describe("When setting a correct tsconfig file", function () {
beforeEach(() => {
process.env.HARDHAT_TSCONFIG = "./test/tsconfig.json";
});
afterEach(() => {
delete process.env.HARDHAT_TSCONFIG;
resetHardhatContext();
});
it("should load hardhat", function () {
assert.doesNotThrow(() =>
require("../../../src/internal/lib/hardhat-lib")
);
});
});
});