Merge pull request #14689 from rokadias/add-protractor-browser-logs

Adding protractor-browser-logs typescript definition files
This commit is contained in:
Zhengbo Li
2017-02-19 23:56:45 -08:00
committed by GitHub
5 changed files with 138 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
// Type definitions for protractor-browser-logs 1.0
// Project: https://www.npmjs.com/package/protractor-browser-logs, https://github.com/wix/protractor-browser-logs
// Definitions by: Saqib Rokadia <https://github.com/rokadias>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as webdriver from 'selenium-webdriver';
import Entry = webdriver.logging.Entry;
import { ProtractorBrowser } from 'protractor/built';
interface BrowserLogOptions {
reporters?: Array<(entries: Entry[]) => void>;
}
type matchPredicateFunction = (entry: Entry) => boolean;
type matchPredicate = string | RegExp | matchPredicateFunction;
interface BrowserLogs {
ERROR: matchPredicateFunction;
WARNING: matchPredicateFunction;
DEBUG: matchPredicateFunction;
INFO: matchPredicateFunction;
LOG: matchPredicateFunction;
or(a: matchPredicateFunction, b: matchPredicateFunction): matchPredicateFunction;
and(a: matchPredicateFunction, b: matchPredicateFunction): matchPredicateFunction;
reset(): void;
logs(): Entry[];
verify(): void;
ignore(... matches: matchPredicate[]): matchPredicateFunction[];
expect(... matches: matchPredicate[]): matchPredicateFunction[];
}
export default function browserLogs(browser: ProtractorBrowser, options?: BrowserLogOptions): BrowserLogs;
+6
View File
@@ -0,0 +1,6 @@
{
"dependencies": {
"protractor": "latest",
"@types/selenium-webdriver": "latest"
}
}
@@ -0,0 +1,74 @@
import { browser } from 'protractor/built';
import browserLogs from 'protractor-browser-logs';
import * as webdriver from 'selenium-webdriver';
import Entry = webdriver.logging.Entry;
function colored(entries: Entry[]) {
let colors: any = { INFO: 35 /* magenta */, WARNING: 33 /* yellow */, SEVERE: 31 /* red */};
entries.forEach(function (entry: Entry) {
console.log('\u001b[' + (colors[entry.level.name] || 37) + 'm' + [entry.level.name, entry.message].join(': ') + '\u001b[39m');
});
}
function testCreateFunction() {
let logs = browserLogs(browser);
logs = browserLogs(browser, { reporters: [] });
logs = browserLogs(browser, { reporters: [ colored ] });
}
function testLogLevels() {
let logs = browserLogs(browser);
logs.ignore(logs.ERROR);
logs.expect(logs.WARNING);
logs.ignore(logs.DEBUG);
logs.expect(logs.INFO);
logs.ignore(logs.LOG);
}
function testPredicateFunctions() {
let logs = browserLogs(browser);
logs.ignore(logs.or(logs.ERROR, logs.WARNING));
logs.expect(logs.and(logs.DEBUG, logs.INFO));
}
function testRegExp() {
let logs = browserLogs(browser);
logs.ignore(/foo/i);
logs.expect(new RegExp('/foo/i'));
}
function testString() {
let logs = browserLogs(browser);
logs.ignore('foo');
logs.expect('foo');
}
function testMatchFunction() {
let logs = browserLogs(browser);
let filter = (entry: Entry) => entry.message === "foo";
logs.ignore(filter);
logs.expect(filter);
}
function testReset() {
let logs = browserLogs(browser);
logs.reset();
}
function testLogs() {
let logs = browserLogs(browser);
let entries: Entry[] = logs.logs();
}
function testVerify() {
let logs = browserLogs(browser);
logs.verify();
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"protractor-browser-logs-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}