|
1 | 1 | import assert from "node:assert/strict";
|
| 2 | +import path from "node:path"; |
2 | 3 | import { before, describe, it } from "node:test";
|
3 | 4 |
|
4 | 5 | import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre";
|
5 |
| -import { exists, remove } from "@ignored/hardhat-vnext-utils/fs"; |
| 6 | +import { exists, readUtf8File, remove } from "@ignored/hardhat-vnext-utils/fs"; |
6 | 7 | import { useFixtureProject } from "@nomicfoundation/hardhat-test-utils";
|
7 | 8 |
|
8 | 9 | describe("hardhat-typechain", () => {
|
| 10 | + describe("check that types are generated correctly", () => { |
| 11 | + const projectFolder = "generate-types"; |
| 12 | + |
| 13 | + useFixtureProject(projectFolder); |
| 14 | + |
| 15 | + before(async () => { |
| 16 | + await remove(`${process.cwd()}/types`); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should generate the types", async () => { |
| 20 | + // Check that the types are generated with the expected addition of the "/index.js" extensions |
| 21 | + // and the v3 modules |
| 22 | + |
| 23 | + const hardhatConfig = await import( |
| 24 | + // eslint-disable-next-line import/no-relative-packages -- allow for fixture projects |
| 25 | + `./fixture-projects/${projectFolder}/hardhat.config.js` |
| 26 | + ); |
| 27 | + |
| 28 | + const hre = await createHardhatRuntimeEnvironment(hardhatConfig.default); |
| 29 | + |
| 30 | + assert.equal(await exists(`${process.cwd()}/types`), false); |
| 31 | + |
| 32 | + await hre.tasks.getTask("clean").run(); |
| 33 | + |
| 34 | + await hre.tasks.getTask("compile").run({}); |
| 35 | + |
| 36 | + const content = await readUtf8File( |
| 37 | + path.join(process.cwd(), "types", "ethers-contracts", "hardhat.d.ts"), |
| 38 | + ); |
| 39 | + |
| 40 | + // The overload target the v3 hardhat ethers package |
| 41 | + assert.equal( |
| 42 | + content.includes( |
| 43 | + `declare module "@ignored/hardhat-vnext-ethers/types" {`, |
| 44 | + ), |
| 45 | + true, |
| 46 | + ); |
| 47 | + |
| 48 | + // The import should be from the v3 hardhat ethers package |
| 49 | + assert.equal( |
| 50 | + content.includes(`from "@ignored/hardhat-vnext-ethers/types";`), |
| 51 | + true, |
| 52 | + ); |
| 53 | + |
| 54 | + // A relative import should have the ".js" extension |
| 55 | + assert.equal( |
| 56 | + content.includes(`import * as Contracts from "./index.js"`), |
| 57 | + true, |
| 58 | + ); |
| 59 | + |
| 60 | + // The import from a npm package should have ".js" extensions |
| 61 | + assert.equal(content.includes(`import { ethers } from 'ethers'`), true); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
9 | 65 | describe("generate types from contracts", () => {
|
10 | 66 | const projectFolder = "generate-types";
|
11 | 67 |
|
|
0 commit comments