cucumber / cucumber-electron

Run cucumber.js in electron
MIT License
118 stars 22 forks source link

Support electron 5 #30

Closed aslakhellesoy closed 5 years ago

aslakhellesoy commented 5 years ago

Makes things work in electron 5 and node 12. This means we get full async stack traces, finally! 🎉

Things almost worked without any changes, but we had a slightly crazy hack to make the debug module print coloured output in the terminal. This broke because electron 5 evidently doesn't allow overwriting process.type in the way that we were (in order to fool the debug module into using the node implementation and not the browser implementation in an electron renderer process.

This has been reworked so that we take an equally crazy (but maybe not quite as brittle) approach:

  1. require the debug module, allowing it to infer we want the browser implementation, not the node implementation (also don't assume the debug module is installed in any given project)
  2. find it in the require cache and replace it with the explicitly-loaded node implementation.

Also undoes some nasty monkey-patching of tty

aslakhellesoy commented 5 years ago

This looks great @joshski - did you type the above on my laptop? Those are your words, not me :-)

jbpros commented 5 years ago

w00t! I'd like to give it a go on some side project of mine.

aslakhellesoy commented 5 years ago

I am getting a test failure locally on Node 12 (also on master):

$ yarn test
yarn run v1.16.0
$ cucumber-js && node ./bin/cucumber-electron.js && npm run eslint
............................................F.......

Failures:

1) Scenario: Debugging a scenario with node.js and browser step definitions # features/node_and_browser.feature:37
   ✔ Before # features/support/world.js:146
   ✔ Before # features/support/world.js:149
   ✔ Given the file "features/weather_report.feature" contains: # features/step_definitions/steps.js:3
       """
       Feature: Weather Report
         Scenario: Checking the weather in London
           Given I am in London
           When I check the weather
           Then it should be rainy
       """
   ✔ And the file "features/step_definitions/steps.js" contains: # features/step_definitions/steps.js:3
       """
       const { Given, When, Then } = require('cucumber')
       const assert = require('assert')

       Given(/^I am in London$/, function () {
         const element = document.createElement('div')
         element.id = 'weather'
         element.innerHTML = 'Rainy!'
         document.body.appendChild(element)
       })

       When(/^I check the weather$/, function () {
         this.weatherElement = document.getElementById('weather')
       })

       Then(/^it should be rainy$/, function () {
         assert.equal('Rainy!', this.weatherElement.innerHTML)
       })
       """
   ✔ When I run `cucumber-electron --interactive` # features/step_definitions/steps.js:47
   ✖ Then the process should not exit # features/step_definitions/steps.js:71
       Error: kill ESRCH
           at process.kill (internal/process/per_thread.js:188:13)
           at Timeout._onTimeout (/Users/aslakhellesoy/git/cucumber/cucumber-electron/features/support/world.js:87:19)
           at listOnTimeout (internal/timers.js:531:17)
           at processTimers (internal/timers.js:475:7)

7 scenarios (1 failed, 6 passed)
38 steps (1 failed, 37 passed)
0m15.093s

I have added Node 10 and 12 to the travis config (for this branch as well as master). I suggest postponing a release until this is fixed. Not sure if it's reproducible on Travis yet - it's so slow!!

joshski commented 5 years ago

Yarg, thanks

aslakhellesoy commented 5 years ago

I managed to reproduce the failure on Travis on Node 10: https://travis-ci.org/cucumber/cucumber-electron/jobs/542206637 - it passes on Node 12: https://travis-ci.org/cucumber/cucumber-electron/jobs/542206638

That suggests to me this failure has nothing to do with the Node version - it's more likely it's a flaky test (race condition?)

joshski commented 5 years ago

Yeah I'm pretty sure that's right. I don't understand it...

aslakhellesoy commented 5 years ago

Here is master failing: https://travis-ci.org/cucumber/cucumber-electron/builds/542207127 - I'll try to fix it on master.