业力打字稿:已编译的文件名被添加为内联sourcemap的源文件

时间:2018-09-15 22:31:38

标签: typescript google-chrome-devtools karma-runner source-maps karma-typescript

我对所有这些测试东西都是新手,所以可能只是我不了解某些东西,但是我已经设置了因果报应,摩卡,打字稿等项目。

在我进入Chrome开发人员工具并逐步执行代码之前,一切似乎都可以正常运行。在“源”选项卡中,我在测试项目中看到src文件夹和文件:

Chrome Source Tab

对于我的spec文件,我看到两个条目:已编译的js,然后是从js文件中的源映射信息派生的源ts。在我的规范源文件中,我正在导入TestClass.ts类。此文件列出了3次:编译后的js文件和ts版本,还有另一个同名的js文件。 TestClass.ts和第二个TestClass.js是从第一个TestClass.js内联的源映射派生的。

==>问题是当我单步执行代码并击中TestClass时,它将在映射的TestClass.ts和TestClass.js之间来回跳转。它不会仅停留在ts中。

我猜这是由于在源图中都引用了它们,但是为什么会这样呢?为什么只使用导入的类,而不使用我的规范脚本?

sample.spec.ts:

import { expect } from "chai";
import { describe, it } from "mocha";

import TestClass from "./TestClass";

describe("Test A", function() {
    it("should pass", function(){
        expect(TestClass.getString()).to.be.a("string");
    });
});

TestClass.ts:

export default class TestClass {
    static getString () {
        return "This is a string";
    }
}

karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: "",
    frameworks: ["mocha", "chai", "sinon", "karma-typescript"],
    files: [
      "src/sample.spec.ts",
      "src/TestClass.ts"
    ],
    exclude:[
      "scr/**.*.js"
    ],
    preprocessors: {
      "**/*.ts": "karma-typescript" // *.tsx for React Jsx
    },
    reporters: ["karma-typescript","progress", "mocha"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ["ChromeDebug"],
    customLaunchers: {
      ChromeDebug: {
        base: "Chrome",
        flags: ["--remote-debugging-port=9333"],
        smartStep: true
      }
    },
    singleRun: false,
    karmaTypescriptConfig: {
        tsconfig: "./tsconfig.test.json"
    },
  })
}

tsconfig.test.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "lib": ["es2015"],
    "module": "commonjs",
    "moduleResolution": "node",
    "alwaysStrict": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
  },
  "exclude": [
    "node_modules",
    "buildtasks",
    "build",
    "tasks",
    "docs"
  ]
}

package.json:

{
    "name": "test",
    "version": "1.0.0-alpha.1",
    "description": "This is a test.",
    "dependencies": {},
    "devDependencies": {
        "@types/bluebird": "^3.5.24",
        "@types/chai": "^4.1.4",
        "@types/karma": "^1.7.6",
        "@types/mocha": "^5.2.5",
        "@types/sinon": "^5.0.2",
        "chai": "^4.1.2",
        "karma": "^3.0.0",
        "karma-chai": "^0.1.0",
        "karma-chrome-launcher": "^2.2.0",
        "karma-mocha": "^1.3.0",
        "karma-mocha-reporter": "^2.2.5",
        "karma-sinon": "^1.0.5",
        "karma-typescript": "^3.0.13",
        "mocha": "^5.2.0",
        "sinon": "^6.3.3",
        "typescript": "^3.0.3"
    },
    "scripts": {
        "karma:dev.test": "karma start karma.conf.js"
    }
}

几天前试图弄清楚这个。疯了我!

谢谢!

0 个答案:

没有答案