Skip to content

Can't run tests in Typescript #4900

@Rc85

Description

@Rc85

Prerequisites

node ../../node_modules/mocha/bin/mocha -r ts-node/register --loader=ts-node/esm

  • [x ] Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • [x ] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • [x ] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • [x ] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

At first, I was getting this error Debug Failure. False expression: Non-string value passed to ts.resolveTypeReferenceDirective, likely by a wrapping package working with an outdated 'resolveTypeReferenceDirectives' signature. This is probably not a problem in TS itself.

Upgraded ts-node to latest version and then got this error ``TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts".

Added the --loader=ts-node/esm flag and now I'm getting this error ReferenceError: exports is not defined in ES module scope

Played around with module and target in tsconfig.json and none has helped. Changing target from commonjs to es2015 gives me error saying that it Error: Cannot find module yadayada import from soandso.

I'm out of ideas.

Steps to Reproduce

  1. Install Typescript 4.5.4, ts-node 10.8.2, mocha 10.0.0, run tests written in typescript with the npm command above.

Expected behavior: Should run tests

Actual behavior: Tests not running due to error mentioned above.

Reproduces how often: 100%

Versions

typescript 4.5.4
ts-node 10.8.2
mocha 10.0.0

Windows 10 64-bit

  • The output of mocha --version and node_modules/.bin/mocha --version:
  • The output of node --version:
  • Your operating system
    • name and version:
    • architecture (32 or 64-bit):
  • Your shell (e.g., bash, zsh, PowerShell, cmd):
  • Your browser and version (if running browser tests):
  • Any third-party Mocha-related modules (and their versions):
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: integrationsrelated to working with 3rd party software (e.g., babel, typescript)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions