Getting an error after Basic setup about unexpected token % in JSON at position 0
aurimas-darguzis opened this issue · comments
-
**I'm submitting a ... **
- bug report
- feature request
-
Do you want to request a feature or report a bug?
I would like to report a bug. -
What is the current behavior?
Currently, after installing the package as the dev dependency and setting up everything in karma.config file as suggested in the docs, and after running the tests, I get the following error message:
HeadlessChrome 67.0.3396 (Mac OS X 10.13.3) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1 -
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
After basic setup - running the karma tests I get the error 'Unexpected token % in JSON at position 0' -
What is the expected behavior?
No errors -
Please tell us about your environment:
- version: 5.2.9
- Browser: Chrome Headless
- Language: TypeScript 2.3.4
- Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
Thank you for looking into this. Please do ask if I can give any additional information that can help to resolve this issue.
Interesting, I have not seen this error. Could you post your karma-config file somewhere? Also, can you run your karma suite in debug mode (--log-level debug
) and post the logs here?
Hi joeljeske, thank you for coming back to promptly. Here is the karma-config file:
As for the logs - do you mean simply copy paste log info from the console, or is there a file somewhere that karma dumps all the logs? Sorry for the last part, I don't use karma very often.
module.exports = function(config) {
config.set({
basePath: './',
frameworks: ['parallel', 'jasmine'],
files: [
'node_modules/babel-polyfill/browser.js',
{ pattern: 'karma-test-shim.ts', watched: false },
{ pattern: 'src/**/*.spec.ts', watched: true }
],
exclude: [],
preprocessors: {
'**/*.ts': ['webpack']
},
reporters: ['progress', 'bamboo'],
port: 1111,
colors: true,
customLaunchers: {
ChromeCustom: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
browsers: ['ChromeCustom'],
singleRun: true,
concurrency: Infinity,
webpack: require('./webpack-karma.config'),
webpackMiddleware: {
noInfo: true
},
plugins: [
require('karma-parallel'),
require('karma-bamboo-reporter'),
require('karma-webpack'),
require('karma-chrome-launcher'),
require('karma-jasmine')
],
parallelOptions: {
executors: 4, // Defaults to cpu-count - 1
shardStrategy: 'round-robin'
// shardStrategy: 'description-length'
},
mime: { 'text/x-typescript': ['ts', 'tsx'] }
});
};
I just mean copying and pasting the stdout/err here. Passing the That debug flag provides more useful information
I have gotten the same error.
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
HeadlessChrome 67.0.3396 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token % in JSON at position 0
at http://localhost:9876/context.html:1
Finished in 7.806 secs / 0 secs @ 09:48:25 GMT+0300 (IDT)
SUMMARY:
✔ 0 tests completed
No type errors found
Version: typescript 3.0.1
Time: 34245ms
From some investigation, it falls on web initial file loading script
https://github.com/joeljeske/karma-parallel/blob/master/lib/karma-parallelizer.js#L155
The %KARMA_SHARD_INFO%
variable was not replaced so it understandable why json.parse
failed.
It seems the beforeMiddleware
is not executed
https://github.com/joeljeske/karma-parallel/blob/master/lib/middleware.js#L39
I traced in back to our karma version which was a very old one that did not have support for before middlewares
. After updating Karma to the latest version ( > 2.0) this error was resolved.
Yes, we do not support karma < v1. I have added an explicit peer dependency to ensure awareness when installing the package.
Thanks!