rryter / hardhat-jest-plugin

A Jest plugin for Hardhat.
https://hardhat.org/
MIT License
19 stars 5 forks source link

Error: Can't find a root directory while resolving a config file path. #19

Open ackvf opened 2 years ago

ackvf commented 2 years ago

I am getting this error while trying to run hardhat test:jest on windows.

C:\repos\myProject\contracts>npr contracts:jest

> contracts@0.1.0 contracts:jest
> hardhat test:jest --no-compile

You have both ethereum-waffle and @nomicfoundation/hardhat-chai-matchers installed. They don't work correctly together, so please make sure you only use one.

We recommend you migrate to @nomicfoundation/hardhat-chai-matchers. Learn how to do it here: https://hardhat.org/migrate-from-waffle
An unexpected error occurred:

Error: Can't find a root directory while resolving a config file path.
Provided path to resolve: C:\Users\Qwerty\repos\myProject\contracts/jest.config.js
cwd: C:\repos\myProject\contracts
    at resolveConfigPath (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\resolveConfigPath.js:134:11)
    at readConfig (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\index.js:228:49)
    at readConfigs (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\jest-config\build\index.js:420:32)
    at runCLI (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\node_modules\@jest\core\build\cli\index.js:133:29)
    at testFailures (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:20:14)
    at new Promise (<anonymous>)
    at SimpleTaskDefinition.action (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:15:32)
    at async Environment._runTaskDefinition (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at async Environment.run (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (C:\Users\Qwerty\repos\myProject\contracts\node_modules\hardhat-jest-plugin\src\index.ts:48:28)
(node:49648) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

But then when I run npx jest --showConfig it does read my jest.config.ts correctly, which can be seen from the output:

C:\repos\myProject\contracts>npx jest --showConfig
{
  "configs": [
    {
      "cwd": "C:\\Users\\Qwerty\\repos\\myProject\\contracts",
      "displayName": {
        "name": "Contracts",
        "color": "white"
      },

This is my jest.config.ts

import type { Config } from '@jest/types'

const config: Config.InitialOptions = {
  displayName: {
    name: 'Contracts',
    color: 'white',
  },

  testEnvironment: 'node',
  testRegex: 'test/.*\\.(ts|tsx)$',
  rootDir: '.',

  moduleNameMapper: {
    '^@abi/(.*)': '<rootDir>/abi/$1',
    '^@typings$': '<rootDir>/typings',
    '^@typings/(.*)': '<rootDir>/typings/$1',
  },

  silent: false,
  verbose: false,
}

export default config

What I am finding odd is the weird forward slash where it should have been a backwards slash. And then it actually tries to load jest.config.js instead of .ts

Provided path to resolve: C:\Users\Qwerty\repos\myProject\contracts/jest.config.js

What should I do?

ackvf commented 2 years ago

When I tried to change the config.paths.root + "/jest.config.js" by hand to jest.config.ts it didn't really help. It did discover the files, but then I received

 FAIL   Contracts  test/Example.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.