webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

Allow to run unit tests within the browser

Open christian-bromann opened this issue 4 years ago • 4 comments

Currently the WebdriverIO testrunner is used to run e2e tests in Node.js. However there are tools like Karma that still have a lot popularity. I don't see a reason why WebdriverIO should not allow to also run unit tests in the browser. Rather than initiating a framework as we do right now, we would would use browserify or other bundlers to create a script that will be executed in a browser window.

Without much investigation my suggestion is to enhance the framework adapter to manage this.

  • for Mocha: https://mochajs.org/#running-mocha-in-the-browser
  • for Jasmine adapt what https://github.com/jasmine/jasmine-browser does
  • for Cucumber adapt what https://github.com/s9tpepper/karma-cucumberjs does

This feature idea was influenced by conversations in https://github.com/sinonjs/fake-timers/issues/380

christian-bromann avatar May 27 '21 12:05 christian-bromann

Would this be in addition to allowing tests to be run in Node.js, or a replacement for that?

klamping avatar May 27 '21 13:05 klamping

@klamping an addition. Most people still want to run WebDriver tests.

christian-bromann avatar May 27 '21 14:05 christian-bromann

Jest is easily the/one of the most popular unit test frameworks, if we will allow unit testing and we exclude Jest then I forsee people wanting it added ^^;

erwinheitzman avatar Aug 01 '21 07:08 erwinheitzman

@erwinheitzman It's also the hardest target since it does so much more than just running tests. Tom Sherman has some good insights into how he managed to cram Jest inside of a Karma setup: https://github.com/tom-sherman/blog/blob/master/posts/02-running-jest-tests-in-a-browser.md

The one thing you are not able to do (easily) is ES module mocking in the browser, which Jest otherwise achieves using some Node specific magic. To get that working you would need something like import maps.

fatso83 avatar Sep 03 '21 07:09 fatso83

This landed with WebdriverIO v8 and the new browser runner: https://webdriver.io/docs/component-testing

christian-bromann avatar Mar 30 '23 04:03 christian-bromann