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

Add e2e tests #116

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Add e2e tests #116

wants to merge 10 commits into from

Conversation

samreaves
Copy link

To run end to end tests:

  1. Start up the webpack dev server with either gulp serve or gulp watch.
  2. Run "npm run e2e" to get automated tests. By just running "protractor" in the root directory, you will see test logs with greater verbosity.

E2E Test Generator

I've added a component e2e test file generator, and updated the component module generator with a default route of the component name. In order for the component to be tested, two tasks must still be accomplished.

  1. New component must be added to the components.js file.
  2. There must be a link to the route somewhere in the app for ui-router to recognize it.

…e, run on any file ending with .e2e.js, run in verbose mode and use babel for es2015 compilation
…ent has a home at which to be tested. Still needs to be imported in components.js and provided a ui-sref link somewhere in order for route to work.
@@ -44,6 +45,10 @@
"yargs": "^3.9.0"
},
"scripts": {
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run it as postinstall script?

@samreaves
Copy link
Author

How about now, guys?

Removed extraneous code, added environment variables, using relative paths, and the developer experience is so much better.

gulp e2e

  • bundles our source with webpack
  • serves a webserver
  • updates selenium
  • runs selenium
  • runs protractor (with verbosity this time!)
  • exits process after protractor is finished

npm e2e

  • Runs gulp e2e



gulp.task('e2e', ['protractor'], function() {
process.exit();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe not a good idea, but we could store server instance in gulpfile scope and then just stop it. But i think this is better than process.exit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous commit I have serve.exit() from the browser-sync API instead, and it doesn't stop the server. Exiting the process seemed to be the only option.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't stop gulp task maybe?

let stopServer;

// ...
gulp.task('server', function (callback) {
    const server = browsersync({...});

    stopServer = () => {
       server.exit();
       callback();
    };

});

// ...

stopServer();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. However with that implementation, protractor never starts. Probably because serve task is expecting to only proceed after the callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, you are right... so we need to run callback after server is ready.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what I'm missing here. Everything finishes except for the process.

`
let stopServer;
// Setting up the test task
gulp.task('protractor', ['serve'], function(callback) {
gulp
.src(['example_spec.js'])
.pipe(gulpProtractorAngular({
'configFile': 'protractor.conf.js',
'debug': false,
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end', callback);
});

gulp.task('e2e', ['protractor'], function(callback) {
//process.exit();
stopServer();
callback();
});

gulp.task('serve', function(callback) {
const config = require('./webpack.dev.config');
config.entry.app = [
// this modules required to make HRM working
// it responsible for all this webpack magic
'webpack-hot-middleware/client?reload=true',
// application entry point
paths.entry
];

var compiler = webpack(config);

const server = serve.init({
port: process.env.PORT || 3000,
open: false,
server: {baseDir: root},
middleware: [
historyApiFallback(),
webpackDevMiddelware(compiler, {
stats: {
colors: colorsSupported,
chunks: false,
modules: false
},
publicPath: config.output.publicPath
}),
webpachHotMiddelware(compiler)
]
});

stopServer = function() {
server.exit();
}

callback();
});
`

@pkishino
Copy link

update on this ? Ive used most of this stuff and I can get the protractor to run properly, but as you say, when used with gulp it doesnt want to exit..

@fesor
Copy link
Collaborator

fesor commented Nov 26, 2016

I currently working on getting rid of gulp completely. This will simplify stuff.

@FarhadG
Copy link

FarhadG commented Jul 17, 2017

Do we have a working version of the latest here? Curious...

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

Successfully merging this pull request may close these issues.

5 participants