monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.
313 stars 109 forks source link

Unable to run tests directly against tyepscript files #496

Open FlippieCoetser opened 2 years ago

FlippieCoetser commented 2 years ago

This two-step process works:

  1. compile typescript files to es6 modules : tsc --project tsconfig.json
  2. run tests: karma start

Here is a copy of the tsconfig.json:

{
    "compilerOptions": {
        "module": "es2020",
        "moduleResolution": "node",
        "target": "es2020",
        "declaration": true,
        "noImplicitAny": false,
        "noImplicitThis": true,
        "noResolve": true,
        "allowJs": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
    },
    "exclude": [
        "node_modules",
        "karma.conf.js"
    ]
}

Here is a copy of the karma,conf.js:

module.exports = function(config) {
  config.set({
    basePath: "",
    frameworks: ["jasmine"],
    files: [
      { pattern: "**/*.test.js", type: "module", included: true },
      { pattern: "**/*.js", type: "module", included: false }
    ],
    exclude: [],
    preprocessors: {},
    reporters: ["spec"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ["Chrome"],
    singleRun: true,
    concurrency: Infinity
  });
};

This one-step process using karma-typescript does not work:

Here is a copy of the karma,conf.js after installing karma-typescript:

module.exports = function(config) {
  config.set({
    basePath: "",
    frameworks: ["jasmine", "karma-typescript"],
    files: [
      { pattern: "**/*.test.ts", type: "module", included: true },
      { pattern: "**/*.ts", type: "module", included: false }
    ],
    exclude: [],
    preprocessors: {
      "**/*.ts": ["karma-typescript"]
    },
    reporters: ["spec", "karma-typescript"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ["Chrome"],
    singleRun: true,
    concurrency: Infinity
  });
};

Here is a screenshot of the errors: image

How can I set up karma to use the typescript files rather than the compiled javascript files?

JiaHenry commented 2 years ago

Please remove the output js files created by tsc, otherwise they will be used instead of the expected output of karma-typescript.