Skip to content

Commit a9ac01a

Browse files
authored
Feature Flags Options from commandHandlers.js (#6)
Feature `Flags Options` from `commandHandlers.js`
2 parents dadfd37 + 7b24a3c commit a9ac01a

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

index.js

Lines changed: 20 additions & 9 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)
@@ -14,17 +15,16 @@ Object.prototype.isEmpty = (obj) => {
1415
}
1516

1617
Array.prototype.isEmpty = (arr) => {
17-
if (arr === undefined || arr.length === 0) return false
18-
return true
18+
return (arr === undefined || arr.length === 0) ? false : true
1919
}
2020

2121
const execResult = (err = null, out, outerr = null) => {
2222
let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json')
2323

2424
const data = JSON.parse(out)
2525

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

2929
const accessibilityScoresJSON = JSON.parse(accessibilityScores)
3030
const categoriesScoresObject = {}
@@ -45,7 +45,9 @@ const execResult = (err = null, out, outerr = null) => {
4545

4646
if (!existsSync('./out/logs')) mkdirSync('./out/logs')
4747

48-
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('.')
4951
const rawOutputFilename = `./out/logs/${logFileNameBasedOnUrl}-${optionCategories
5052
.join('-')}-${Date.now()}.json`
5153

@@ -54,9 +56,8 @@ const execResult = (err = null, out, outerr = null) => {
5456
}
5557

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

6162
series([
6263
() => exec(commandToRun, execOptions, execResult),
@@ -65,4 +66,14 @@ const testURL = (urlToCheck, options = {}) => {
6566
])
6667
}
6768

68-
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)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lighthouse-link-thesis",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "a way to automatically use lighthouse to get accessibility report number",
55
"main": "index.js",
66
"type": "module",

src/lib/commandHandlers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { getCategoriesFlags } from "./categoriesHandlers.js"
22

33
const makeCommandFromURL = (url, options) => {
44
const isOptionsCategories = getCategoriesFlags(options?.categories)
5-
return `lighthouse ${url} ${isOptionsCategories}--output json --disable-full-page-screenshot`
5+
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`
6+
const commandToRun = `lighthouse ${url} ${currentFlags}`
7+
return { commandToRun, currentFlags }
68
}
79

810
export { makeCommandFromURL }

0 commit comments

Comments
 (0)