winston#error TypeScript Examples
The following examples show how to use
winston#error.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: testerSession.ts From Assistive-Webdriver with MIT License | 5 votes |
async waitAndCheckEvent(
testName: string,
type: string,
props: any,
action: () => Promise<void>,
filterEvents: (event: any) => boolean = () => true
) {
await this.assertQueueEmpty(filterEvents);
debug(`Testing ${type} event for ${testName}`);
let actionResult;
let event: any;
props = { ...props, type };
const propsKeys = Object.keys(props);
try {
await this.measureTime(type, async () => {
actionResult = action();
let maxEvents = 5;
let foundCorrectEvent = false;
while (!foundCorrectEvent) {
event = await this.eventsQueue.waitForValue();
if (!filterEvents(event)) {
continue;
}
maxEvents--;
const invalidKeys = [];
for (const key of propsKeys) {
if (event[key] !== props[key]) {
invalidKeys.push(key);
}
}
foundCorrectEvent = invalidKeys.length === 0;
if (!foundCorrectEvent) {
this.reportError(
`Unexpected value for ${invalidKeys.join(
", "
)} on event: expected ${JSON.stringify(
props
)} but got ${JSON.stringify(event)}`
);
if (maxEvents <= 0) {
throw new Error("Too many incorrect events!");
}
}
}
});
await actionResult;
} catch (error) {
this.reportError(
`Error while testing ${type} event for ${testName}: ${error}`
);
}
return event;
}
Example #2
Source File: testerSession.ts From Assistive-Webdriver with MIT License | 5 votes |
reportError(message: string) {
this.errorsNumber++;
error(message);
}
Example #3
Source File: testerSession.ts From Assistive-Webdriver with MIT License | 5 votes |
async waitAndCheckEvent(
testName: string,
type: string,
props: any,
action: () => Promise<void>,
filterEvents: (event: any) => boolean = () => true
) {
await this.assertQueueEmpty(filterEvents);
debug(`Testing ${type} event for ${testName}`);
let actionResult;
let event: any;
props = { ...props, type };
const propsKeys = Object.keys(props);
try {
await this.measureTime(type, async () => {
actionResult = action();
let maxEvents = 5;
let foundCorrectEvent = false;
while (!foundCorrectEvent) {
event = await this.eventsQueue.waitForValue();
if (!filterEvents(event)) {
continue;
}
maxEvents--;
const invalidKeys = [];
for (const key of propsKeys) {
if (event[key] !== props[key]) {
invalidKeys.push(key);
}
}
foundCorrectEvent = invalidKeys.length === 0;
if (!foundCorrectEvent) {
this.reportError(
`Unexpected value for ${invalidKeys.join(
", "
)} on event: expected ${JSON.stringify(
props
)} but got ${JSON.stringify(event)}`
);
if (maxEvents <= 0) {
throw new Error("Too many incorrect events!");
}
}
}
});
await actionResult;
} catch (error) {
this.reportError(
`Error while testing ${type} event for ${testName}: ${error}`
);
}
return event;
}
Example #4
Source File: testerSession.ts From Assistive-Webdriver with MIT License | 5 votes |
reportError(message: string) {
this.errorsNumber++;
error(message);
}
Example #5
Source File: cli.ts From Assistive-Webdriver with MIT License | 4 votes |
(async function () {
const argv = await yargs.options({
browser: {
array: true,
type: "string",
alias: "b",
default: ["chromium"]
},
"log-level": {
type: "string",
alias: "l",
default: "info"
},
"public-host": {
type: "string",
alias: "h",
default: `${hostname()}.`
},
"listen-host": {
type: "string",
default: "0.0.0.0"
},
"public-port": {
type: "number",
alias: "p",
default: 0
},
"listen-port": {
type: "number",
default: 0
},
"vm-settings": {
type: "string",
alias: "m",
demandOption: true
},
"server-port": {
type: "number",
default: 7779
},
"skip-keys": {
type: "array",
alias: "k"
},
"screen-reader": {
type: "boolean",
default: true
}
}).argv;
configure({
level: argv["log-level"] as any,
format: format.combine(format.colorize(), format.simple()),
transports: [new transports.Console()]
});
const vmSettings = JSON.parse(argv["vm-settings"]);
info(`Starting the VM...`);
const driver = await createVM({
log: (entry: any) => log(entry),
vmSettings,
playwrightPort: argv["server-port"]
});
const availableBrowsers: {
[name: string]:
| BrowserType<ChromiumBrowser>
| BrowserType<FirefoxBrowser>
| BrowserType<WebKitBrowser>;
} = {
chromium: driver.chromium,
firefox: driver.firefox,
webkit: driver.webkit
};
const screenReader = argv["screen-reader"];
const testerSession = new TesterSession(driver, screenReader);
let vmDestroyed = false;
process.on("SIGINT", async () => {
if (!vmDestroyed) {
warn("Stopping the VM...");
vmDestroyed = true;
await driver.vm.destroy();
error("Tests were interrupted.");
process.exit(2);
}
});
sigintWin32();
try {
const eventsServerAddress = await new Promise<AddressInfo>(
(resolve, reject) =>
testerSession.eventsServer
.listen(
argv["listen-port"] || argv["public-port"],
argv["listen-host"] || argv["public-host"],
() => {
resolve(testerSession.eventsServer.address() as AddressInfo);
}
)
.once("error", reject)
);
const eventsServerListenAddress = `http://${eventsServerAddress.address}:${eventsServerAddress.port}`;
const publicPort = argv["public-port"] || eventsServerAddress.port;
const publicHost = argv["public-host"] || eventsServerAddress.address;
const eventsServerPublicAddress = `http://${publicHost}:${publicPort}`;
info(
`Test page server started at ${eventsServerListenAddress}, VM will connect to ${eventsServerPublicAddress}`
);
if (screenReader) {
info("Screen reader testing is ENABLED.");
driver.screenReader.on("message", message =>
info(`Screen reader said: ${message}`)
);
} else {
info("Screen reader testing is DISABLED.");
}
for (const browserName of argv.browser) {
const browser = availableBrowsers[browserName];
if (!browser) {
testerSession.reportError(`Unknown browser: ${browserName}`);
continue;
}
info(`Testing on browser ${browserName}`);
const browserInstance = await browser.launch({ headless: false });
try {
const page = await browserInstance.newPage({
viewport: null
});
testerSession.page = page;
const mouse = await driver.calibrateMouse(page);
testerSession.mouse = mouse;
info(`Loading test page from ${eventsServerPublicAddress}`);
const response = await page.goto(eventsServerPublicAddress);
if (!response?.ok) {
testerSession.reportError(
`Could not successfully load page ${eventsServerPublicAddress}`
);
continue;
}
info(`Test page was successfully loaded`);
const testInput = await page.$("#testInput");
await mouse.click(0, 0, { origin: testInput });
await page.waitForFunction(hasFocus, testInput);
if (screenReader) {
await driver.screenReader.clearMessages();
}
await driver.keyboard.press(Key.Tab);
if (screenReader) {
try {
await driver.screenReader.waitForMessage("mysupertestlabeltocheck");
} catch (e) {
testerSession.reportError(`Screen reader test failed: ${e}`);
}
}
const testDiv = await page.$("#testDiv");
await page.waitForFunction(hasFocus, testDiv);
await testerSession.eventsQueue.getAllWaitingValues();
await testAllKeys(testerSession, argv["skip-keys"] as any);
await testMouseButtons(testerSession);
} catch (error: any) {
testerSession.reportError(`${error.stack || error.message || error}`);
continue;
} finally {
try {
info(`Closing browser ${browserName}...`);
await browserInstance.close();
} catch (e) {
console.log(`Error in browserInstance.close()`);
}
info(`Tests finished for browser ${browserName}`);
}
}
if (testerSession.errorsNumber === 0) {
info("All tests were successful!");
} else {
throw "Some tests failed!";
}
} finally {
await collectCoverage(driver.url);
testerSession.reportMeasures();
vmDestroyed = true;
await driver.vm.destroy();
testerSession.eventsServer.close();
}
})().catch(e => {
error(`${e.stack || e.message || e}`);
process.exit(1);
});
Example #6
Source File: bin.ts From Assistive-Webdriver with MIT License | 4 votes |
(async function () {
const argv = await yargs.options({
server: {
type: "string",
alias: "s",
default: "http://localhost:3000"
},
browser: {
type: "string",
alias: "b",
default: Browser.CHROME
},
capabilities: {
type: "string",
default: "{}"
},
"log-level": {
type: "string",
alias: "l",
default: "info"
},
"public-host": {
type: "string",
alias: "h",
default: `${hostname()}.`
},
"listen-host": {
type: "string",
default: "0.0.0.0"
},
"public-port": {
type: "number",
alias: "p",
default: 0
},
"listen-port": {
type: "number",
default: 0
},
"vm-config": {
type: "string",
alias: "m"
},
"skip-keys": {
type: "array",
alias: "k"
}
}).argv;
configure({
level: argv["log-level"] as any,
format: format.combine(format.colorize(), format.simple()),
transports: [new transports.Console()]
});
const capabilities = JSON.parse(argv.capabilities);
if (argv["vm-config"]) {
capabilities["awd:vm-config"] = argv["vm-config"];
}
info(`Connecting to webdriver server at ${argv.server}`, {
capabilities,
browser: argv.browser
});
const driver = await new Builder()
.withCapabilities(capabilities)
.forBrowser(argv.browser)
.usingServer(argv.server)
.build();
process.on("SIGINT", async () => {
warn("Closing the session...");
await driver.quit();
error("Tests were interrupted.");
process.exit(2);
});
sigintWin32();
const testerSession = new TesterSession(driver);
try {
const eventsServerAddress = await new Promise<AddressInfo>(
(resolve, reject) =>
testerSession.eventsServer
.listen(
argv["listen-port"] || argv["public-port"],
argv["listen-host"] || argv["public-host"],
() => {
resolve(testerSession.eventsServer.address() as AddressInfo);
}
)
.once("error", reject)
);
const eventsServerListenAddress = `http://${eventsServerAddress.address}:${eventsServerAddress.port}`;
const publicPort = argv["public-port"] || eventsServerAddress.port;
const publicHost = argv["public-host"] || eventsServerAddress.address;
const eventsServerPublicAddress = `http://${publicHost}:${publicPort}`;
info(
`Test page server started at ${eventsServerListenAddress}, VM will connect to ${eventsServerPublicAddress}`
);
try {
await refreshScreenReaderText(testerSession.driver);
info("Screen reader testing is ENABLED.");
addScreenReaderTextListener(testerSession.driver, message =>
info(`Screen reader said: ${message}`)
);
testerSession.screenReader = true;
} catch (error) {
info("Screen reader testing is DISABLED.");
}
info(`Loading test page from ${eventsServerPublicAddress}`);
await driver.get(eventsServerPublicAddress);
const body = await driver.findElement(By.css("body"));
await driver.wait(until.elementTextContains(body, "ready"));
info(`Test page was successfully loaded`);
const testInput = await driver.findElement(By.css("#testInput"));
await driver.actions().click(testInput).perform();
await driver.wait(untilElementHasFocus(testInput), 10000);
if (testerSession.screenReader) {
await clearCachedScreenReaderText(testerSession.driver);
}
await driver.actions().keyDown(Key.TAB).keyUp(Key.TAB).perform();
if (testerSession.screenReader) {
try {
await testerSession.driver.wait(
forScreenReaderToSay("mysupertestlabeltocheck"),
5000
);
} catch (e) {
testerSession.reportError(`Screen reader test failed: ${e}`);
}
}
const testDiv = await driver.findElement(By.css("#testDiv"));
await driver.wait(untilElementHasFocus(testDiv), 10000);
await testerSession.eventsQueue.getAllWaitingValues();
await testAllKeys(testerSession, argv["skip-keys"] as any);
await testMouseButtons(testerSession);
if (testerSession.errorsNumber === 0) {
info("All tests were successful!");
} else {
throw new Error("Some tests failed!");
}
} finally {
testerSession.reportMeasures();
await driver.quit();
testerSession.eventsServer.close();
}
})().catch(e => {
error(`${e}`);
process.exit(1);
});