Skip to content

Commit a57a42f

Browse files
committed
Update index.js support new return from commandHandlers.js
1 parent 95587ac commit a57a42f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './sr
55
import { urlList, options, execOptions } from './src/urlList.js'
66
import { makeCommandFromURL } from './src/lib/commandHandlers.js'
77
import { getCategoriesFromCategoriesFlags, getCurrentCategories } from './src/lib/categoriesHandlers.js'
8+
import { getCategoriesFlags } from "./src/lib/categoriesHandlers.js"
89

910
Object.prototype.isEmpty = (obj) => {
1011
for (const prop in obj)
@@ -22,8 +23,8 @@ const execResult = (err = null, out, outerr = null) => {
2223

2324
const data = JSON.parse(out)
2425

25-
const commandToRun = makeCommandFromURL(data?.requestedUrl, options)
26-
console.log(`command stopped: ${commandToRun}`)
26+
const { commandToRun } = makeCommandFromURL(data?.requestedUrl, options)
27+
if (options?.consoleLog ?? true) console.log(`Stopped Test on ${data?.requestedUrl}`)
2728

2829
const accessibilityScoresJSON = JSON.parse(accessibilityScores)
2930
const categoriesScoresObject = {}
@@ -44,7 +45,9 @@ const execResult = (err = null, out, outerr = null) => {
4445

4546
if (!existsSync('./out/logs')) mkdirSync('./out/logs')
4647

47-
const logFileNameBasedOnUrl = data?.requestedUrl.replace(/^(http|https):\/\/(www.|)/g, '').replaceAll("/", "").split('.').reverse().join('.')
48+
const REGEX_HTTPS_HTTP = /^(http|https):\/\/(www.|)/g
49+
50+
const logFileNameBasedOnUrl = data?.requestedUrl.replace(REGEX_HTTPS_HTTP, '').replaceAll("/", "").split('.').reverse().join('.')
4851
const rawOutputFilename = `./out/logs/${logFileNameBasedOnUrl}-${optionCategories
4952
.join('-')}-${Date.now()}.json`
5053

@@ -53,9 +56,8 @@ const execResult = (err = null, out, outerr = null) => {
5356
}
5457

5558
const testURL = (urlToCheck, options = {}) => {
56-
const commandToRun = makeCommandFromURL(urlToCheck, options)
57-
58-
console.log(`running command: ${commandToRun}`)
59+
const { commandToRun } = makeCommandFromURL(urlToCheck, options)
60+
if (options?.consoleLog ?? true) console.log(`Running Test on ${urlToCheck}`)
5961

6062
series([
6163
() => exec(commandToRun, execOptions, execResult),
@@ -64,4 +66,14 @@ const testURL = (urlToCheck, options = {}) => {
6466
])
6567
}
6668

67-
urlList.forEach(url => testURL(url, options))
69+
const main = (urlList, options) => {
70+
const isOptionsCategories = getCategoriesFlags(options?.categories)
71+
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`
72+
73+
console.log(`TLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
74+
console.log(`Running with these Flags: ${currentFlags}\n`)
75+
76+
urlList.forEach((url, index) => { testURL(url, options) })
77+
}
78+
79+
main(urlList, options)

0 commit comments

Comments
 (0)