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 ability to pick protractor framework to allow cucumber as an e2e … #1071

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Because we create a generator you should be specific as possible in your request

Before you submit your pull request consider the following guidelines:

**Test**
**Test**
Please add unit tests for every new feature or bug fix and make sure all tests pass before submitting pull requests. Generator tests are written in [Mocha](http://mochajs.org). [Karma](http://karma-runner.github.io/0.12/index.html) and [Protractor](http://angular.github.io/protractor) are used to run unit tests and e2e tests on generated app.
* Run `./node_modules/mocha/bin/_mocha ./test/*.js` to execute all tests instead of `npm test`. Currently all protractor tests in (2) are excluded from `npm test` due to Travis issue.
* Run `./node_modules/mocha/bin/_mocha ./test/**/*.js` to execute all tests instead of `npm test`. Currently all protractor tests in (2) are excluded from `npm test` due to Travis issue. You will need to have the ruby sass gem installed to run the full suite of tests.
* Add tests into (1) and (2) if there are changes in generated project's structure.
* Feel free to create new test file for new generator features.

Expand All @@ -39,13 +39,13 @@ Please add unit tests for every new feature or bug fix and make sure all tests p
| (4) `test-import-gen.js` | Test generator directory.
| (5) `test-utils.js` | Unit tests for utils.js.

**Style Guide**
**Style Guide**
Please brief yourself on [Idiomatic.js](https://github.com/rwldrn/idiomatic.js) style guide with two space indent.

**Documentation**
**Documentation**
Add documentation for every new feature, directory structure change. Feel free to send corrections or better docs!

**Branch**
**Branch**
Must be one of the following:

* feat: A new feature
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ yo gulp-angular
![Logo](docs/assets/bower.png)
![Logo](docs/assets/webpack.png)
![Logo](docs/assets/karma.png)
![Logo](docs/assets/cucumber.png)
![Logo](docs/assets/istanbul.png)
![Logo](docs/assets/browsersync.png)
![Logo](docs/assets/jasmine.png)
Expand Down
Binary file added docs/assets/cucmber.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/original/cucumber.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ There is none at the generation but you can add `.jade`, `.haml` or `.hbs` (depe
* *CSS pre-processor*: Less, Sass with Ruby and Node, Stylus, none
* *JS preprocessor*: CoffeeScript, TypeScript, ECMAScript 6 (Traceur and Babel), none
* *HTML preprocessor*: Jade, Haml, Handlebars, none
* *Protractor framework*: Jasmine, Cucumber
* **TODO** Script loader: Require, Webpack, none
* **TODO** Test framework: Jasmine, Mocha, Qunit
8 changes: 7 additions & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Its usage is described in the chapters [Development server](#development-server)

### `test`

For testing, a fully working test environment is shipped with some examples. It uses Karma (with `gulp test`) for the unit tests, and Protractor for the end-to-end tests (with `gulp protractor`).
For testing, a fully working test environment is shipped with some examples. It uses Karma (with `gulp test`) for the unit tests, and Protractor for the [end-to-end tests](#end-to-end-tests) (with `gulp protractor`).

More information in the [Test environment configured](#test-environment-configured) chapter.

Expand Down Expand Up @@ -147,6 +147,12 @@ To allow tests to load HTML partials especially for the directives tests, we use

Other than that, we try to use as less Karma plugins as possible because they often duplicate process we already have inside Gulp. For sake of coherence and stability we're searching for a process centralized in Gulp and not duplicated in Karma or other tools like perhaps Webpack.

## End to end tests

The generator provides end to end testing using [Protractor](https://angular.github.io/protractor/#/). By default, Protractor uses the Jasmine test framework for its testing interface. There is an option to change the testing framework to [Cucumber](https://cucumber.io/), a BBD testing framework that uses human readable feature tests to drive assertions.

When the Cucumber options is selected, the [Chai](http://chaijs.com/) library loaded for assertions in your end-to-end tests.

## Optimization process

The central piece of the optimization process is the use of the [gulp-useref](https://github.com/jonkemp/gulp-useref). Its task is to concat files and rewriting the `index.html` file to points on the concat versions of the files. All works with HTML comments block starting with `<!-- build:(...) ->` and ending with `<!-- endbuild -->`.
Expand Down
7 changes: 4 additions & 3 deletions generators/app/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
".editorconfig",

"tsconfig.json",
"protractor.conf.js",

"e2e/.eslintrc",
"e2e/main.spec.js",
"e2e/main.feature",

"gulpfile.js",
"gulp/.eslintrc",
"gulp/e2e-tests.js",

"src/favicon.ico",
"src/assets/images/yeoman.png"
Expand All @@ -25,10 +23,13 @@
"typings.json",

"karma.conf.js",
"protractor.conf.js",

"e2e/main.spec.js",
"e2e/main.po.js",

"gulp/conf.js",
"gulp/e2e-tests.js",
"gulp/build.js",
"gulp/inject.js",
"gulp/markups.js",
Expand Down
21 changes: 21 additions & 0 deletions generators/app/prompts.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,26 @@
"name": "Handlebars (*.hbs)"
}
]
},
{
"type": "list",
"name": "protractorFramework",
"message": "Which Protractor test framework do you want?",
"choices": [
{
"value": {
"key": "jasmine",
"extension": "js"
},
"name": "None, Use the default protractor framework (Jasmine)."
},
{
"value": {
"key": "cucumber",
"extension": "feature"
},
"name": "Cucumber, a BDD testing framework that uses feature tests."
}
]
}
]
10 changes: 8 additions & 2 deletions generators/app/src/mock-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var questions = [
'foundationComponents',
'cssPreprocessor',
'jsPreprocessor',
'htmlPreprocessor'
'htmlPreprocessor',
'protractorFramework'
];

var model = {};
Expand Down Expand Up @@ -81,6 +82,10 @@ model.htmlPreprocessor.choices.forEach(function (choice) {
model.htmlPreprocessor.values[choice.value.key] = choice.value;
});

model.protractorFramework.choices.forEach(function (choice) {
model.protractorFramework.values[choice.value.key] = choice.value;
});

module.exports = {
prompts: model,
defaults: {
Expand All @@ -94,6 +99,7 @@ module.exports = {
foundationComponents: model.foundationComponents.values.noFoundationComponents,
cssPreprocessor: model.cssPreprocessor.values['node-sass'],
jsPreprocessor: model.jsPreprocessor.values.noJsPrepro,
htmlPreprocessor: model.htmlPreprocessor.values.noHtmlPrepro
htmlPreprocessor: model.htmlPreprocessor.values.noHtmlPrepro,
protractorFramework: model.protractorFramework.values.jasmine,
}
};
8 changes: 7 additions & 1 deletion generators/app/src/preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = function (GulpAngularGenerator) {
'js',
this.props.cssPreprocessor.extension,
this.props.jsPreprocessor.extension,
this.props.htmlPreprocessor.extension
this.props.htmlPreprocessor.extension,
this.props.protractorFramework.extension
];
if (this.imageMin) {
this.processedFileExtension = this.processedFileExtension.concat(['jpg', 'png', 'gif', 'svg']);
Expand Down Expand Up @@ -75,6 +76,11 @@ module.exports = function (GulpAngularGenerator) {
if (this.props.jsPreprocessor.key !== 'noJsPrepro') {
rejectWithRegexp.call(this, /^(?!^e2e\/).*spec\.js/);
}

if (this.props.protractorFramework.key !== 'cucumber') {
rejectWithRegexp.call(this, /main\.feature/);
}

};

/**
Expand Down
3 changes: 2 additions & 1 deletion generators/app/src/techs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = function (GulpAngularGenerator) {
this.props.foundationComponents.key,
this.props.cssPreprocessor.key,
this.props.jsPreprocessor.key,
this.props.htmlPreprocessor.key
this.props.htmlPreprocessor.key,
this.props.protractorFramework.key
Copy link
Author

Choose a reason for hiding this comment

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

By adding a new item to the prompt, this causes an error (since this.props.protractorFramework is undefined) when the user loads an existing .yo.rc.

How have you historically managed changes like this?

])
.filter(_.isString)
.filter(function (tech) {
Expand Down
6 changes: 6 additions & 0 deletions generators/app/techs.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,11 @@
"url": "http://handlebarsjs.com/",
"description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.",
"logo": "handlebars.png"
},
"cucumber": {
"title": "Cucumber",
"url": "https://cucumber.io/",
"description": "Cucumber, the popular Behaviour-Driven Development tool, brought to your JavaScript stack.",
"logo": "cucumber.png"
}
}
6 changes: 6 additions & 0 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"wiredep": "~2.2.2",
"karma": "~0.13.10",
"karma-jasmine": "~0.3.6",
<% if (props.protractorFramework.key === 'cucumber') { -%>
"cucumber": "~0.10.2",
"protractor-cucumber-framework": "~0.5.0",
"chai": "~3.5.0",
"chai-as-promised": "~5.3.0",
<% } -%>
<% if(props.jsPreprocessor.key === 'traceur') { -%>
"karma-chrome-launcher": "~0.2.1",
<% } else { -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ exports.config = {

// Spec patterns are relative to the current working directory when
// protractor is called.
specs: [paths.e2e + '/**/*.js'],
specs: [paths.e2e + '/**/*.<%- props.protractorFramework.extension %>'],

<% if (props.protractorFramework.key === 'cucumber') { -%>
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),

// relevant cucumber command line options
cucumberOpts: {
require: [
paths.e2e + '/**/*.js'
],
format: "pretty"
}
<% } else { -%>
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
<% } -%>
};
52 changes: 52 additions & 0 deletions generators/app/templates/e2e/_main.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

<% if (props.protractorFramework.key === 'cucumber') { -%>
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var expect = chai.expect;
var page = require('./main.po');

chai.use(chaiAsPromised);

module.exports = function () {
this.Given('a demo app', function (done) {
done();
});

this.When('I load the page', function (done) {
browser.get('/index.html');
done();
});

this.Then(/^I should see the jumbotron with correct data$/, function () {
expect(page.h1El.getText()).to.eventually.equal('\'Allo, \'Allo!');
expect(page.imgEl.getAttribute('src')).to.eventually.have.string('assets/images/yeoman.png');
return expect(page.imgEl.getAttribute('alt')).to.eventually.equal('I\'m Yeoman');
});

this.Then(/^I should see a list of more than (\d+) awesome things$/, function (itemNumber) {
return expect(page.thumbnailEls.count()).to.eventually.be.at.least(itemNumber);
});
};
<% } else { -%>
describe('The main view', function () {
var page;

beforeEach(function () {
browser.get('/index.html');
page = require('./main.po');
});

it('should include jumbotron with correct data', function() {
expect(page.h1El.getText()).toBe('\'Allo, \'Allo!');
expect(page.imgEl.getAttribute('src')).toMatch(/assets\/images\/yeoman.png$/);
expect(page.imgEl.getAttribute('alt')).toBe('I\'m Yeoman');
});

it('should list more than 5 awesome things', function () {
expect(page.thumbnailEls.count()).toBeGreaterThan(5);
});

});
<% } -%>

7 changes: 7 additions & 0 deletions generators/app/templates/e2e/main.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: The project introduction page

Scenario: The main view
Given a demo app
When I load the page
Then I should see the jumbotron with correct data
And I should see a list of more than 5 awesome things
21 changes: 0 additions & 21 deletions generators/app/templates/e2e/main.spec.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function runProtractor (done) {
var params = process.argv;
var args = params.length > 3 ? [params[3], params[4]] : [];

gulp.src(path.join(conf.paths.e2e, '/**/*.js'))
gulp.src(path.join(conf.paths.e2e, '/**/*.<%- props.protractorFramework.extension %>'))
.pipe($.protractor.protractor({
configFile: 'protractor.conf.js',
args: args
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions test/inception/test-inception.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('gulp-angular generator inception tests', function () {
});
});

describe('with [angular 1.3.x, jQuery 2.x.x, Restangular, UI-Router, Foundation, angular-foundation, CSS, Coffee, Jade]', function () {
describe('with [angular 1.3.x, jQuery 2.x.x, Restangular, UI-Router, Foundation, angular-foundation, CSS, Coffee, Jade, cucmber]', function () {
before(function () {
return inception.prepare({}, {
angularVersion: prompts.angularVersion.values['1.3'],
Expand All @@ -46,7 +46,8 @@ describe('gulp-angular generator inception tests', function () {
foundationComponents: prompts.foundationComponents.values['angular-foundation'],
cssPreprocessor: prompts.cssPreprocessor.values.noCssPrepro,
jsPreprocessor: prompts.jsPreprocessor.values.coffee,
htmlPreprocessor: prompts.htmlPreprocessor.values.jade
htmlPreprocessor: prompts.htmlPreprocessor.values.jade,
protractorFramework: prompts.protractorFramework.values.cucumber
}).then(function (generator) {
gulpAngular = generator;
});
Expand Down
Loading