Lesson 6: Running test giving Cannot find module error #502
-
The complied "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const hardhat_1 = require("hardhat");
const chai_1 = require("chai");
describe("SimpleStorage", function () {
let simpleStorage;
let SimpleStorageFactory;
beforeEach(async () => {
SimpleStorageFactory = await hardhat_1.ethers.getContractFactory("SimpleStorage");
simpleStorage = await SimpleStorageFactory.deploy();
});
it("Should start with a Favorite Number 0", async function () {
let currentValue = await simpleStorage.retrieve();
(0, chai_1.expect)(currentValue).to.equal(0);
//assert.equal(currentValue, 0);
});
}); The actual import { ethers } from "hardhat";
import { assert, expect } from "chai";
describe("SimpleStorage", function () {
let simpleStorage;
let SimpleStorageFactory;
beforeEach(async () => {
SimpleStorageFactory = await ethers.getContractFactory("SimpleStorage");
simpleStorage = await SimpleStorageFactory.deploy();
});
it("Should start with a Favorite Number 0", async function () {
let currentValue = await simpleStorage.retrieve();
expect(currentValue).to.equal(0);
//assert.equal(currentValue, 0);
});
}); The command I am running on terminal hardhat test test-deploy.js This is the following error I am getting An unexpected error occurred:
Error: Cannot find module 'D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\test-deploy.js'
Require stack:
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\node_modules\mocha\lib\mocha.js
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\node_modules\mocha\index.js
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\builtin-tasks\test.js
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\internal\core\tasks\builtin-tasks.js
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\internal\core\config\config-loading.js
- D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\internal\cli\cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\@cspotcode\source-map-support\source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\node_modules\mocha\lib\mocha.js:417:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\node_modules\mocha\lib\mocha.js:414:14)
at Mocha.run (D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\node_modules\mocha\lib\mocha.js:1015:10)
at testFailures (D:\coding-learning\solidityjsbypatrick\hardhat-simple-storage\node_modules\hardhat\src\builtin-tasks\test.ts:99:15) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\node_modules\\mocha\\lib\\mocha.js',
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\node_modules\\mocha\\index.js',
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\builtin-tasks\\test.js',
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\internal\\core\\tasks\\builtin-tasks.js',
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\internal\\core\\config\\config-loading.js',
'D:\\coding-learning\\solidityjsbypatrick\\hardhat-simple-storage\\node_modules\\hardhat\\internal\\cli\\cli.js'
]
}
error Command failed with exit code 1. To me it look like I need to import some kind of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@sanjayojha The typescript compiler is looking for Mocha types to run the tests. Check if you have |
Beta Was this translation helpful? Give feedback.
-
I missed the Patrcik explanation in the end of tutorial. I was coding in typescript while following the video. And didn't realize all this has been explained in the end of video |
Beta Was this translation helpful? Give feedback.
@sanjayojha The typescript compiler is looking for Mocha types to run the tests. Check if you have
@types/chai
and@types/mocha
installed in your project. You can check that from yourpackage.json
file. In any case, if any of those mentioned above package doesn't exist, do install themyarn add --dev @types/mocha @types/chai
. This should solve the issue.