I'm using
- React: application
- npm: package manager
- mocha/chai/sinon: unit test
- protractor: e2e testing
in my application. The entire application is written with ES6, but the e2e tests are plain javascript. I would like to use ES6 styling for my e2e tests files as well, but the issue that I am facing is to preprocess or compile the ES6 files to plain javascript and then run the protractor agains compiled files. Can anyone please point how to use webpack with babel to convert those ES6 files into plain javascript?
here is my protractor.conf.js
:
/*eslint-disable no-var*/
'use strict';
exports.config = {
specs: ['../tests/e2e/**/*.js'],
capabilities: {
browserName: 'chrome'
},
baseUrl: 'http://localhost:3000',
frameworks: ['mocha', 'chai'],
onPrepare: function() {
browser.ignoreSynchronization = true;
}
};
and a simple test:
/*eslint-disable no-var*/
'use strict';
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
var expect = chai.expect;
chai.use(sinonChai);
describe('app login flow', function() {
var loginUrl, homeUrl;
it('sets up initial variables', function() {
browser.get('/teams');
loginUrl = browser.getCurrentUrl();
browser.sleep(6000).then(function() {
homeUrl = browser.getCurrentUrl();
expect('1').to.equal('1');
})
});
});
The problem was solved simply by adding
require('babel/register');
at the very top of theprotractor.conf.js
file. for more info check this issue on githubSo the
protractor.conf.js
now looks like this:and the test files now can be written in ES6.
PS. a good reference for making protractor to work with ReactJs: Testing React apps with Protractor by Joel Auterson
UPDATE