mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Merge pull request #14689 from rokadias/add-protractor-browser-logs
Adding protractor-browser-logs typescript definition files
This commit is contained in:
Vendored
+32
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user