winston#warn TypeScript Examples
The following examples show how to use
winston#warn.
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: collectCoverage.ts From Assistive-Webdriver with MIT License | 6 votes |
export async function collectCoverage(url: string) {
if (process.env.ENABLE_COVERAGE === "1") {
try {
const response = await fetch(`${url}/__coverage__`);
if (response.ok) {
const json = await response.buffer();
const nycFolder = join(process.cwd(), ".nyc_output");
await promises.mkdir(nycFolder, { recursive: true });
const fileName = join(nycFolder, `${createUUID()}.json`);
await promises.writeFile(fileName, json);
info(`Successfully saved code coverage from the VM in ${fileName}.`);
} else {
warn(`Code coverage does not seem to be enabled in the VM.`);
}
} catch (error) {
warn(`Failed to collect/save code coverage from the VM`, error);
}
}
}
Example #2
Source File: testKeys.ts From Assistive-Webdriver with MIT License | 6 votes |
testAllKeys = async (
testerSession: TesterSession,
userSkipKeys: string[] = []
) => {
info(`Testing key events`);
const userSkipKeysMap = new Set(userSkipKeys);
for (const key of keysMap.entries()) {
const keyName = key[1];
const keyChar = key[0];
const skipKey = isShiftedKey(keyChar) || skipKeys.has(keyName);
if (!skipKey) {
if (userSkipKeysMap.has(keyName)) {
warn(`Skipping test for ${keyName}`);
} else {
await testKey(testerSession, keyName, keyChar);
}
}
}
}
Example #3
Source File: testKeys.ts From Assistive-Webdriver with MIT License | 6 votes |
testAllKeys = async (
testerSession: TesterSession,
userSkipKeys: string[] = []
) => {
info(`Testing key events`);
const userSkipKeysMap = new Set(userSkipKeys);
for (const key of keysMap.entries()) {
const keyName = key[1];
const keyChar = key[0];
const skipKey = isShiftedKey(keyChar) || skipKeys.has(keyName);
if (!skipKey) {
if (userSkipKeysMap.has(keyName)) {
warn(`Skipping test for ${keyName}`);
} else {
await testKey(testerSession, keyName, keyChar);
}
}
}
}
Example #4
Source File: testKeys.ts From Assistive-Webdriver with MIT License | 5 votes |
testKey = async (
testerSession: TesterSession,
keyName: string,
keyChar: string
) => {
const extraKeyDowns: any[] = [];
const props = keyProperties(keyName, keyChar);
const filterOutExtraKeydown = (event: any) => {
const isExtraKeyDown = event.type === "keydown" && event.key === props.key;
if (isExtraKeyDown) {
extraKeyDowns.push(event);
}
return !isExtraKeyDown;
};
await checkFocus(testerSession);
await testerSession.waitAndCheckEvent(keyName, "keydown", props, () =>
testerSession.driver.keyboard.down(keyChar)
);
await wait(5);
await checkFocus(testerSession);
const earlyKeyup = (
await testerSession.assertQueueEmpty(filterOutExtraKeydown)
).find(item => item.type === "keyup" && item.key === props.key);
if (earlyKeyup) {
warn(
`keyup for ${keyName} received before key was released (${JSON.stringify(
earlyKeyup
)})`
);
// just send the keyup, but it is useless to wait for the corresponding keyup event in this case
// as there was one already
await testerSession.driver.keyboard.up(keyChar);
return;
}
await testerSession.waitAndCheckEvent(
keyName,
"keyup",
props,
() => testerSession.driver.keyboard.up(keyChar),
filterOutExtraKeydown
);
if (extraKeyDowns.length > 0) {
warn(
`received extra keydown event(s) for ${keyName} before the key was released (${JSON.stringify(
extraKeyDowns
)})`
);
}
}
Example #5
Source File: testKeys.ts From Assistive-Webdriver with MIT License | 5 votes |
testKey = async (
testerSession: TesterSession,
keyName: string,
keyChar: string
) => {
const extraKeyDowns: any[] = [];
const props = keyProperties(keyName, keyChar);
const filterOutExtraKeydown = (event: any) => {
const isExtraKeyDown = event.type === "keydown" && event.key === props.key;
if (isExtraKeyDown) {
extraKeyDowns.push(event);
}
return !isExtraKeyDown;
};
await checkFocus(testerSession);
await testerSession.waitAndCheckEvent(keyName, "keydown", props, () =>
testerSession.driver.actions().keyDown(keyChar).perform()
);
await wait(5);
await checkFocus(testerSession);
const earlyKeyup = (
await testerSession.assertQueueEmpty(filterOutExtraKeydown)
).find(item => item.type === "keyup" && item.key === props.key);
if (earlyKeyup) {
warn(
`keyup for ${keyName} received before key was released (${JSON.stringify(
earlyKeyup
)})`
);
// just send the keyup, but it is useless to wait for the corresponding keyup event in this case
// as there was one already
await testerSession.driver.actions().keyUp(keyChar).perform();
return;
}
await testerSession.waitAndCheckEvent(
keyName,
"keyup",
props,
() => testerSession.driver.actions().keyUp(keyChar).perform(),
filterOutExtraKeydown
);
if (extraKeyDowns.length > 0) {
warn(
`received extra keydown event(s) for ${keyName} before the key was released (${JSON.stringify(
extraKeyDowns
)})`
);
}
}
Example #6
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 #7
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);
});