Code Monkey home page Code Monkey logo

Comments (5)

twolfson avatar twolfson commented on July 20, 2024

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)

from karma-electron.

trusktr avatar trusktr commented on July 20, 2024

@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?

from karma-electron.

trusktr avatar trusktr commented on July 20, 2024

Seems like something in karma or karma-electron is choosing not to log the full error output?

from karma-electron.

twolfson avatar twolfson commented on July 20, 2024

from karma-electron.

trusktr avatar trusktr commented on July 20, 2024

Alright, after disabling karma-electron, and using default values for the browser,

karma.config.js
module.exports = function(config) {

    config.set({

        frameworks: ['jasmine', 'stacktrace'],
        port: 9876,  // karma web server port
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        singleRun: debugMode ? false : true,
        concurrency: Infinity,

        basePath: CWD,

        
        files: [
            'tests/**/*.js',
        ],
        client: {
            useIframe: false,
            loadScriptsViaRequire: true,
        },

    })

}

the errors are still in the same format. So for this simple test file,

test file
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 Chrome instead of Electron:

error output:
09 04 2019 19:26:37.163:INFO [karma-server]: Karma v4.0.1 server started at http://0.0.0.0:9876/
09 04 2019 19:26:42.625:INFO [Chrome 73.0.3683 (Mac OS X 10.14.3)]: Connected on socket pI2-vVfZy7mtUSeIAAAA with id manual-6446
Chrome 73.0.3683 (Mac OS X 10.14.3) ERROR
  {
    "message": "An error was thrown in afterAll\nError: test error\n    at tests/test.js:3:7",
    "str": "An error was thrown in afterAll\nError: test error\n    at tests/test.js:3:7"
  }

Longer errors can be even worse:

longer error:
09 04 2019 19:25:43.803:INFO [karma-server]: Karma v4.0.1 server started at http://0.0.0.0:9876/
09 04 2019 19:25:46.689:INFO [Chrome 73.0.3683 (Mac OS X 10.14.3)]: Connected on socket EkGfojpmOhFDLuihAAAA with id manual-3879
Chrome 73.0.3683 (Mac OS X 10.14.3) ERROR: 'DEPRECATION:', 'Setting specFilter directly on Env is deprecated, please use the specFilter option in `configure`'

Chrome 73.0.3683 (Mac OS X 10.14.3) ERROR
  {
    "message": "An error was thrown in afterAll\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\
nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError:
Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected iden
tifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntax
Error: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpec

ted identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier
\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxErro
r: Unexpected token {\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected
 identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSynt
axError: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexpected string\nSyntaxError: Unexpected strin
g\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexp
ected identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexpected string\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token export
\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxEr
ror: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpecte
d identifier\nSyntaxError: Unexpected token *\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token *\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token *",
    "str": "An error was thrown in afterAll\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyn
taxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unex
pected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifi
er\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxErro
r: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected
identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSy
ntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: U
nexpected token {\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected ide
ntifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxEr
ror: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexpected string\nSyntaxError: Unexpected string\nS
yntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token {\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexpecte
d identifier\nSyntaxError: Unexpected string\nSyntaxError: Unexpected string\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token export\nSy
ntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError:
 Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected identifier\nSyntaxError: Unexpected id
entifier\nSyntaxError: Unexpected token *\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token *\nSyntaxError: Unexpected token export\nSyntaxError: Unexpected token *"
  }

So it seems like it is something to do with Karma.

from karma-electron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.