Skip to content
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

Tests fail when running tests with codecoverage enabled within electron #259

Closed
weedgrease opened this issue May 16, 2017 · 13 comments
Closed

Comments

@weedgrease
Copy link

I'm using ember-cli-code-coverage and running COVERAGE=true ember electron:test but my tests fail:

not ok 28 Chrome 56.0 - Global error: Uncaught TypeError: Cannot convert undefined or null to object at serve://dist/?hidepassed=&testemId=5156, line 116
    ---
        Log: |
            { type: 'error',
              text: 'Uncaught TypeError: Cannot convert undefined or null to object at serve://dist/?hidepassed=&testemId=5156, line 116\n' }
    ...
not ok 29 Chrome 56.0 - Unit | Route | loading: global failure
    ---
        actual: >
            null
        expected: >
            null
        stack: >
            TypeError: Cannot read property 'setContext' of null
        message: >
            beforeEach failed on global failure: Cannot read property 'setContext' of null
        Log: |
    ...

1..29
# tests 29
# pass  27
# skip  0
# fail  2

Running ember electron:test works fine so I'm not sure what's happening. I know this might not be related to ember-electron, however, was curious when I saw it looking at serve://dist/.

@jkeen
Copy link

jkeen commented Jun 2, 2017

I'm getting this same issue, but not on ember-electron specifically but rather on the tests for an ember addon (found this via google search). I'm stuck on it, and I've found nothing helpful on the internet.

I have figured out that it has nothing to do with that last test, and rather it's something to do with shutting down the test environment. It only happens for me on 2.12 and up. 2.8 LTS runs fine.

Did you figure anything out about it @kevingelion?

@xn
Copy link

xn commented Aug 8, 2017

I'm hitting this as well.

@xn
Copy link

xn commented Aug 8, 2017

ember-cli-code-coverage/ember-cli-code-coverage#75
This is pointing to a problem redefining require

@xn
Copy link

xn commented Aug 11, 2017

Ok, I got code coverage up and running.

First, I had to change require to requireModule because ember-electron overwrites require
https://github.com/xn/ember-cli-code-coverage

Then I created an express app to fill in for the middleware because ember-electron intercepts the middleware route, /write-coverage. I don't think there is a way to get around this. Someone please tell me if I am wrong.

https://gist.github.com/xn/d9d71acb3af59eb90d921ecdf8e738e0

@jkeen @kevingelion

@anulman
Copy link
Collaborator

anulman commented Dec 6, 2017

@jkeen @kevingelion @xn is this still an issue in modern e-electron & e-cli-code-coverage? If so I'd like us to work with their team for a more future-friendly solution.

@xn
Copy link

xn commented Dec 6, 2017

I believe it is, yes.

@anulman
Copy link
Collaborator

anulman commented Dec 6, 2017

Thanks @xn. Can you please open an issue + link to this one in e-cli-code-coverage? I see how we can move your fix upstream, but not knowing that project's guts would like to discuss exactly how with @kategengler first.

(Plus, I think it'd be nicer for her to hear from an actual user directly :)

@xn
Copy link

xn commented Dec 7, 2017

Sure thing, will do.

@jacobq
Copy link
Collaborator

jacobq commented Oct 9, 2018

FWIW, this is still happening. Steps to repro:

  1. ember new junk-app # ember-cli@3.4.3
  2. cd junk-app
  3. ember install ember-electron@2.9.0
  4. ember install ember-cli-code-coverage
  5. ember electron:test --server works
  6. COVERAGE=true ember electron:test --server errors:

    Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys ()
    at sendCoverage (index.html?hidepassed=&testemId=2505493489143422:119)
    at Object. (index.html?hidepassed=&testemId=2505493489143422:156)
    at Object.runAfterTests (testem.js:957)
    at Object.emit (testem.js:836)
    at emit (testem.js:1068)
    at Array. (testem.js:412)
    at runLoggingCallbacks (qunit.js:1291)
    at done (qunit.js:1496)
    at advanceTestQueue (qunit.js:1388)
    Uncaught TypeError: Cannot read property 'length' of undefined
    at processHooks (qunit.js:1837)
    at Test.hooks (qunit.js:1846)
    at runTest (qunit.js:1978)
    at advanceTestQueue (qunit.js:1393)
    at Object.advance (qunit.js:1357)
    at Test.queue (qunit.js:2000)
    at test (qunit.js:2240)
    at Object.onError (qunit.js:2943)
    at window.onerror (qunit.js:4176)

That first error comes from this line since require.entries is undefined and Object.keys(undefined) throws an error.

Upgrading to the beta version via ember install ember-cli-code-coverage@1.0.0-beta.6 changes the problem slightly as the errors now appear to be the following:

Uncaught DOMException: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
at handleCoverageResponse (serve://dist/tests/index.html?hidepassed=&testemId=250593437939356:167:36)
at XMLHttpRequest.request.onreadystatechange (serve://dist/tests/index.html?hidepassed=&testemId=250593437939356:139:11)
handleCoverageResponse @ index.html?hidepassed=&testemId=250593437939356:167
request.onreadystatechange @ index.html?hidepassed=&testemId=250593437939356:139
XMLHttpRequest.send (async)
sendCoverage @ index.html?hidepassed=&testemId=250593437939356:133
(anonymous) @ index.html?hidepassed=&testemId=250593437939356:152
runAfterTests @ testem.js:957
emit @ testem.js:836
emit @ testem.js:1068
(anonymous) @ testem.js:412
runLoggingCallbacks @ qunit.js:1291
done @ qunit.js:1496
advanceTestQueue @ qunit.js:1388
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
advanceTestQueue @ qunit.js:1399
advance @ qunit.js:1357
begin @ qunit.js:3126
(anonymous) @ qunit.js:3086
setTimeout (async)
scheduleBegin @ qunit.js:3085
load @ qunit.js:3057
load (async)
addEvent @ qunit.js:3321
(anonymous) @ qunit.js:4146
(anonymous) @ qunit.js:4186
(anonymous) @ qunit.js:5259
Uncaught TypeError: Cannot read property 'length' of undefined
at processHooks (qunit.js:1837)
at Test.hooks (qunit.js:1846)
at runTest (qunit.js:1978)
at advanceTestQueue (qunit.js:1393)
at Object.advance (qunit.js:1357)
at Test.queue (qunit.js:2000)
at test (qunit.js:2240)
at Object.onError (qunit.js:2943)
at window.onerror (qunit.js:4176)

I'm not sure exactly what's going on here, but it may have something to do with our customer dist:// protocol/scheme. When the first error occurs xhr.responseURL === "serve://dist/write-coverage", 'xhr.responseType === "json"', and xhr.response === null. What seems weird to me is that I can see 1 matching URL in the "Network" tab of the chrome/electron developer tools, and it's a POST request with a response that looks like HTML. (The Content-Type request header shows application/json; charset=utf-8 but there is no Content-Type response header.) It's not clear to me whether line 54 should be changed to var data = xhr.response || (xhr.responseType === 'text' && xhr.responseText) or if the problem is deeper.

@xn
Copy link

xn commented Oct 11, 2018

@jacobq Did you see my work around above?

@jacobq
Copy link
Collaborator

jacobq commented Oct 11, 2018

Yes, @xn, I saw that you were able to get it working, but it looked like you had to modify code. I think the goal of this issue is to avoid needing to fork/modify anything to get it to work, and I wanted to see if that had been done yet.

@xn
Copy link

xn commented Oct 15, 2018

Ah, that would be contingent on getting that /write_coverage endpoint mounted. I didn't see a way to do that when I was working on it.

@bendemboski
Copy link
Member

The ember-electron v3 beta is out which has significantly updated all the tooling, as well as bringing some of the ember electron:* commands more in line with the corresponding core ember-cli commands, so I'm going to close this issue out. Feel free to re-open if it still happens on v3.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants