Skip to content

Commit

Permalink
chore: smooth the protractor process; shuffle scripts in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Apr 14, 2016
1 parent 62f8915 commit 168495d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
*.js.map
!**/*e2e-spec.js
_test-output
protractor-results.txt
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ we configured protractor to find them.
Thereafter, run them with `npm run e2e`.

That command first compiles, then simultaneously starts the Http-Server at `localhost:8080`
and launches protractor. The pass/fail test results appear at the bottom of the terminal window.
and launches protractor.

The pass/fail test results appear at the bottom of the terminal window.
A custom reporter (see `protractor.config.js`) generates a `./protractor-results.txt` file
which is easier to read; this file is excluded from source control.

Shut it down manually with Ctrl-C.
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{
"name": "angular2-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"build-and-test": "npm run tsc && npm run test",
"docker-build": "docker build -t ng2-quickstart .",
"docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
"e2e": "tsc && concurrently \"http-server\" \"protractor protractor.config.js\"",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"postinstall": "typings install",
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"webdriver:update": "webdriver-manager update",
"postinstall": "typings install"
"webdriver:update": "webdriver-manager update"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.15",
"a2-in-memory-web-api": "^0.1.15",

"systemjs": "0.19.26",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10"
"zone.js": "0.6.10",

"a2-in-memory-web-api": "^0.1.15"
},
"devDependencies": {
"canonical-path": "0.0.2",
Expand All @@ -41,5 +43,6 @@
"rimraf": "^2.5.2",
"typescript": "^1.8.10",
"typings":"^0.7.12"
}
},
"repository": { }
}
45 changes: 9 additions & 36 deletions protractor.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,7 @@ exports.config = {

// debugging
// console.log('browser.params:' + JSON.stringify(browser.params));

var appDir = browser.params.appDir;
if (appDir) {
if (appDir.match('/ts') != null) {
browser.appIsTs = true;
} else if (appDir.match('/js') != null) {
browser.appIsJs = true;
} else if (appDir.match('/dart') != null) {
browser.appIsDart = true;
} else {
browser.appIsUnknown = true;
}
} else {
browser.appIsUnknown = true;
}
jasmine.getEnv().addReporter(new Reporter( browser.params )) ;
global.describeIf = describeIf;
global.itIf = itIf;
global.sendKeys = sendKeys;

// Allow changing bootstrap mode to NG1 for upgrade tests
global.setProtractorToNg1Mode = function() {
Expand All @@ -82,22 +64,6 @@ exports.config = {
}
};

function describeIf(cond, name, func) {
if (cond) {
describe(name, func);
} else {
xdescribe(name, func);
}
}

function itIf(cond, name, func) {
if (cond) {
it(name, func);
} else {
xit(name, func);
}
}

// Hack - because of bug with send keys
function sendKeys(element, str) {
return str.split('').reduce(function (promise, char) {
Expand All @@ -108,11 +74,13 @@ function sendKeys(element, str) {
// better to create a resolved promise here but ... don't know how with protractor;
}


// Custom reporter
function Reporter(options) {
var _defaultOutputFile = path.resolve(process.cwd(), "../../", 'protractor-results.txt');
var _defaultOutputFile = path.resolve(process.cwd(), './', 'protractor-results.txt');
options.outputFile = options.outputFile || _defaultOutputFile;

initOutputFile(options.outputFile);
options.appDir = options.appDir || './';
var _root = { appDir: options.appDir, suites: [] };
log('AppDir: ' + options.appDir, +1);
var _currentSuite;
Expand Down Expand Up @@ -159,6 +127,11 @@ function Reporter(options) {
fs.appendFileSync(outputFile, output);
};

function initOutputFile(outputFile) {
var header = "Protractor results for: " + (new Date()).toLocaleString() + "\n\n";
fs.writeFileSync(outputFile, header);
}

// for output file output
function formatOutput(output) {
var indent = ' ';
Expand Down

0 comments on commit 168495d

Please sign in to comment.