Using the package with jasmine-ts (ts-node)
See original GitHub issueHi,
I use Typescript files that are transpiled to Javascript in a dist folder (works fine) and Typescript spec files for my unit tests (my problem). I have a deep directory structure so I use the paths section of tsconfig.json to map my folders to my modules. I noticed that when I run jasmine-ts to evaluate my spec files, the paths section is not taken into account and thus I get “Error: Cannot find module” error messages.
I think tsconfig-paths should solve this problem but I can’t figure out what’s wrong.
<root>/package.json contains:
"test": "jasmine-ts -r tsconfig-paths/register \"tests/**/*.spec.ts\" JASMINE_CONFIG_PATH=./jasmine.json",
root/tsconfig.json contains
"paths": {
"*":["src/*"],
"engines/*": ["src/engines/*"],
"typings-custom/*": ["typings-custom/*"]
},
root/jasmine.json contains:
{
"spec_dir": "tests",
"spec_files": [
"**/*[sS]pec.ts"
],
"helpers": [
"helpers/**/*.ts"
],
"stopSpecOnExpectationFailure": true,
"random": true
}
root/src/engines/engine1.ts contains
export default class Engine1 {
[...]
}
root/tests/unit/specs/engine1.spec.ts contains:
import engine1 from "engines/engine1"; //<= Cannot find module
works fine when I put the relative but ugly path
import engine1 from "../../../src/engines/engine1";
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Typescript with Jasmine: easy project setup | by Turhan Oz
jasmine : it is a testing framework for javascript code. It does not require DOM · ts-node : typescript source code does not...
Read more >Unit testing using Jasmine and TypeScript - Stack Overflow
Here's (in my opinion) the best way to test a ts-node app as of 2018: npm install --save-dev typescript jasmine @types/jasmine ts-node.
Read more >jasmine-ts - npm
Start using jasmine-ts in your project by running `npm i jasmine-ts`. There are 15 other projects in the npm registry using jasmine-ts.
Read more >svi3c/jasmine-ts: Executes jasmine tests with ts-node - GitHub
In your package.json file create a test script: { "scripts": { "test": "jasmine-ts \"path/to/specs/**/*.spec.ts\"" } } · Initialize jasmine. npx jasmine-ts init.
Read more >TypeScript and Jasmine playground
For easing the transpilation process of TypeScript, we will use ts-node. npm init --yes # It will create package.json file npm install ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into the same issue and fixed it by using ts-node with jasmine like this:
I suspect the issue is with jasmine-ts but don’t have time to investigate / think it’s probably best not to get too far away from ts-node as it’s already an abstraction.
I’ll close this because of inactivity. Please re-open if you still have the issue.