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

Unable to run tests directly against tyepscript files #496

Open
FlippieCoetser opened this issue Sep 11, 2021 · 1 comment
Open

Unable to run tests directly against tyepscript files #496

FlippieCoetser opened this issue Sep 11, 2021 · 1 comment

Comments

@FlippieCoetser
Copy link

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
Copy link

JiaHenry commented Mar 4, 2022

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

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

2 participants