question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using the package with jasmine-ts (ts-node)

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jellingcommented, Oct 14, 2018

I ran into the same issue and fixed it by using ts-node with jasmine like this:

 "test:alloy": "ts-node -r tsconfig-paths/registernode_modules/jasmine/bin/jasmine.js \"services/**/**.service.spec.ts\"",

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.

0reactions
jonaskellocommented, Jul 16, 2018

I’ll close this because of inactivity. Please re-open if you still have the issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found