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

Problems running with typescript #13

Closed
marcoturi opened this issue Oct 13, 2016 · 3 comments
Closed

Problems running with typescript #13

marcoturi opened this issue Oct 13, 2016 · 3 comments

Comments

@marcoturi
Copy link

Hi @artberri and thank you for your plugin. I'm having a similar issue of #6 , but with typescript. Here is the code i use:

https://github.com/hotforfeature/ionic2-boilerplate/blob/master/config/karma.conf.js

I can't put rollup-plugin-istanbul before rollup-plugin-typescript otherwise I get:

Error: Line 4: Unexpected token ILLEGAL
    at constructError (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:2407:21)
    at createError (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:2426:17)
    at unexpectedTokenError (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:2501:13)
    at throwUnexpectedToken (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:2505:15)
    at scanPunctuator (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:842:13)
    at advance (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:1622:16)
    at lex (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:1691:78)
    at consumeSemicolon (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:2606:13)
    at parseImportDeclaration (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:5455:9)
    at parseStatementListItem (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:3975:24)
    at parseScriptBody (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:5490:25)
    at parseProgram (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:5506:16)
    at Object.parse (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/node_modules/esprima/esprima.js:5690:23)
    at Object.instrumentSync (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/istanbul/lib/instrumenter.js:459:31)
    at Object.transform (/Users/marco/Sources/Github/ionic2-boilerplate/node_modules/rollup-plugin-istanbul/dist/rollup-plugin-istanbul.cjs.js:28:27)
    at /Users/marco/Sources/Github/ionic2-boilerplate/node_modules/rollup/src/utils/transform.js:19:35

At the same time i get the istanbul/lib/report/html.js:241:45 error of #6 if i keep the plugin after the others. For further info marcoturi/ionic-boilerplate#5

@joaovieira
Copy link

Can't get this to work with Typescript as well.

When not using Istanbul plugin, the sourcemaps are loaded correctly for all files in the bundle.

screen shot 2016-12-01 at 15 01 55 2

With istanbul, the instrumented files "loose" their mapping.

screen shot 2016-12-01 at 15 34 59 2

Not sure this should happen already in the first place, but then the coverage report gets the wrong lines as mentioned in marcoturi/ionic-boilerplate#5

screen shot 2016-12-01 at 15 37 13

The plugin is instrumenting the transpiled and bundled code. The instrumented parts point to the original file (TS), but somehow seem to actually map the intermediary transpiled (foo.js) file?

intermediary foo.js:

export function foo() {
    return 1;
}
export function bar(smt) {
    return smt === 'foo';
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "moduleResolution": "node",
    "declaration": true,
    "sourceMap": true
  }
}

karma.config.js:

const node = require('rollup-plugin-node-resolve')
const tsc = require('rollup-plugin-typescript')
const typescript = require('typescript')
const istanbul = require('rollup-plugin-istanbul')

const TESTS = 'test.ts'
const EXTERNAL = 'node_modules/**/*'

module.exports = function (config) {
  config.set({
    frameworks: ['jasmine'],
    files: [ TESTS ],
    preprocessors: {
      [TESTS]: ['rollup']
    },
    rollupPreprocessor: {
      plugins: [
        tsc({typescript}),
        node({ jsnext: true }),
        istanbul({
          exclude: [TESTS, EXTERNAL]
        })
      ],
      format: 'iife',
      sourceMap: 'inline'
    },
    reporters: ['coverage'],
    browsers: ['Chrome'],
    singleRun: true
  })
}

I've tried to compile TS before running Karma, having sourcemaps available for remap-istanbul but to no success or little success.

@jlmakes
Copy link

jlmakes commented Dec 29, 2016

@joaovieira I had a similar issue, where line numbers were not accurate; I solved that by using:

instrumenterConfig: {
    embedSource: true
}

Not sure if that's any help.

@marcoturi I too experienced unexpected token errors having rollup-plugin-istanbul before my transpiler. I believe you SHOULD have your transpiler before istanbul, and instead, take a look at these discussion concerning #6:

karma-runner/karma-coverage#157
karma-runner/karma-coverage#167

And in the Istanbul repo:
gotwarlost/istanbul#429

There's even a fork of the latest istanbul with an alleged fix:
https://github.com/jansoren/istanbul

@artberri
Copy link
Owner

artberri commented Dec 7, 2017

Sorry for being late answering here.

The new v2.0.0 version uses now the new istanbul instrumenter. Please double check if you keep suffering the error.

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

4 participants