-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Difficulty debugging errors, stack traces missing and/or poor formatting #3296
Difficulty debugging errors, stack traces missing and/or poor formatting #3296
Comments
Oddly, I don't get this error when I run the code with the window visible. To run it in that mode,
There doesn't seem to be any error in that case. Why might this be? |
To see karma plugins and versions, look inside of |
The reporter is suppose to format the errors, your reporter is 'spec' (IDK what it is). |
|
I updated to latest Karma, 4.0.1, and still see the same error ( |
Aha! Those errors are being thrown from the testFiles.forEach(file => {
const relativeFile = file.replace(CWD, '')
const relativePath = dirname(relativeFile)
mkdirp.sync( CWD + '/.karma-test-build' + relativePath )
const nodeModulesToCompile = config.nodeModulesToCompile
fs.writeFileSync( CWD + '/.karma-test-build' + relativeFile, `
// NOTE, we don't use babel.config.js settings here, we can target a
// more modern environment.
require('@babel/register')({
presets: [ ['@babel/preset-env', { targets: { node: 9 } }] ],
plugins: [
// We need to transpile the not-yet-official re-export syntax.
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
],
sourceMap: 'inline',
${config.nodeModulesToCompile ? `
ignore: [
// don't compile node_modules except for ones specified in the config
${nodeModulesToCompile.map(moduleName => {
return r`/node_modules(?!\/${r.escape(moduleName)}\/)/`
})}
],
` : ''}
})
// RIGHT HERE, LOG THE ERROR ----------------------------
try {
require( '${ file }' )
} catch(e) {
console.error(e)
throw e
}
` )
}) Now I can see the following in terminal:
which is much more helpful. So my question is, if I don't catch the error, then which part of the stack is deciding to output such limit ed information regarding the error? |
Not sure if it's a karma problem, or a karma-electron problem, so I posted there too: twolfson/karma-electron#35 (cc @twolfson) |
As you can see the error is coming from inside of Electron. So the error is not happening during karma's config loading. Rather the config is creating some code that is executed in Electron and that code fails a the 'top' level. The top level fail is calling the error handler here: This error handler conforms to |
@johnjbarton Upon further investigation, it doesn't seem like a karma-electron issue: I disabled karma-electron, and spec runner, and added karma-chrome-launcher and using progress reporter: karma.config.jsconst CWD = process.cwd()
module.exports = function(config) {
config.set({
frameworks: ['jasmine', 'stacktrace'],
reporters: ['progress'],
port: 9876, // karma web server port
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
singleRun: true,
concurrency: Infinity,
basePath: CWD,
browsers: ['ChromeHeadless'],
files: [
'tests/**/*.js',
],
})
} For the following simple test file, `test/test.js`console.log( 'test.js' )
throw new Error('test error')
describe('Tests...', () => {
it('needs to be implemented', () => {
expect(true).toBe(true)
})
}) the error output is in the same format, but they are now tagged with error output:
Longer errors can be even worse: long error
I made a reproduction: git clone [email protected]:trusktr/infamous
cd infamous
git checkout karma-issue-3296
npm install
npm test
# or
./node_modules/.bin/karma start ./node_modules/builder-js-package/config/karma.config.js I also tried it without karma-chrome-launcher, in which case I opened my browser to the localhost URL, and it gave me the same error formatting. It seems like the errors are being formatted that way by Karma. Or could it be Jasmine or stacktrace? Let me try mocha/chai... |
I disabled |
So, it seems in that small example the stack traces aren't missing, but as you see from my previous Seems like whatever is handling the error should just log the error directly, or log |
Strange: I am able to pause on the uncaught exceptions in devtools, so it seems that nothing is catching the errors. However, despite the errors not being caught, they do not show up in the console. |
I re-worded my previous comment; after reading it a second time, I couldn't even understand it myself. Basically I was saying that I can't see these errors in devtools console like we normally do with uncaught errors. The only way to see them is by turning on the "Pause on exceptions" option. |
My PR #3298 will make the error less mysterious but it may still have the line number of the transpile output, depending upon your sourcemap setup. |
Please try the new release. |
Expected behaviour
I'm hoping to see full stack traces, to aid in debugging.
Actual behaviour
I see output like the following, which is making it difficult to debug:
output:
As you can see, the only hint is line
98
, which doesn't match the original source because that line seems to be relative to transpiled code. Plus, without the stack trace it is hard to imagine what is happening.My karma config looks like the following:
karma.config.js:
Any ideas why the error output is so limited, or on how to make it show full stack traces? Maybe it isn't a karma problem, but a problem with a karma plugin? Thanks for any insight!
Environment Details
karma --version
): 2.0.5karma.config.js
file: see aboveSteps to reproduce the behaviour
Note,
npm test
ultimately runs the script innode_modules/builder-js-package/scripts/run-karma-tests.sh
:run-karma-tests.sh:
So, another way in which you can run the tests directly is:
The text was updated successfully, but these errors were encountered: