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

feat(tests): add '--suite' option to 'ng e2e' command #3551

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@types/node": "^6.0.36",
"@types/request": "0.0.30",
"@types/rimraf": "0.0.25-alpha",
"@types/sinon": "^1.16.33",
"@types/semver": "^5.3.30",
"@types/source-map": "^0.5.0",
"@types/webpack": "^1.12.22-alpha",
Expand All @@ -161,7 +162,7 @@
"request": "^2.74.0",
"resolve-bin": "^0.4.0",
"rewire": "^2.5.1",
"sinon": "^1.17.3",
"sinon": "^1.17.6",
"tree-kill": "^1.0.0",
"ts-node": "^1.3.0"
}
Expand Down
17 changes: 13 additions & 4 deletions packages/angular-cli/commands/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
const Command = require('../ember-cli/lib/models/command');
import {E2eTask} from '../tasks/e2e';
import {CliConfig} from '../models/config';
import { E2eTask } from '../tasks/e2e';
import { CliConfig } from '../models/config';

export interface E2eOptions {
suite?: string;
}

const E2eCommand = Command.extend({
name: 'e2e',
description: 'Run e2e tests in existing project',
works: 'insideProject',
run: function () {

availableOptions: [
{ name: 'suite', type: String, default: null },
],

run: function (commandOptions: E2eOptions) {
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();

const e2eTask = new E2eTask({
ui: this.ui,
project: this.project
});

return e2eTask.run();
return e2eTask.run(commandOptions);
}
});

Expand Down
14 changes: 10 additions & 4 deletions packages/angular-cli/tasks/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const Task = require('../ember-cli/lib/models/task');
import * as chalk from 'chalk';
import {exec} from 'child_process';

import { exec } from 'child_process';
import { E2eOptions } from '../commands/e2e';

export const E2eTask = Task.extend({
run: function () {
run: function (options: E2eOptions) {
const commandArgs: string[] = [];
const ui = this.ui;
let exitCode = 0;

if (options.suite) {
commandArgs.push(`--suite="${options.suite}"`);
}

return new Promise((resolve) => {
exec(`npm run e2e -- ${this.project.ngConfig.config.e2e.protractor.config}`,
const protractorConfig = this.project.ngConfig.config.e2e.protractor.config;
exec(`npm run e2e -- ${protractorConfig} ${commandArgs.join(' ')}`,
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => {
ui.writeLine(stdout);
if (err) {
Expand Down
59 changes: 59 additions & 0 deletions tests/helpers/mock-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var Project = require('angular-cli/ember-cli/lib/models/project');
var MockUI = require('./mock-ui');

function MockProject() {
var root = process.cwd();
var pkg = {};
var ui = new MockUI();
Project.apply(this, [root, pkg, ui]);
}

MockProject.prototype.require = function(file) {
if (file === './server') {
return function() {
return {
listen: function() {
arguments[arguments.length - 1]();
}
};
};
}
};

MockProject.prototype.config = function() {
return this._config || {
baseURL: '/',
locationType: 'auto'
};
};

MockProject.prototype.has = function(key) {
return (/server/.test(key));
};

MockProject.prototype.name = function() {
return 'mock-project';
};

MockProject.prototype.initializeAddons = Project.prototype.initializeAddons;
MockProject.prototype.hasDependencies = function() {
return true;
};
MockProject.prototype.discoverAddons = Project.prototype.discoverAddons;
MockProject.prototype.addIfAddon = Project.prototype.addIfAddon;
MockProject.prototype.supportedInternalAddonPaths = Project.prototype.supportedInternalAddonPaths;
MockProject.prototype.setupBowerDirectory = Project.prototype.setupBowerDirectory;
MockProject.prototype.setupNodeModulesPath = Project.prototype.setupNodeModulesPath;
MockProject.prototype.isEmberCLIProject = Project.prototype.isEmberCLIProject;
MockProject.prototype.isEmberCLIAddon = Project.prototype.isEmberCLIAddon;
MockProject.prototype.findAddonByName = Project.prototype.findAddonByName;
MockProject.prototype.dependencies = function() {
return [];
};
MockProject.prototype.isEmberCLIAddon = function() {
return false;
};

module.exports = MockProject;
2 changes: 1 addition & 1 deletion tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Mocha = require('mocha');
var glob = require('glob');
var path = require('path');

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

Expand Down
50 changes: 50 additions & 0 deletions tests/unit/commands/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import E2eCommand from 'angular-cli/commands/e2e';
import { CliConfig } from 'angular-cli/models/config/config';
import { stub, SinonStub } from 'sinon';
import { expect } from 'chai';
import * as proc from 'child_process';

const MockUI = require('../../helpers/mock-ui');
const MockProject = require('../../helpers/mock-project');

function createProject() {
const project = new MockProject();
project.isEmberCLIProject = () => true;
project.ngConfig = CliConfig.fromJson({
e2e: {
protractor: {
config: 'some-config'
}
}
});

return project;
}

describe('e2e command', () => {
let command: any;
let exec: SinonStub;

beforeEach(() => {
command = new E2eCommand({
settings: {},
project: createProject(),
ui: new MockUI(),
});
});

beforeEach(() => {
exec = stub(proc, 'exec').callsArg(1);
});

afterEach(() => {
exec.restore();
});

it('passes through the suite option', () => {
return command.validateAndRun(['--suite', 'suiteA,suite B']).then(() => {
expect(exec.calledOnce).to.be.true;
expect(exec.firstCall.args[0]).to.have.string(' --suite="suiteA,suite B"');
});
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.