ERROR [preprocessor.coverage]: Unexpected token
See original GitHub issueI am trying to add coverage to my project, I keep getting this error every time I run npm run karma
snippet of algorithms.js
/**
Currently used only for adding 'assert' class to algorithm lists
*/
import css from "text!../../assets/algorithms.css";
export const name = "core/algorithms";
export async function run() {
const elements = Array.from(document.querySelectorAll("ol.algorithm li"));
elements
.filter(li => li.innerText.trim().startsWith("Assert: "))
.forEach(li => li.classList.add("assert"));
if (document.querySelector(".assert")) {
const style = document.createElement("style");
style.textContent = css;
document.head.appendChild(style);
}
}
karma.conf.js
// Karma configuration
// Generated on Fri Feb 26 2016 13:09:51 GMT+1100 (AEDT)
/*globals module, require, process*/
"use strict";
module.exports = function(config) {
const options = {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "./",
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["jasmine", "requirejs", "detectBrowsers"],
// configuration
detectBrowsers: {
enabled: !config.browsers.length,
usePhantomJS: false,
postDetection(browsers) {
return (
browsers
// Remove IE
.filter(browser => browser !== "IE")
);
},
},
// list of files / patterns to load in the browser
files: [
"js/deps/jquery.js",
{
pattern: "assets/**/*.*",
included: false,
served: true,
},
{
pattern: "tests/support-files/**/*",
included: false,
served: true,
},
{
pattern: "builds/**/*.*",
included: false,
served: true,
},
{
pattern: "js/deps/marked.js",
included: false,
served: true,
},
{
pattern: "js/**/*.*",
included: false,
served: true,
},
{
pattern: "tests/**/*-spec.js",
included: false,
served: true,
},
{
pattern: "tests/data/**/*",
included: false,
served: true,
},
{
pattern: "tests/*.html",
included: false,
served: true,
},
{
pattern: "tests/**/*.html",
included: false,
served: true,
},
{
pattern: "worker/*.js",
included: false,
served: true,
},
{
pattern: "src/**/*.js",
included: false,
},
"tests/spec/SpecHelper.js",
"tests/test-main.js",
],
// list of files to exclude
exclude: ["**/*.swp", "*.swp", ".DS_Store"],
proxies: {
"/about-blank.html": "/base/tests/about-blank.html",
"/assets/": "/base/assets/",
"/js/": "/base/js/",
"/builds/": "/base/builds/",
"/tests/": "/base/tests/",
"/spec/": "/base/tests/spec/",
"/deps/": "/base/js/deps/",
"/js/deps/": "/base/js/deps/",
"/base/deps/": "/base/js/deps/",
"/worker/respec-worker.js": "/base/worker/respec-worker.js",
"/support-files/hljs-testlang.js":
"/base/tests/support-files/hljs-testlang.js",
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
"src/**/*.js": ["coverage"],
},
// test results reporter to use
// possible values: "dots", "progress"
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["mocha", "progress", "coverage", "coveralls"],
// web server port
port: config.port || 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// See "detectBrowsers"
//browsers: ["Chrome", "Safari", "Firefox"],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: 1,
browserNoActivityTimeout: 100000,
client: {
args: ["--grep", config.grep || ""],
},
coverageReporter: {
includeAllSources: true,
type: "lcov", // lcov or lcovonly are required for generating lcov.info files needed for coveralls.
dir: "coverage/",
},
};
if (process.env.TRAVIS) {
process.env.CHROME_BIN = require("puppeteer").executablePath();
options.detectBrowsers.enabled = false;
options.autoWatch = false;
options.singleRun = true;
options.concurrency = 1;
options.reporters = ["mocha", "progress", "coverage", "coveralls"];
options.browsers = ["ChromeHeadless"];
}
config.set(options);
};
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Unexpected token while running karma-coverage on ...
A preprocessor's purpose is to modify files before running them in tests. For example, changing imports or adding some polyfill . Just comment ......
Read more >Unexpected Token While Running Karmacoverage On
ERROR [preprocessor.coverage]: Line 12: Unexpected token #310.to find any documented karma.conf.js setting that would fix these errors.
Read more >Coverage - Karma test runner
If you want to generate the coverage, you need to configure up to three parts: preprocessor coverage (required); reporter coverage (required); reporter options ......
Read more >karma-typescript
Simplifying running unit tests with coverage for Typescript projects. ... ERROR [source-reader.karma-typescript]: Error parsing code: Unexpected token ...
Read more >karma-runner/karma - Gitter
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR SyntaxError: Unexpected token 'const' ... use this plugin also: https://github.com/babel/karma-babel-preprocessor.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are there any updates in this? I want to run karma with jasmine in Chrome, but I don’t want to transpile / bundle my ES6 modules. I can run the specs right now, but when I add coverage I get the Unexpected token error. How can I get karma-coverage to work with ES6 modules? Thanks!
I think this project will require work to fix tests and upgrade it.
Did you look at https://www.npmjs.com/package/karma-coverage-istanbul-reporter?