Skip to content

Commit d298d3a

Browse files
committed
Add '--suite' option to 'ng e2e' command
1 parent 1352545 commit d298d3a

File tree

8 files changed

+131
-9
lines changed

8 files changed

+131
-9
lines changed

packages/angular-cli/commands/e2e.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
const Command = require('../ember-cli/lib/models/command');
2-
import {E2eTask} from '../tasks/e2e';
3-
import {CliConfig} from '../models/config';
2+
import { E2eTask } from '../tasks/e2e';
3+
import { CliConfig } from '../models/config';
4+
5+
export interface E2eOptions {
6+
suite?: string;
7+
}
48

59
const E2eCommand = Command.extend({
610
name: 'e2e',
711
description: 'Run e2e tests in existing project',
812
works: 'insideProject',
9-
run: function () {
13+
14+
availableOptions: [
15+
{ name: 'suite', type: String, default: null },
16+
],
17+
18+
run: function (commandOptions: E2eOptions) {
1019
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();
1120

1221
const e2eTask = new E2eTask({
@@ -15,7 +24,7 @@ const E2eCommand = Command.extend({
1524
project: this.project
1625
});
1726

18-
return e2eTask.run();
27+
return e2eTask.run(commandOptions);
1928
}
2029
});
2130

packages/angular-cli/tasks/e2e.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
const Task = require('../ember-cli/lib/models/task');
22
import * as chalk from 'chalk';
3-
import {exec} from 'child_process';
4-
3+
import { exec } from 'child_process';
4+
import { E2eOptions } from '../commands/e2e';
55

66
export const E2eTask = Task.extend({
7-
run: function () {
7+
run: function (options: E2eOptions) {
8+
const commandArgs: string[] = [];
89
const ui = this.ui;
910
let exitCode = 0;
1011

12+
if (options.suite) {
13+
commandArgs.push(`--suite=${options.suite}`);
14+
}
15+
1116
return new Promise((resolve) => {
12-
exec(`npm run e2e -- ${this.project.ngConfig.config.e2e.protractor.config}`,
17+
const protractorConfig = this.project.ngConfig.config.e2e.protractor.config;
18+
exec(`npm run e2e -- ${protractorConfig} ${commandArgs.join(' ')}`,
1319
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
1420
ui.writeLine(stdout);
1521
if (err) {

tests/helpers/mock-project.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
var Project = require('angular-cli/ember-cli/lib/models/project');
4+
var MockUI = require('./mock-ui');
5+
6+
function MockProject() {
7+
var root = process.cwd();
8+
var pkg = {};
9+
var ui = new MockUI();
10+
Project.apply(this, [root, pkg, ui]);
11+
}
12+
13+
MockProject.prototype.require = function(file) {
14+
if (file === './server') {
15+
return function() {
16+
return {
17+
listen: function() {
18+
arguments[arguments.length - 1]();
19+
}
20+
};
21+
};
22+
}
23+
};
24+
25+
MockProject.prototype.config = function() {
26+
return this._config || {
27+
baseURL: '/',
28+
locationType: 'auto'
29+
};
30+
};
31+
32+
MockProject.prototype.has = function(key) {
33+
return (/server/.test(key));
34+
};
35+
36+
MockProject.prototype.name = function() {
37+
return 'mock-project';
38+
};
39+
40+
MockProject.prototype.initializeAddons = Project.prototype.initializeAddons;
41+
MockProject.prototype.hasDependencies = function() {
42+
return true;
43+
};
44+
MockProject.prototype.discoverAddons = Project.prototype.discoverAddons;
45+
MockProject.prototype.addIfAddon = Project.prototype.addIfAddon;
46+
MockProject.prototype.supportedInternalAddonPaths = Project.prototype.supportedInternalAddonPaths;
47+
MockProject.prototype.setupBowerDirectory = Project.prototype.setupBowerDirectory;
48+
MockProject.prototype.setupNodeModulesPath = Project.prototype.setupNodeModulesPath;
49+
MockProject.prototype.isEmberCLIProject = Project.prototype.isEmberCLIProject;
50+
MockProject.prototype.isEmberCLIAddon = Project.prototype.isEmberCLIAddon;
51+
MockProject.prototype.findAddonByName = Project.prototype.findAddonByName;
52+
MockProject.prototype.dependencies = function() {
53+
return [];
54+
};
55+
MockProject.prototype.isEmberCLIAddon = function() {
56+
return false;
57+
};
58+
59+
module.exports = MockProject;

tests/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var Mocha = require('mocha');
77
var glob = require('glob');
88
var path = require('path');
99

10-
var root = 'tests/{acceptance,models}';
10+
var root = 'tests/{acceptance,unit}';
1111
var specFiles = glob.sync(root + '/**/*.spec.*');
1212
var mocha = new Mocha({ timeout: 5000, reporter: 'spec' });
1313

tests/unit/commands/e2e.spec.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import E2eCommand from 'angular-cli/commands/e2e';
2+
import { CliConfig } from 'angular-cli/models/config/config';
3+
import { stub } from 'sinon';
4+
import { expect } from 'chai';
5+
import * as proc from 'child_process';
6+
7+
const MockUI = require('../../helpers/mock-ui');
8+
const MockAnalytics = require('../../helpers/mock-analytics');
9+
const MockProject = require('../../helpers/mock-project');
10+
11+
function createProject() {
12+
const project = new MockProject();
13+
project.isEmberCLIProject = () => true;
14+
project.ngConfig = CliConfig.fromJson({
15+
e2e: {
16+
protractor: {
17+
config: 'some-config'
18+
}
19+
}
20+
});
21+
22+
return project;
23+
}
24+
25+
describe('e2e command', () => {
26+
let command: E2eCommand;
27+
28+
beforeEach(() => {
29+
command = new E2eCommand({
30+
settings: {},
31+
project: createProject(),
32+
ui: new MockUI(),
33+
analytics: new MockAnalytics(),
34+
});
35+
});
36+
37+
beforeEach(() => {
38+
stub(proc, 'exec').callsArg(1);
39+
});
40+
41+
it('passes through the suite option', () => {
42+
const commandOption = '--suite=suiteA';
43+
return command.validateAndRun([commandOption]).then(() => {
44+
expect(proc.exec.calledOnce).to.be.true;
45+
expect(proc.exec.firstCall.args[0]).to.have.string(` ${commandOption}`);
46+
});
47+
});
48+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)