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

Sourcemaps do not work #114

Closed
tomitrescak opened this issue Feb 10, 2017 · 17 comments
Closed

Sourcemaps do not work #114

tomitrescak opened this issue Feb 10, 2017 · 17 comments

Comments

@tomitrescak
Copy link

Thanks for the nice package. I have issues making sourcemaps work. I have tried adding --no-cache but I'm still getting error lines of transpiled source (or did I miss anything that console errors should be mapped to correct line?)

Here is my package.json

{
  "scripts": {
    "test": "jest --no-cache",
  },
  ...
  "jest": {
     "globals": {
      "__TS_CONFIG__": "tsconfig.test.json"
    },
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/.storybook/__mocks__/fileMock.js",
      "\\.(css|less)$": "<rootDir>/.storybook/__mocks__/styleMock.js"
    },
    "setupFiles": [
      "<rootDir>/jest.startup.js"
    ],
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "snapshotSerializers": [
      "<rootDir>/node_modules/enzyme-to-json/serializer"
    ]
  }
}

And here is the tsconfig.test.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "lib": [
            "dom",
            "es2015",
            "es2016"
        ],
        "noEmitHelpers": false,
        "emitDecoratorMetadata": true,
        "jsx": "react",
        "target": "es2016",
        "module": "commonjs",
        "moduleResolution": "node",
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "strictNullChecks": false,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noUnusedLocals": false,
        "noUnusedParameters": true,
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "experimentalDecorators": true,
        "outDir": "./build",
        "types": [
            "chai",
            "react"
        ],
        "typeRoots": [
            "src/typings/overrides",
            "node_modules/@types"
        ],
        "pretty": true
    },
    "exclude": [
        "node_modules"
    ]
}
@kulshekhar
Copy link
Owner

can you create a minimal repo that reproduces the issue you're facing?

@kulshekhar
Copy link
Owner

closing due to lack of response. If this needs to be reopened, let me know

@tkrotoff
Copy link
Contributor

tkrotoff commented Feb 28, 2017

@kulshekhar and what about providing an example with ts-jest GitHub repo? this is a good common practice.
This will help people understand how to setup ts-jest and play with it. As of myself, I went back to run tsc as a pre-task and could not see any benefit to ts-jest due to the lack of a clear and simple working example, see #46 (comment)

@kulshekhar
Copy link
Owner

@tkrotoff there are tests in the repo that can help understand how to use ts-jest. These tests cover a lot of scenarios. In any case, if you think there's something that can be added that would improve this package, PRs are most welcome :)

@tkrotoff
Copy link
Contributor

tkrotoff commented Mar 1, 2017

@kulshekhar

there are tests in the repo that can help understand how to use ts-jest

Tests are not user friendly, examples are.

See PR #118

@kulshekhar
Copy link
Owner

@tkrotoff can't argue with that

@RaulTsc
Copy link

RaulTsc commented Jul 11, 2017

Also facing this problem. Not sure how to get sourcemaps to work.

Sorry if this looks like a stackoverflow issue.

Maybe we can improve the documentation.

Would very much appreciate any hint!

package.json:

"jest": {
    "transform": {
      ".*": "<rootDir>/jest-preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "modulePaths": [
      "./src"
    ],
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json",
      "ts",
      "tsx"
    ],
    "moduleDirectories": [
      "node_modules",
      "src"
    ]
  }

ts-preprocessor.js:

const tsc = require('typescript');
const tsConfig = require('./tsconfig.json');

module.exports = {
  process(src, path) {
    if (path.endsWith('.ts') || path.endsWith('.tsx')) {
      var tscCode = tsc.transpile(
        src,
        tsConfig.compilerOptions,
        path,
        []
      );
      return tscCode;
    }
    return src;
  },
};

tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "baseUrl": "./src",
    "rootDir": "./src",
    "declaration": false,
    "sourceMap": false,
    "inlineSourceMap": true,
    "lib": ["es7", "es2017"],
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "typeRoots" : [
      "./node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

@kulshekhar
Copy link
Owner

@RaulTsc It would be more helpful if you opened a new issue and created a minimal repo that demostrates this issue. It'll be hard to look into this without something like that

@RaulTsc
Copy link

RaulTsc commented Jul 11, 2017

@kulshekhar Thanks! I will do that!

@kirillgroshkov
Copy link
Contributor

sourcemaps are not working for me as well..

@kulshekhar
Copy link
Owner

@kirillgroshkov can you create a minimal repo that demonstrates the issue? It'll be hard to figure out what the problem in your setup is otherwise

@NathanBraslavski
Copy link

I have the same problem :-(
Did anyone create a minimal repo already?

@villelahdenvuo
Copy link

I was also struggling with broken sourcemaps, but disabling coverage made them work! I'm using Jest 24.5.0. I just changed my debug script to add --coverage=false and sourcemaps started working.

@xeptore
Copy link

xeptore commented Oct 10, 2019

@villelahdenvuo this is exactly why i love JS :)

@eurostar-fennec-cooper
Copy link

I was also struggling with broken sourcemaps, but disabling coverage made them work! I'm using Jest 24.5.0. I just changed my debug script to add --coverage=false and sourcemaps started working.

Omg, this works 🎉

@rivertam
Copy link

rivertam commented Apr 8, 2020

(this is the first thing that comes up on Google)

This is a bug within Jest regarding coverage breaking source maps:

jestjs/jest#5739

@js-kyle
Copy link

js-kyle commented Apr 24, 2020

@rivertam thank you very much for posting the above

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