GithubHelp home page GithubHelp logo

piotrwitek / ts-mocha Goto Github PK

View Code? Open in Web Editor NEW
190.0 6.0 25.0 216 KB

Mocha thin wrapper that allows running TypeScript tests with TypeScript runtime (ts-node) to get rid of compilation complexity

License: MIT License

TypeScript 33.29% JavaScript 66.71%
ts-mocha mocha typescript testing-tools typescript-tests

ts-mocha's Introduction

TS-Mocha

Latest Stable Version NPM Downloads NPM Downloads Codeship Status for piotrwitek/ts-mocha Greenkeeper badge

ts-mocha is a wrapper on top of mocha to allow running tests written in TypeScript without setting up a complicated setup in your project, it just works.

All mocha features are available without any limitation because ts-mocha is passing all the params to original mocha behind the scenes.

Why?

To setup Mocha with TypeScript you need to figure out how to set it up together, it's not an easy task and require some time and effort to setup correctly. Moreover this setup will stop working whenever mocha or ts-node introduce breaking changes, so you'll have to fix it and waste your time again.

This package handles all that concerns for you and let you use ts-mocha in the same way as a regular mocha while supporting TypeScript.

Also we added some useful options to make your life easier specifically for TypeScript projects, you can find them below.

How?

TS-Mocha has one only dependency - ts-node, which is used as a TypeScript runtime to execute tests that can import and run imported TypeScript source files as well. It is a thin wrapper that run node process with mocha and set up ts-node environment to handle .ts and .tsx files. To speed up TypeScript tests execution type-checking is disabled, using only transpile mode.

NOTE: This package does not include Mocha - Mocha is set as peer dependency, so I don't lock the consumer to a specific Mocha version and I don't have to update this package when Mocha is updated.

PRO TIP: To make your developer experience better I recommend to run type-checking in a separate process by starting TSC compiler (preferably in watch mode) in you terminal with --noEmit and --project flags.

Installation

# remember to install mocha if you don't have it already (npm i -D mocha)

npm i -D ts-mocha

# install recent Mocha and Expect @types packages for best DX
npm i -D @types/mocha @types/expect

Usage

- CLI Usage

CLI options consist of all the options of regular Mocha plus extra options below:

-p, --project <value> - relative or absolute path to a tsconfig.json file (equivalent of tsc -p <value>) [default: "./tsconfig.json"]

Example:

ts-mocha -p src/tsconfig.json src/**/*.spec.ts

--paths - feature toggle flag to enable tsconfig-paths integration [default: false]

tsconfig-paths is an optional dependency, make sure to install it locally in your project

When using path mapping via the paths compiler option in tsconfig.json this library utilizes the tsconfig-paths package, allowing for automatic resolution of aliased modules locations during test execution.

Check our test suite for a reference implementation: Link

Example:

ts-mocha --paths -p src/ src/**/*.spec.ts

--type-check - feature toggle flag to enable type checking in ts-node [default: false]

By default ts-mocha uses the --transpile-only option of ts-node to make tests run faster. Use the --type-check option to enable type checking in ts-node.

Example:

ts-mocha --type-check -p src/ src/**/*.spec.ts

Watch Mode

If you want your tests to be automatically rerun when your code changes, add both the -w flag and the --watch-files flag telling it to watch for typescript files.

Example:

ts-mocha test/**/*.spec.ts -w --watch-files '**/*.ts'

- Programmatic usage

In code you can use ts-mocha by adding a single require at the beginning of your script:

// set env variable to the `tsconfig.json` path before loading mocha (default: './tsconfig.json')
process.env.TS_NODE_PROJECT = './src/tsconfig.json'

// Optional: set env variable to enable `tsconfig-paths` integration
process.env.TS_CONFIG_PATHS = true;

// register mocha wrapper
require('ts-mocha');

For example:

process.env.TS_NODE_PROJECT = './src/tsconfig.json';
require('ts-mocha');
const Mocha = require('mocha');

const mocha = new Mocha();
mocha.addFile(`./src/file.spec.ts`);
mocha.run((failures) => {
  process.on('exit', () => {
    process.exit(failures); // exit with non-zero status if there were failures
  });
});

ts-mocha's People

Contributors

bvanreeven avatar dependabot[bot] avatar felipeplets avatar gfranco93 avatar greenkeeper[bot] avatar jimlynchcodes avatar jmfederico avatar jneander avatar joelharkes avatar kfern avatar patrickspies avatar piotrwitek avatar strantr avatar warting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ts-mocha's Issues

TSX Testing

How to test tsx files with jsx? It says: SyntaxError: Unexpected token <

Option '-r' not supported.

I am trying to have the base case running and fail at it.

Using this command line : ts-mocha --paths -p src/server/tsconfig.mocha.json src/server/**/*.test.ts

Using the tsconfig c/p-ed from here (extending it manually, so without "extends": "../tsconfig.base.json")

Without any mocha.conf, .mocharc.js nor entry in package.json

Once using the --paths option, I end up with this error message:

Option '-r' not supported. Trigger '[...]\node_modules\mocha\bin\mocha -h' for more details

EDIT: Afterward, I managed to have this error with mocha -r ts-node/register, so it's not ts-mocha-related. I let it opened in case somebody has an idea though

ts-node as peerDependency

My project already is using ts-node (v10), but this package brings it's own (v7). Perhaps it'd be possible to set ts-node as a peer dep and defer to the user to bring in a specific version?

How to pass babel transpiling to mocha?

I have a mixed JavaScript/TypeScript project. For running, the JavaScript files are getting transpiled via babel-node.

Now, I'm trying to set-up ts-mocha for running tests. However, I keep getting

src/index.js:3

import 'whatever';

^^^^^^

SyntaxError: Cannot use import statement outside a module

I guess, I would need to pass something like --compilers js:@babel/register to mocha. But how do I do that when using ts-mocha?

ts-mocha --watch is not re-running test cases on file changes

Hi!

I'm using ts_mocha 8 but it's not re-running test cases on file changes.

My mocha command is

ts-mocha \"test/**/*.ts\" --recursive --exit

If I add watch and watch-extensions options the tests are run once and not rerun when the tests or source code is modified

ts-mocha \"test/**/*.ts\" --watch --watch-extensions ts
...
[mocha] waiting for changes...

It's a bug? Any idea how can I solve it?

SO: Ubuntu 21.04
node -v: v12.22.1

Related dependencies:
"@types/mocha": "^9.0.0"
"mocha": "^8.2.1"
"ts-mocha": "^8.0.0"

How to run parallel tests using ts-mocha

How do we run the tests in parallel using ts-mocha?
In mocha --parallel and --jobs flags help in running it. But I've tried it with ts-mocha and it's not working.

CVE-2022-46175 on module json5 < 1.0.2

The library json5 is vulnerable to CVE-2022-46175, which exists in versions < 1.0.2.

severity: High (NVD severity: High).

This vulnerability has a known exploit available. Source: Github.

The vulnerability can be remediated by updating the library to any of the following versions 1.0.2, 2.2.2 or higher, using yarn upgrade json5.

ts-mocha ignores code errors in tests

I have a test file which has a typo in the import statement, but the test still passes. Is there a way to make the test fail due to compilation errors?

Example:

$ mkdir ts-mocha-syntax-errors
$ cd ts-mocha-syntax-errors
$ npm init -y
$ npm install typescript expect mocha ts-mocha
$ vi tsconfig.json
$ cat tsconfig.json
{
    "compilerOptions": {
        "esModuleInterop": true
    }
}
$ vi test.ts
$ cat test.ts
import expect from 'expect';
import {Blah, Blah, Blah} from '../something';

describe('numbers', () => {
    it('fourty two is fourty two', async () => {
        expect(42).toEqual(42);
    });
});
$ node_modules/ts-mocha/bin/ts-mocha test.ts


  numbers
    ✓ fourty two is fourty two


  1 passing (8ms)

That import {Blah, Blah, Blah} from '../something'; is an error. tsc test.ts correctly reports errors like test.ts:2:32 - error TS2307: Cannot find module '../something'..

peer dep for mocha-8

can we update the peer dep, not sure what the diff is between mocha-7 and mocha-8 but it seems to work ok, just seeing the npm warning, current latest is mocha-8.1.3

tsconfig paths not working

tsconfig.json

{
    "compilerOptions": {
        
        "paths": {
            "@logger/config": [
                "logger.config.ts"
            ]
        }
    },
 
}

index.ts

import * from "@logger/config"
...

ts-mocha -p tsconfig.json src/**/*.spec.ts

Error: Cannot find module '@logger/config'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)

mocharc.yml require not working with chai/require-expect

Given that i have added chai/require-expect to the require array in mocharc.yml
When i run npx mocha
Then it should include expect as a global function

-- Actually --

I get the following error:

TSError: ⨯ Unable to compile TypeScript: test/isthisforfun.spec.ts:7:9 - error TS2304: Cannot find name 'expect'.

mocharc.yml

allow-uncaught: false
async-only: false
bail: false
check-leaks: false
color: true
delay: false
diff: true
exit: false # could be expressed as "no-exit: true"
extension:
  - ts
forbid-only: false
forbid-pending: false
full-trace: false
# fgrep and grep are mutually exclusive
# grep: something
growl: false
ignore:
  - node_modules
  - src
inline-diffs: false
# needs to be used with grep or fgrep
# invert: false
recursive: false
reporter: spec
require:
  - "ts-node/register"
  - "chai/register-expect"
retries: 1
slow: 75
sort: false
spec: test/**/*.spec.ts # the positional arguments!
timeout: false # same as "no-timeout: true" or "timeout: 0"
trace-warnings: true # node flags ok
ui: bdd
v8-stack-trace-limit: 100 # V8 flags are prepended with "v8-"
watch: false
watch-files:
  - 'test/**/*.ts'

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "lib": ["es2019"],
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noResolve": false,
    "noEmitOnError": false,
    "noImplicitAny": true,
    "declaration": true,
    "sourceMap": true,
    "outDir": "dist/",
    "moduleResolution": "node",
    "preserveSymlinks": true,
    "skipLibCheck": true,
    "types": [ "node", "mocha" ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

package.json

{
  "name": "isthisforfun",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/chai": "^4.2.11",
    "@types/mocha": "^7.0.2",
    "@types/node": "^13.9.2",
    "babel": "^6.23.0",
    "chai": "^4.2.0",
    "mocha": "^7.1.1",
    "ts-mocha": "^7.0.0",
    "ts-node": "^8.7.0",
    "typescript": "^3.8.3"
  },
  "dependencies": {
    "@types/axios": "^0.14.0",
    "axios": "^0.19.2"
  }
}

Hack Fix
If i include the library as an import in each test it passes

import { expect } from 'chai';  // Using Expect style

ts-mocha does not resolve tsconfig path aliases when using ESM

When trying to execute a test importing a path alias ($lib) I get Cannot find package '$lib' imported from ....
Tests that do not import path aliases are running fine and I don't know what's the problem since I am already using the --paths option and I have tsconfig-paths installed.

This is my current config:
package.json

{
  "name": "test",
  "version": "0.0.1",
  "scripts": {
    "test": "ts-mocha --recursive -n loader=ts-node/esm -n experimental-specifier-resolution=node -p tsconfig.json --paths 'tests/**/*.spec.ts'",
  },
  "devDependencies": {
    "@sveltejs/adapter-node": "next",
    "@sveltejs/kit": "next",
    "@types/chai": "^4.3.0",
    "@types/expect": "^24.3.0",
    "@types/mocha": "^9.1.0",
    "@types/node": "^17.0.23",
    "@types/object-hash": "^2.2.1",
    "chai": "latest",
    "mocha": "latest",
    "svelte": "^3.46.6",
    "svelte-check": "^2.2.6",
    "svelte-preprocess": "^4.10.1",
    "ts-node": "^10.7.0",
    "ts-mocha": "^9.0.2",
    "tsconfig-paths": "^3.14.1",
    "tslib": "latest",
    "typescript": "next",
  },
  "type": "module",
  "dependencies": {
    "async-mutex": "^0.3.2",
    "level-rocksdb": "^5.0.0",
    "node-fetch": "^3.2.3",
    "object-hash": "^3.0.0",
    "secp256k1": "^4.0.3"
  }
}

tsconfig.json

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"baseUrl": ".",
		"rootDir": ".",
		"module": "ESNext",
		"target": "ESNext",
		"lib": ["ESNext"],
		"typeRoots" : ["./node_modules/@types", "./src"],
		"sourceMap": true,
		"resolveJsonModule": true,
		"alwaysStrict": true
	},
	"typeAcquisition": {
		"enable": true
	},
	"paths": {
		"$src/*": ["src/*"],
		"$lib/*": ["src/lib/*"],
		"$api/*": ["src/routes/api/*"],
		"$app/*": [".svelte-kit/runtime/app/*"]
	}
}

Environment

TS_NODE_TRANSPILE_ONLY=1;
TS_NODE_PREFER_TS_EXTS=1;

ts-mocha vs mocha --require ts-node/register

Hey, I'm having a hard time understanding what the difference is between these two commands. Basically, I've configured two tsconfig.json files and I use the --project parameter to import them separately.

The performance is much better with ts-mocha, thank you for that. But I see differences in behaviour, and I'm having a hard time wrapping my head around it...

package.json:

"test": "NODE_ENV=test mocha --timeout 25000 -r ts-node/register -r ts-custom-error src/*.test.* --exit",
"test:strict": "NODE_ENV=test ts-mocha --project ./tsconfig.strict.json --timeout 25000 -r ts-custom-error src/*.test.* --exit"

tsconfig.strict.json:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "strict": true
    }
}

Scenario 1

npm run test with strict: true: I get a lot of TS errors (this is expected)

Scenario 2

npm run test with strict: false: execution but worser performance than with ts-mocha

Scenario 3

npm run test:strict with strict: true: I get no TS errors and normal compilation, albeit fast performance (I expect a lot of TS errors, but don't get any)

Scenario 4

npm run test:strict with strict: false: I get no TS errors and normal compilation, albeit fast performance.

Watch not finding any files

Not sure if i'm missing something, but i ts-mocha works fine, but if i add the --watch flag i just end up with 0 passing (1ms)

Not sure what i'm missing?

My mocha.opts

--timeout 5000
--recursive
--check-leaks
--exit
--full-trace
--require ./test/setup.js

command

"test": "nyc ts-mocha --opts ./test/mocha.opts ./src/**/*.test.ts",
"test:watch": "ts-mocha --watch --watch-extensions ts ./src/**/*.test.ts",

ts-mocha v9 beta released

Hey,

I have published the next release of ts-mocha, you can try it using npm i ts-mocha@next

I have updated ts-node to the most recent v9 release.

Tests are passing so it should work as before, but please let me know if there are any issues.

ENUMs are not picked up from script

using ts-node ENV_FILE=development ts-node --inspect -r ts-node/register -r ./src/shared/types -r ./env -r tsconfig-paths/register src/start.ts
using ts-mocha NODE_ENV=development nyc ts-mocha -r ./env -r src/shared/types --paths ./tests/**/*.ts --exit"

src/shared/types.ts
Contains interfaces and types and enums that are not exported (not a module).
Types and interfaces are picked up by ts-mocha but not the enums.
Everything works fine when running server directly with ts-node.

aside: the path to ./src and /src are different because the relative path does not work on ts-mocha but /src does

Do not correspond to the line numbers on error

Hello!
Why does the line number in the console not match the line number in the code?

image

But if you comment out the string ' Util.promisify(Hg.clone);`, then there is no error with the line number.

image

How to fix?

Changes (angular) src/environments/environment*.ts files

I have several files in src/environments/ directory,
such as environment.alternate.ts:
export const environment = { production: false, envName : "alternate", version: "${project.version}", extendedVersion: "${extended-version}" };
These have template macros that are NOT intended to be expanded at compile time.

When I run:
npx ts-mocha -p . 'src/**/*.test.ts'

It expands the variables (incorrectly) in the environments files, ACTUALLY MODIFYING THOSE FILES

Note : the following command does not modify the files, so I will fall back to using ts-node directly
npx mocha --require ts-node/register 'src/**/*.test.ts'

Peer dependency warning, outdated version on npm?

I just installed ts-mocha in a fresh project folder without a dist-tag (so it should be latest version) and got this error:

npm WARN [email protected] requires a peer of mocha@^3.2.0 but none is installed.
You must install peer dependencies yourself.

This surprised me since the package.json in this repository (version 1.0.3) states that both Mocha 3 and 4 (which I use) are supported as peer dependencies (^3.X.X || ^4.X.X). The version of ts-mocha that I've installed (also 1.0.3?!) however only supports Mocha 3 (^3.2.0), so I get this error message. Is the latest version not on npm? 😕

Support for mocha 10

mocha@10 was released yesterday (see https://github.com/mochajs/mocha/releases/tag/v10.0.0), are there any plans to support it?

npm ERR! Found: [email protected]
npm ERR! node_modules/mocha
npm ERR! dev mocha@"^10.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer mocha@"^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X || ^9.X.X" from [email protected]
npm ERR! node_modules/ts-mocha
npm ERR! dev ts-mocha@"^9.0.2" from the root project

how can I end the process with the programmatic version

I love this programmatic version. Thanks!

My question is, right now, i can do something like

ts-mocha -p tsconfig.json src/tests/**/*.ts --no-timeouts --exit

When the tests are complete. it will end the process. How would I / Can I do the same with your programmatic version?

Thanks!

Testing WorkerThreads with ts-mocha.

Hi, when trying to create a test that tests the behavior of WorkerThreads, it fails to start the application with this error message, failing to parse my workerScript.ts:

import { parentPort } from "worker_threads";
^^^^^^

SyntaxError: Cannot use import statement outside a module

The application itself can be started with and is working via node -r ts-node/register/transpile-only

Is there any option to test WorkerThreads behaviour via ts-mocha at all?

The tsconfig.json is parsed as JSON instead of JSON5

When you run tsc --init, you get a default setup for the tsconfig.json file, which is not actually a JSON file. It's a super-set of JSON which allows, amongst other things, trailing commas and comments in the JSON file. However, it seems like this module doesn't recognize this grammar, and thus fails to parse the default minimal setup with TypeScript:

SyntaxError: /home/.../tsconfig.json: Unexpected token / in JSON at position 29

After changing my tsconfig.json to be without comments (manually), the module works properly.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Errors are thrown as `[object Object]`

Whenever an error is thrown here, I can never see the actual error itself, for example:

/Users/kerberjg/Work/OSS/Yagura/yagura/node_modules/yargs/yargs.js:1163
      else throw err
           ^
[object Object]

How to use ts-mocha in code? (can't find any docs about this)

I used mocha in code like this:

const Mocha = require('mocha');
const mocha = new Mocha({ timeout: 50000 });
if (testSubject)
    mocha.addFile(`tests/integration/${testSubject}`);

now im trying to do the same for ts-mocha but it wont work.

I tried registering ts-node beforehand:

require('ts-node').register({ /* options */ });

but then i get errors that describe and it are no methods (of course).

Is there a way i can use ts-mocha like this?

Btw thanks for your amazing library, super happy to use it, its amazing!

Test context is undefined

I have a test suite in plain JS and a project which is only somewhat migrated to TS.
My tests works fine with regular mocha using the transpiled JS, but when using ts-mocha on the mixed js/ts code I get some difference in behaviour. Mainly, the context of the before/after functions is undefined.

Example:

before(async() => {
  // some setup code that uses the mocha test context through "this"
}

...
describe( ... )

When this is run with ts-mocha, this is undefined in before, after etc, with plain mocha this is set to the test context object.
Am I doing something wrong or does ts-mocha not have equivalent semantics as mocha?

EDIT: I found that arrow functions are discouraged in mocha: https://mochajs.org/#arrow-functions and that changing to function solves the issue! However, the same code works in mocha but not in ts-mocha, so there's still a discrepancy?

Upgrade Typescript to latest version in Ts-Mocha

Hi we are currently using ts-mocha for unit test but lately when we trying to pull in react-pdf beta version, we can't run our test in Github CI because ts-mocha is using an old version of typescript which is 3.3 while our project is using 4.3 and pdf.js is using 4.7. Is there any chance u can upgrade you project with the latest typescript version

Use ts-mocha with mocha-parallel-tests

Is there a way to use mocha-parallel-tests under the hood instead of plain mocha when running ts-mocha?

(I have searched in issues and pull requests here, and briefly Googled it, and could not find any answer.)

Thanks.

TypeError: Unknown file extension ".ts" - esmodules support

Original post in Anchor repo: [(https://github.com/coral-xyz/anchor/issues/1286)]

Anchor.toml [script] command:
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

The problem is the m1.ts file cannot import functions from another ts file!!!???
in my utils.ts

export const log1 = console.log;

in my m1.ts file:

import { log1 } from './utils';
describe('scenario1', async () => {
  it('initialize', async () => {
    log1('\n---------== init');
  });
});

the imported log1 function or any other function will cause the Unknown file extension ".ts" error!!??

my local package dependencies:
"mocha": "^9.1.3",
"ts-mocha": "^9.0.0-alpha1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"

Please advise. Thank you
unknown file extension ts2

Support mocha 9

And any plans to support mocha 9?
npm WARN [email protected] requires a peer of mocha@^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X but none is installed. You must install peer dependencies yourself.

Originally posted by @teolag in #61 (comment)

What is the added value on top of just using ts-node/register?

We use ts-node/register currently to run mocha tests with TS in watch mode. In development, our express service is ran with ts-node-dev, which combines ts-node and node-dev, so the watching is optimized. I was hoping to see the same with this package. If I look at the code, ts-node/register is just being used. So I wonder what the actual extra added value of this package is on top of ts-node/register?

Imho, this would be a welcome addition to the readme, so people will know, as if you don't want to use any of the extra stuff, you can just use ts-node/register.

How can I --require .ts files?

Hi, I would like to require a file, so it runs before all of my tests.
Example: ts-mocha -r test/setup.ts \"test/**/*.test.ts\"

If I run this I get the following error: TypeError: Unknown file extension ".ts".
If I try to run the setup.mjs file, which I had before, when I wasn't using typescript, all the imports in that file don't work, because they are from .ts files.

What's the best way to get this working with ts-mocha?

Runner ignores js spec files

Hi,

We're slowly migrating our codebase to TS and have specs in both JS and TS.
Using this command, JS tests seem to be skipped ts-mocha -p tsconfig.json src/**/*.spec.[jt]s.

Is this intentional?

Using nyc with ts-mocha

Hi! Are there any examples for using nyc with ts-mocha? We've just adopted ts-mocha in Shields in badges/shields#3722, and our frontend test coverage stopped working at the same time (at least, the new TypeScript files aren't getting included in the coverage reports, even if I add them to the config).

Shields is a relatively complicated repo and I had to fiddle with our nycrc to get frontend test coverage in the first place.

I found these resources for TS coverage with Istanbul/NYC, but they aren't for ts-mocha:

Some pointers or an example repo where this is working would be really helpful!

Add changelog.md

You need autogenerated changelog from git history and you can usage popular commit guideline

commit prefix:
feat
fix
docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.