Skip to content

Commit 0d32187

Browse files
committed
tests: add basic e2e tests
1 parent ba4f81b commit 0d32187

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@
5353
"devDependencies": {
5454
"broccoli-stew": "^0.3.6",
5555
"chai": "^3.2.0",
56+
"cucumber": "^0.9.2",
5657
"exists-sync": "0.0.3",
5758
"glob": "^5.0.14",
5859
"minimatch": "^2.0.10",
5960
"mocha": "^2.2.5",
6061
"rewire": "^2.3.4",
62+
"shelljs": "^0.5.3",
6163
"through": "^2.3.8",
6264
"walk-sync": "^0.1.3"
6365
}

tests/e2e/basic.feature

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Feature: Basic Workflow
2+
As a user
3+
I want to be able to install the tool, generate a project, build it, test it,
4+
generate a component, generate a service, generate a pipe and test it again
5+
6+
Scenario: Generate new project
7+
Given the name "test-project"
8+
When I create a new project
9+
Then it creates the files:
10+
"""
11+
ember-cli-build.js
12+
.gitignore
13+
karma-test-shim.js
14+
karma.conf.js
15+
package.json
16+
src/app/test-project.html
17+
src/app/test-project.spec.ts
18+
src/app/test-project.ts
19+
src/app.ts
20+
src/favicon.ico
21+
src/index.html
22+
src/tsconfig.json
23+
"""
24+
Then it initializes a git repository
25+
Then it install npm dependencies
26+
27+
Scenario: Build new project
28+
Given the directory "test-project"
29+
When I build the project
30+
Then it creates the files:
31+
"""
32+
"""
33+
34+
Scenario: Run tests for new project
35+
Given the directory "test-project"
36+
When I run the tests
37+
Then it passes with:
38+
"""
39+
..
40+
Chrome
41+
"""
42+
43+
Scenario: Generate a component
44+
Given the directory "test-project"
45+
And the name "test-component"
46+
When I generate a component
47+
Then it creates the files:
48+
"""
49+
"""
50+
51+
Scenario: Run tests for a project with a generated component
52+
Given the directory "test-project"
53+
When I run the tests
54+
Then it passes with:
55+
"""
56+
...
57+
Chrome
58+
"""

tests/e2e/steps/basic.steps.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var chai = require('chai');
2+
var shell = require('shelljs');
3+
4+
var chaiAsPromised = require('chai-as-promised');
5+
chai.use(chaiAsPromised);
6+
7+
var expect = chai.expect;
8+
9+
module.exports = function() {
10+
var _name;
11+
var _newOutput;
12+
13+
this.Given(/^the name "([^"]*)"$/, function(name, cb) {
14+
_name = name;
15+
cb();
16+
});
17+
18+
this.Given(/^the directory "([^"]*)"$/, function(directory, cb) {
19+
cb();
20+
});
21+
22+
this.When(/^I create a new project$/, function(cb) {
23+
_newOutput = shell.exec('ng new ' + _name + ' --skip-npm --skip-git', {silent: true}).output;
24+
cb();
25+
});
26+
27+
this.When(/^I build the project$/, function(cb) {
28+
cb();
29+
});
30+
31+
this.When(/^I run the tests$/, function(cb) {
32+
cb();
33+
});
34+
35+
this.When(/^I generate a component$/, function(cb) {
36+
cb();
37+
});
38+
39+
this.Then(/^it initializes a git repository$/, function(cb) {
40+
cb();
41+
});
42+
43+
this.Then(/^it install npm dependencies$/, function(cb) {
44+
cb();
45+
});
46+
47+
this.Then(/^it creates the files:$/, function(files, cb) {
48+
var patternToCatch = /create\s(.*)/gm;
49+
var patternToReplace = /create\s/gm;
50+
var caught = _newOutput.match(patternToCatch);
51+
var _files = files.split(/\s/);
52+
53+
caught.forEach(function(item, index) {
54+
expect(item.replace(patternToReplace, '')).to.equal(_files[index]);
55+
});
56+
57+
cb();
58+
});
59+
60+
this.Then(/^it passes with:$/, function(string, cb) {
61+
cb();
62+
});
63+
};

0 commit comments

Comments
 (0)