update test to mjs

This commit is contained in:
Matt Walsh
2025-05-14 09:42:31 -05:00
parent cde7ceda6e
commit 99308155d6
8 changed files with 784 additions and 1106 deletions

4
.vscode/launch.json vendored
View File

@@ -69,13 +69,13 @@
},
{
"name": "Test",
"program": "${workspaceFolder}/tests/index.js",
"program": "${workspaceFolder}/tests/index.mjs",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"outputCapture": "std"
"console": "integratedTerminal"
},
],
"compounds": [

View File

@@ -1,4 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
import 'dotenv/config';
import {
src, dest, series, parallel,
} from 'gulp';
@@ -32,8 +33,6 @@ const jsSourcesData = [
const webpackOptions = {
mode: 'production',
// mode: 'development',
// devtool: 'source-map',
output: {
filename: 'ws.min.js',
},
@@ -138,7 +137,7 @@ const uploadSources = [
];
const upload = () => src(uploadSources, { base: './dist', encoding: false })
.pipe(s3({
Bucket: 'weatherstar',
Bucket: process.env.BUCKET,
StorageClass: 'STANDARD',
maps: {
CacheControl: (keyname) => {
@@ -156,13 +155,13 @@ const imageSources = [
const uploadImages = () => src(imageSources, { base: './server', encoding: false })
.pipe(
s3({
Bucket: 'weatherstar',
Bucket: process.env.BUCKET,
StorageClass: 'STANDARD',
}),
);
const invalidate = () => cloudfront.send(new CreateInvalidationCommand({
DistributionId: 'E9171A4KV8KCW',
DistributionId: process.env.DISTRIBUTION_ID,
InvalidationBatch: {
CallerReference: (new Date()).toLocaleString(),
Paths: {

View File

@@ -1,42 +0,0 @@
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);
};

40
tests/index.mjs Normal file
View File

@@ -0,0 +1,40 @@
import puppeteer from 'puppeteer';
import { setTimeout } from 'node:timers/promises';
import { readFile } from 'fs/promises';
import messageFormatter from './messageformatter.mjs';
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);
const tester = async (location, testPage) => {
// Set the address
await testPage.type('#txtAddress', location);
await setTimeout(500);
// get the page
await testPage.click('#btnGetLatLng');
// wait for errors
await setTimeout(5000);
};
// 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();

View File

@@ -1,6 +1,6 @@
const chalk = require('chalk');
import chalk from 'chalk';
const describe = (jsHandle) => jsHandle.executionContext().evaluate(
const describe = (jsHandle) => jsHandle.evaluate(
// serialize |obj| however you want
(obj) => `OBJ: ${typeof obj}, ${obj}`,
jsHandle,
@@ -25,4 +25,4 @@ const formatter = async (message) => {
console.log(color(`CONSOLE.${type}: ${message.text()}\n${text} `));
};
module.exports = formatter;
export default formatter;

1757
tests/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,16 @@
{
"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"
}
"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.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"chalk": "^5.4.1",
"puppeteer": "^24.8.2"
},
"type": "module"
}

View File

@@ -42,7 +42,8 @@
"Tucsan",
"Malek",
"mwood",
"unmuted"
"unmuted",
"dumpio"
],
"cSpell.ignorePaths": [
"**/package-lock.json",