You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
'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
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
Mocha runs the test in the compiled javascript file, instead of the test in the typescript file. My understanding of mocha with ts-node is that it should transpile the ts file on the fly, not read the javascript file.
Add console.log('foo') to packages\typescript\src\index.ts
Remove outDir in packages\typescript\tsconfig.json
run npm run compile. There will now be a index.js file in src.
run npm test. "foo" is shown
Change foo to fah in index.ts
run npm test
Expected behavior: fah
Actual behavior: foo
Reproduces how often: [What percentage of the time does it reproduce?]
100%
Versions
The output of mocha --version and node_modules/.bin/mocha --version: latest
The output of node --version: 16.14.2
Your operating system
name and version: Windows 10
architecture (32 or 64-bit): 64-bit
Your shell (e.g., bash, zsh, PowerShell, cmd): cmd
Your browser and version (if running browser tests):
Any third-party Mocha-related modules (and their versions): ts-node ^9.1.1
Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): typescript ^4.2.4
Additional Information
Might be a issue with ts-node. What's interesting about this is that packages\typescript\.mocharc.json specifies the ts extension only, so I don't know why it's reading the js. Same thing with spec, it specifies just ts.
If you're wondering how this scenario would happen in the real world, I run into it from time to time in https://github.com/almenon/AREPL-backend. I compile the typescript to publish the package but don't always have the compiler running, so the compiled files might not match the typescript files.
The text was updated successfully, but these errors were encountered:
Mocha can be configured to run on .ts source files using transpilers such as ts-node. But it doesn't do by default. By default, it just reads from .js files.
The mocha-examples/typescript example doesn't use a transpiler. That's why it has a separate compile command to run tsc.
So this is really a docs / examples request - that we don't have any examples showing on-the-fly transpilation. Filed mochajs/mocha-examples#75 to add examples. Thanks for reporting! 🙌
Prerequisites
faq
labelnode_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Mocha runs the test in the compiled javascript file, instead of the test in the typescript file. My understanding of mocha with ts-node is that it should transpile the ts file on the fly, not read the javascript file.
Steps to Reproduce
npm i
packages\typescript\src\index.ts
outDir
inpackages\typescript\tsconfig.json
npm run compile
. There will now be aindex.js
file in src.npm test
. "foo" is shownnpm test
Expected behavior: fah
Actual behavior: foo
Reproduces how often: [What percentage of the time does it reproduce?]
100%
Versions
mocha --version
andnode_modules/.bin/mocha --version
: latestnode --version
: 16.14.2Additional Information
Might be a issue with ts-node. What's interesting about this is that
packages\typescript\.mocharc.json
specifies thets
extension only, so I don't know why it's reading the js. Same thing with spec, it specifies justts
.If you're wondering how this scenario would happen in the real world, I run into it from time to time in https://github.com/almenon/AREPL-backend. I compile the typescript to publish the package but don't always have the compiler running, so the compiled files might not match the typescript files.
The text was updated successfully, but these errors were encountered: