Closed trusktr closed 5 years ago
Looking at our resolution in #32, I'm going to assume we're still using babel-register
. I have a feeling that there is no stack trace because there is no stack to dump (i.e. it's only 1 level deep)
The error looks like it's coming from the Babel transpiler reading in /Users/joepea/src/trusktr+infamous/src/html/behaviors/Behavior.js
, it's not an error from Electron running the file -- but when it transpiles it instead
For reference, here's what a normal runtime error stacktrace looks like:
Electron 1.8.8 (Node 8.2.1) module for `require` based Node.js integrations in the top level identify as the page itself FAILED
Error: Test error
at throwTestError (/home/todd/github/karma-electron/test/integration-test/node-require-test.js:22:9)
at Context.<anonymous> (/home/todd/github/karma-electron/test/integration-test/node-require-test.js:29:7)
@twolfson Alright, I've done some debugging. I've found out that the errors are being thrown from within the require()
calls that I have in the @babel/register
setup.
However, the stack traces are deep, and I can see the stack traces if I modify the code to catch them and log them manually.
Here's that part of my karma config.
I modified that part of my karma config so it looks like the following:
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.log(e)
process.exit()
}
` )
})
Before doing this, I was seeing an error like:
Electron 2.0.18 (Node 8.9.3) ERROR
{
"message": "Uncaught TypeError: Cannot read property 'default' of undefined\nat /Users/trusktr/src/trusktr+infamous/src/core/ImperativeBase.js:100:129\n\nundefined",
"str": "Uncaught TypeError: Cannot read property 'default' of undefined\nat /Users/trusktr/src/trusktr+infamous/src/core/ImperativeBase.js:100:129\n\nundefined"
}
Then after adding the try-catch and logging the error I was able to see:
Electron 2.0.18 (Node 8.9.3) LOG: TypeError: Cannot read property 'default' of undefined
TypeError: Cannot read property 'default' of undefined
at exports.default.Base (/Users/trusktr/src/trusktr+infamous/src/core/ImperativeBase.js:100:129)
at /Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:54:36
at /Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:64:17
at /Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:132:17
at /Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:44:12
at ApplyDefault (/Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:119:22)
at Mixin (/Users/trusktr/src/trusktr+infamous/node_modules/lowclass/Mixin.js:37:13)
at initImperativeBase (/Users/trusktr/src/trusktr+infamous/src/core/ImperativeBase.js:100:58)
at getImperativeBaseProtectedHelper (/Users/trusktr/src/trusktr+infamous/src/core/ImperativeBase.js:62:3)
at Object.<anonymous> (/Users/trusktr/src/trusktr+infamous/src/core/Motor.js:15:86)
So my question is, if I don't catch the error and log it my self, what in the stack is deciding to display such a limited version of the error?
Seems like something in karma or karma-electron is choosing not to log the full error output?
I can't think of anything off the top of my head. Pretty confident it's either Karma or your repo since we do nothing to tweak errors in karma-electron
Easiest way to find out would be to try another Karma engine (would disqualify/prove karma-electron) and use a simpler repo (would disqualify/prove your repo)
On Tue, Apr 9, 2019, 2:57 PM Joe Pea notifications@github.com wrote:
Seems like something in karma or karma-electron is choosing not to log the full error output?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/twolfson/karma-electron/issues/35#issuecomment-481455301, or mute the thread https://github.com/notifications/unsubscribe-auth/AA3FWDkER8iZFZLANlBqLgfGPexmUk1Lks5vfQzJgaJpZM4bT8NW .
Alright, after disabling karma-electron, and using default values for the browser,
the errors are still in the same format. So for this simple test file,
the error output is in the same format, but they are now tagged with Chrome
instead of Electron
:
Longer errors can be even worse:
So it seems like it is something to do with Karma.
When I get errors in my test code, I often see them formatted in the console like so:
I noticed that the errors are the same format regardless which karma reporter I use.
Is it karma-electron outputting them like that? If so, how can I get it to output full formatted stack traces