add test via multiple locations
This commit is contained in:
parent
888b35ea73
commit
249cbb93e6
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
|
@ -63,7 +63,17 @@
|
|||
"env": {
|
||||
"DIST": "1"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Test",
|
||||
"program": "${workspaceFolder}/tests/index.js",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"outputCapture": "std"
|
||||
},
|
||||
],
|
||||
"compounds": [
|
||||
{
|
||||
|
|
12
index.js
12
index.js
|
@ -31,17 +31,17 @@ const index = (req, res) => {
|
|||
};
|
||||
|
||||
// debugging
|
||||
if (process.env?.DIST !== '1') {
|
||||
// debugging
|
||||
app.get('/index.html', index);
|
||||
app.get('/', index);
|
||||
app.get('*', express.static(path.join(__dirname, './server')));
|
||||
} else {
|
||||
if (process.env?.DIST === '1') {
|
||||
// distribution
|
||||
app.use('/images', express.static(path.join(__dirname, './server/images')));
|
||||
app.use('/fonts', express.static(path.join(__dirname, './server/fonts')));
|
||||
app.use('/scripts', express.static(path.join(__dirname, './server/scripts')));
|
||||
app.use('/', express.static(path.join(__dirname, './dist')));
|
||||
} else {
|
||||
// debugging
|
||||
app.get('/index.html', index);
|
||||
app.get('/', index);
|
||||
app.get('*', express.static(path.join(__dirname, './server')));
|
||||
}
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
|
|
|
@ -123,10 +123,12 @@ const getWeatherRegionalIconFromIconLink = (link, _isNightTime) => {
|
|||
case 'tropical_storm':
|
||||
return addPath('Thunderstorm.gif');
|
||||
|
||||
case 'wind':
|
||||
case 'wind_few':
|
||||
case 'wind_sct':
|
||||
case 'wind_bkn':
|
||||
case 'wind_ovc':
|
||||
case 'wind-n':
|
||||
case 'wind_few-n':
|
||||
case 'wind_bkn-n':
|
||||
case 'wind_ovc-n':
|
||||
|
@ -210,6 +212,9 @@ const getWeatherIconFromIconLink = (link, _isNightTime) => {
|
|||
return addPath('CC_Fog.gif');
|
||||
|
||||
case 'rain_sleet':
|
||||
case 'rain_sleet-n':
|
||||
case 'sleet':
|
||||
case 'sleet-n':
|
||||
return addPath('Sleet.gif');
|
||||
|
||||
case 'rain_showers':
|
||||
|
@ -245,6 +250,8 @@ const getWeatherIconFromIconLink = (link, _isNightTime) => {
|
|||
case 'snow_fzra-n':
|
||||
case 'fzra':
|
||||
case 'fzra-n':
|
||||
case 'rain_fzra':
|
||||
case 'rain_fzra-n':
|
||||
return addPath('CC_FreezingRain.gif');
|
||||
|
||||
case 'snow_sleet':
|
||||
|
@ -268,9 +275,10 @@ const getWeatherIconFromIconLink = (link, _isNightTime) => {
|
|||
case 'wind_sct':
|
||||
case 'wind_bkn':
|
||||
case 'wind_ovc':
|
||||
return addPath('CC_Windy.gif');
|
||||
|
||||
case 'wind_skc':
|
||||
case 'wind_few-n':
|
||||
case 'wind_bkn-n':
|
||||
case 'wind_ovc-n':
|
||||
case 'wind_skc-n':
|
||||
case 'wind_sct-n':
|
||||
return addPath('CC_Windy.gif');
|
||||
|
|
1
tests/README.md
Normal file
1
tests/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Currently, tests take a different approach from typical unit testing. The test methodology loads several forecasts for different locations and logs them all to one logger so errors can be found such as missing icons, locations that do not have all of the necessary data or other changes that may occur between geographical locations.
|
42
tests/index.js
Normal file
42
tests/index.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
const puppeteer = require('puppeteer');
|
||||
const { setTimeout } = require('node:timers/promises');
|
||||
const { readFile } = require('fs/promises');
|
||||
const messageFormatter = require('./messageformatter');
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch({
|
||||
// headless: false,
|
||||
slowMo: 10,
|
||||
timeout: 10_000,
|
||||
dumpio: true,
|
||||
});
|
||||
|
||||
// get the list of locations
|
||||
const LOCATIONS = JSON.parse(await readFile('./tests/locations.json'));
|
||||
|
||||
// get the page
|
||||
const page = (await browser.pages())[0];
|
||||
await page.goto('http://localhost:8080');
|
||||
|
||||
page.on('console', messageFormatter);
|
||||
|
||||
// run all the locations
|
||||
for (let i = 0; i < LOCATIONS.length; i += 1) {
|
||||
const location = LOCATIONS[i];
|
||||
console.log(location);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await tester(location, page);
|
||||
}
|
||||
|
||||
browser.close();
|
||||
})();
|
||||
|
||||
const tester = async (location, page) => {
|
||||
// Set the address
|
||||
await page.type('#txtAddress', location);
|
||||
await setTimeout(500);
|
||||
// get the page
|
||||
await page.click('#btnGetLatLng');
|
||||
// wait for errors
|
||||
await setTimeout(5000);
|
||||
};
|
52
tests/locations.json
Normal file
52
tests/locations.json
Normal file
|
@ -0,0 +1,52 @@
|
|||
[
|
||||
"New York, New York",
|
||||
"Los Angeles, California",
|
||||
"Chicago, Illinois",
|
||||
"Houston, Texas",
|
||||
"Phoenix, Arizona",
|
||||
"Philadelphia, Pennsylvania",
|
||||
"San Antonio, Texas",
|
||||
"San Diego, California",
|
||||
"Dallas, Texas",
|
||||
"San Jose, California",
|
||||
"Austin, Texas",
|
||||
"Jacksonville, Florida",
|
||||
"Fort Worth, Texas",
|
||||
"Columbus, Ohio",
|
||||
"Charlotte, North Carolina",
|
||||
"Indianapolis, Indiana",
|
||||
"San Francisco, California",
|
||||
"Seattle, Washington",
|
||||
"Denver, Colorado",
|
||||
"Nashville, Tennessee",
|
||||
"Washington, District of Columbia",
|
||||
"Oklahoma City, Oklahoma",
|
||||
"Boston, Massachusetts",
|
||||
"El Paso, Texas",
|
||||
"Portland, Oregon",
|
||||
"Las Vegas, Nevada",
|
||||
"Memphis, Tennessee",
|
||||
"Detroit, Michigan",
|
||||
"Baltimore, Maryland",
|
||||
"Milwaukee, Wisconsin",
|
||||
"Albuquerque, New Mexico",
|
||||
"Fresno, California",
|
||||
"Tucson, Arizona",
|
||||
"Sacramento, California",
|
||||
"Mesa, Arizona",
|
||||
"Kansas City, Missouri",
|
||||
"Atlanta, Georgia",
|
||||
"Omaha, Nebraska",
|
||||
"Colorado Springs, Colorado",
|
||||
"Raleigh, North Carolina",
|
||||
"Long Beach, California",
|
||||
"Virginia Beach, Virginia",
|
||||
"Oakland, California",
|
||||
"Miami, Florida",
|
||||
"Minneapolis, Minnesota",
|
||||
"Bakersfield, California",
|
||||
"Tulsa, Oklahoma",
|
||||
"Aurora, Colorado",
|
||||
"Arlington, Texas",
|
||||
"Wichita, Kansas"
|
||||
]
|
28
tests/messageformatter.js
Normal file
28
tests/messageformatter.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const chalk = require('chalk');
|
||||
|
||||
const describe = (jsHandle) => jsHandle.executionContext().evaluate(
|
||||
// serialize |obj| however you want
|
||||
(obj) => `OBJ: ${typeof obj}, ${obj}`,
|
||||
jsHandle,
|
||||
);
|
||||
|
||||
const colors = {
|
||||
LOG: chalk.grey,
|
||||
ERR: chalk.red,
|
||||
WAR: chalk.yellow,
|
||||
INF: chalk.cyan,
|
||||
};
|
||||
|
||||
const formatter = async (message) => {
|
||||
const args = await Promise.all(message.args().map((arg) => describe(arg)));
|
||||
// make ability to paint different console[types]
|
||||
const type = message.type().substr(0, 3).toUpperCase();
|
||||
const color = colors[type] || chalk.blue;
|
||||
let text = '';
|
||||
for (let i = 0; i < args.length; i += 1) {
|
||||
text += `[${i}] ${args[i]} `;
|
||||
}
|
||||
console.log(color(`CONSOLE.${type}: ${message.text()}\n${text} `));
|
||||
};
|
||||
|
||||
module.exports = formatter;
|
1436
tests/package-lock.json
generated
Normal file
1436
tests/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
15
tests/package.json
Normal file
15
tests/package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "ws4kp-tests",
|
||||
"version": "1.0.0",
|
||||
"description": "Currently, tests take a different approach from typical unit testing. The test methodology loads several forecasts for different locations and logs them all to one logger so errors can be found such as missing icons, locations that do not have all of the necessary data or other changes that may occur between geographical locations.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chalk": "^4.0.0",
|
||||
"puppeteer": "^19.5.2"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue