Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
0-sv opened this issue Mar 19, 2021 · 2 comments
Open

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

0-sv opened this issue Mar 19, 2021 · 2 comments

Comments

@0-sv
Copy link

0-sv commented Mar 19, 2021

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.

@0-sv
Copy link
Author

0-sv commented Mar 19, 2021

This seems to work:

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

But it doesn't work with ts-mocha as I expect with the --project flag:

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

@0-sv
Copy link
Author

0-sv commented Mar 19, 2021

I also have access to some environment variables, listed here: https://github.com/TypeStrong/ts-node/tree/629525474fb548fddb7a90a48ab795a9199b1997#cli-and-programmatic-options. Does this also work for ts-mocha?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant