Skip to content

Error on ESM TypeScript project when using ts-node + mocha #1094

Description

@lostvicking

Error is thrown when running mocha tests

ESM TypeScript project is being tested with Mocha, when ts-auto-mock's createMock is called an error is thrown

Your environment

  • ts-auto-mock version: 3.5.0
  • typescript version: 4.6.2
  • node version: 14.17.6
  • npm version: 8.4.1
  • mocha version: 9.2.2
  • ts-node version: 10.7.0

Steps to reproduce

Example repo here: https://github.com/lostvicking/esm-ts-auto-mock-example
Run npm test

Expected behavior

Expect createMock to generate a mock of specified type without errors.

Actual behavior

An error is thrown:

Error:
  hey, it looks like ts-auto-mock is not configured correctly! You can find the instructions here https://typescript-tdd.github.io/ts-auto-mock/installation.
  If you need further assistance feel free to drop a message on slack. (link at the bottom of https://typescript-tdd.github.io/ts-auto-mock)

    at r.createMock (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/ts-auto-mock/index.js:1:502)
    at file:///Users/victorneiman/Code/esm-ts-auto-mock-example/tests/test.ts:5:26
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async formattedImport (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async Object.exports.requireOrImport (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
    at async Object.exports.loadFilesAsync (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
    at async singleRun (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/Users/victorneiman/Code/esm-ts-auto-mock-example/node_modules/mocha/lib/cli/run.js:374:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions