Code Monkey home page Code Monkey logo

Comments (9)

twolfson avatar twolfson commented on July 2, 2024 1

Alright, second PR is open: electron/electron#8890

Since this issue is not specific to our repo at all, we are going to close it. Thanks for the bug report and finding that edge case =)

from karma-electron.

GProst avatar GProst commented on July 2, 2024

Packages versions:
electron: 1.6.2
karma: 1.5.0
karma-electron: 5.1.1
karma-jasmine: 1.1.0
karma-ng-html2js-preprocessor: 1.0.0
angular: 1.6.2
angular-mocks: 1.6.2

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Thanks for the detailed bug report. I'm not sure what would cause this so we'll definitely need to triage. I'll perform a triage by the end of the weekend

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

We have successfully reproduced the error. We were able to reproduce with something as simple as:

var electron = require('electron');
console.log(electron);

My hunch is this is an issue in Karma's serializer due to Electron using some native modules but I'll keep on digging

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Okay, we've traced down the source of this issue. electron is using a Proxy constructor for its remote functions:

https://github.com/electron/electron/blob/v1.6.3/lib/renderer/api/remote.js#L170-L190

Proxies cannot be serialized without causing a TypeError:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString

new Proxy(function x () {}, {}).toString()
// VM594:1 Uncaught TypeError: Function.prototype.toString is not generic
//    at Proxy.toString (<anonymous>)
//    at <anonymous>:1:33

Unfortunately, proxies can't be detected either (due to them being proxies -- intentionally transparent). However, we can detect them having serialization issues and provide a fallback.

case 'function':
  try {
    return obj.toString().replace(/\{[\s\S]*\}/, '{ ... }')
  } catch (err) {
    if (err instanceof TypeError) {
      return 'Proxy(function ' + (obj.name || '') + '(...) { ... })';
    } else {
      throw err;
    }
  }

which yields:

Object{clipboard: Object{availableFormats: Proxy(function remoteMemberFunction(...) { ... }), has: Proxy(function remoteMemberFunction(...) { ... }), 

Our plan of action is 2 part:

  • Add a try/catch to Karma so it falls back when encountering proxies
  • Add toString logic to Electron's Proxy wrapper
new Proxy(function x () {}, {get: function () { return function () { return x.toString() }; }}).toString()
// "function x() {}"

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

As a workaround for you, you should be able to use a fork of Karma with the patched serializer (which it seems you're already doing). This can be formalized by a git+ssh URL but whatever works for you 👍

https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Okay, 1 PR down -- Karma karma-runner/karma#2595. 1 PR to go

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Finally got the repo locally bootstrapped. Took a lot longer than I expected because I missed the quick bootstrap notes again:

https://github.com/electron/electron/blob/v1.6.3/docs/development/build-system-overview.md#minimal-bootstrapping

from karma-electron.

GProst avatar GProst commented on July 2, 2024

Great! Thanks for being quick to react, I will look forward for your PR's to be merged and released.

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.