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
33 changes: 33 additions & 0 deletions client/app/components/about/about.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('About Route', () => {

// Before each test
beforeEach(() => {

// Navigate to about component
browser.get('/about');
});

// About component should be visible
it('should be visible', () => {

// Expect home component to be visible
expect(element(by.tagName('about')).isDisplayed()).toBe(true);
});

// Link to Home navigates to Home Component
it('should navigate to Home if Home link clicked', () => {

// Click navigation to Home route
element(by.css('[ui-sref="home"]'))
.click()
.then(() => {

// Expect Home Component to be visible
expect(element(by.tagName('home')).isDisplayed()).toBe(true);

// Expect About component to be not be present
expect(element(by.tagName('about')).isPresent()).toBe(false);
})
});

});
34 changes: 34 additions & 0 deletions client/app/components/home/home.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe('Home Route', () => {

// Before each test
beforeEach(() => {

// Navigate to home component
browser.get('/');
});


// Home component should be visible
it('should be visible', () => {

// Expect home component to be visible
expect(element(by.tagName('home')).isDisplayed()).toBe(true);
});

// Link to About navigates to About Component
it('should navigate to About if About link clicked', () => {

// Click navigation to About route
element(by.css('[ui-sref="about"]'))
.click()
.then(() => {

// Expect About Component to be visible
expect(element(by.tagName('about')).isDisplayed()).toBe(true);

// Expect Home component to not be present
expect(element(by.tagName('home')).isPresent()).toBe(false);
})
});

});
16 changes: 16 additions & 0 deletions generator/component/temp.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('<%= upCaseName %> Route', () => {

// Before each test
beforeEach(() => {

// Navigate to <%= name %> component
browser.get('/<%= name %>');
});

// <%= upCaseName %> component should be visible
it('should be visible', () => {

// Expect <%= upCaseName %> component to be visible
expect(element(by.tagName('<%= name %>')).isDisplayed()).toBe(true);
});
});
9 changes: 9 additions & 0 deletions generator/component/temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ let <%= name %>Module = angular.module('<%= name %>', [
uiRouter
])

.config(($stateProvider) => {
"ngInject";
$stateProvider
.state('<%= name %>', {
url: '/<%= name %>',
template: '<<%= name %>></<%= name %>>'
});
})

.component('<%= name %>', <%= name %>Component);

export default <%= name %>Module;
33 changes: 31 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import webpackDevMiddelware from 'webpack-dev-middleware';
import webpachHotMiddelware from 'webpack-hot-middleware';
import colorsSupported from 'supports-color';
import historyApiFallback from 'connect-history-api-fallback';
import gulpProtractorAngular from 'gulp-angular-protractor';

let root = 'client';

Expand Down Expand Up @@ -60,7 +61,31 @@ gulp.task('webpack', (cb) => {
});
});

gulp.task('serve', () => {


// 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() {
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();
});
`

});



gulp.task('serve', function() {
const config = require('./webpack.dev.config');
config.entry.app = [
// this modules required to make HRM working
Expand All @@ -72,7 +97,7 @@ gulp.task('serve', () => {

var compiler = webpack(config);

serve({
serve.init({
port: process.env.PORT || 3000,
open: false,
server: {baseDir: root},
Expand All @@ -91,8 +116,12 @@ gulp.task('serve', () => {
});
});



gulp.task('watch', ['serve']);



gulp.task('component', () => {
const cap = (val) => {
return val.charAt(0).toUpperCase() + val.slice(1);
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"css-loader": "^0.19.0",
"fs-walk": "0.0.1",
"gulp": "^3.9.0",
"gulp-angular-protractor": "0.1.1",
"gulp-rename": "^1.2.2",
"gulp-template": "^3.0.0",
"gulp-util": "^3.0.7",
Expand All @@ -33,6 +34,7 @@
"mocha": "^2.3.0",
"ng-annotate-loader": "0.0.10",
"node-libs-browser": "^0.5.0",
"protractor": "3.1.1",
"raw-loader": "^0.5.1",
"run-sequence": "^1.1.0",
"style-loader": "^0.12.2",
Expand All @@ -44,7 +46,8 @@
"yargs": "^3.9.0"
},
"scripts": {
"test": "karma start"
"test": "karma start",
"e2e": "gulp e2e"
},
"keywords": [
"angular",
Expand Down
25 changes: 25 additions & 0 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
exports.config = {
framework: "jasmine",
baseUrl: `http://localhost:${process.env.PORT || 3000}`,
specs: [
'client/**/**.e2e.js',
'client/**/*.e2e.js'
],
jasmineNodeOpts: {
showTiming: true,
showColors: true,
isVerbose: true,
includeStackTrace: true,
defaultTimeoutInterval: 400000
},
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['show-fps-counter=true']
}
},
allScriptsTimeout: 30000,
onPrepare: function () {
require("babel-core/register")({ retainLines: true });
}
}