Skip to content

Commit

Permalink
Update workflows, Utility class and more files (#20)
Browse files Browse the repository at this point in the history
Update `workflows, Utility class` and more files
  • Loading branch information
EmptyWork authored Aug 14, 2023
2 parents 595db70 + 4ff0c4b commit 551016b
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 57 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/test.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/tlighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: TLighthouse

on:
pull_request:
types: [synchronize, opened, reopened]
push:
branches: [main, development, dev-workflows]

jobs:
install-ubuntu:
name: Install on Ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: npm ci

install-macos:
name: Install on MacOS
runs-on: macos-latest

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: npm ci

install-windows:
name: Install on Windows
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Install Dependencies
run: npm ci

test:
name: Test with Jest
needs: [install-ubuntu, install-macos, install-windows]
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Install Dependencies
run: npm ci

- name: Testing with Jest
run: npm test

running:
name: Run with Node
needs: test
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Install Dependencies
run: npm ci

- name: Set up Chrome
uses: browser-actions/setup-chrome@v1

- name: Running the program
run: npm start
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TLighthouse - Lighthouse Accesibility Thesis

This is a small program that I created to help me to gather Accessibility report from Google Lighthouse™ for my Bachelor's Thesis.

## Requirement

Before you can install this program, you need to make sure that you have the latest version of [Google Chrome](https://www.google.com/chrome/) this due to [Lighthouse-CLI]() only support the use of Chrome as the program to run the test.

### Installation

To use this program you just need to follow this steps:

- `fork` this repo or `clone` this repo
- move to the directory where this repo located on you local device, then do `npm install` to download all the dependecies
- `npm run start` or `yarn start` to start initiate the program
- you can then access newly created file on `src` named `urlList.class.js` and add the certain url of websites that you want to do test on.


## Credits

- [Google Lighthouse](https://github.com/GoogleChrome/lighthouse) (opensource - owned and trademarked by Google inc.)
- [Lighthouse CLI](https://github.com/GoogleChrome/lighthouse) (opensource - owned and trademarked by Google inc.)
- [Async](https://github.com/caolan/async) (opensource)

### Supports

[![EmptyWork](https://raw.githubusercontent.com/EmptyWork/cpp-teaching/master/assets/active.svg)](https://emptywork.netlify.app)
5 changes: 3 additions & 2 deletions clean.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { existsSync, rmSync } from 'fs'
import { Logger, LoggerType } from "./src/lib/utilities.class.js"

const cleanDirectory = () => {
if (!existsSync('./out/')) return console.error(`failed: dir out not exist`)
if (!existsSync('./out/')) return Logger(`\`./out\` not exist`, LoggerType.warning)
rmSync('./out/', { recursive: true })
console.log(`complete: dir out has been deleted`)
Logger(`\`./out\` has been deleted`, LoggerType.info)
}

cleanDirectory()
1 change: 1 addition & 0 deletions legacy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const main = (urlList, options) => {
const isOptionsCategories = getCategoriesFlags(options?.categories)
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`

console.log(`Copyright (c) 2023 Stevarth`)
console.log(`[Legacy] TLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
console.log(`Running with these Flags: ${currentFlags}\n`)

Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lighthouse-link-thesis",
"version": "0.0.6c",
"version": "0.0.7c",
"description": "a way to automatically use lighthouse to get accessibility report number",
"main": "index.class.js",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { existsSync, copyFileSync } from 'fs'
import { copyIfNotExists } from "./src/lib/utilities.class.js";

if (!existsSync('./src/urlList.class.js')) copyFileSync('./src/urlList.class.example', './src/urlList.class.js')
copyIfNotExists('./src/urlList.class.js', './src/urlList.class.example')
36 changes: 24 additions & 12 deletions src/lib/application.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { series } from "async"
import { exec } from 'child_process'
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'
import { getCategoriesFlags, getCategoriesFromCategoriesFlags, getCurrentCategories } from "./categoriesHandlers.class.js"
import { Logger, LoggerType } from "./utilities.class.js"
import Command from "./commandHandlers.class.js"

export default class ThesisLighthouse {
Expand All @@ -20,9 +21,10 @@ export default class ThesisLighthouse {
this.#currentCategories = getCurrentCategories(categories)
}

testURL = (urlToCheck, options = {}) => {
testURL = (urlToCheck, options = {}, currentIndex) => {
const { commandToRun } = Command.make(urlToCheck, options)
if (options?.consoleLog ?? true) console.log(`Running Test on ${urlToCheck}`)

Logger(`Running Test on ${urlToCheck}`, LoggerType.info, options.consoleLog)

series([
() => exec(commandToRun, this.execOptions, this.execResult.bind(this))
Expand All @@ -36,11 +38,11 @@ export default class ThesisLighthouse {
)

const data = JSON.parse(out)
if (this.options?.consoleLog) console.log(`Stopped Test on ${data?.requestedUrl}`)
Logger(`Stopped Test on ${data?.requestedUrl}`, LoggerType.info, this.options?.consoleLog)

const newAccessibilityJSON = this.#produceNewJSON(data, accessibilityScores)

this.#checkDir()
this.#checkDir([`${this.#outputDir}`, `${this.#outputDir}logs`])
const rawOutputFilename = this.#createFileName(data?.requestedUrl)

writeFileSync(rawOutputFilename, JSON.stringify(data), { flag: 'w' })
Expand Down Expand Up @@ -79,20 +81,30 @@ export default class ThesisLighthouse {
return (!existsSync(location)) ? readFileSync(backup) : readFileSync(location)
}

#checkDir = () => {
if (!existsSync(`${this.#outputDir}`)) mkdirSync(`${this.#outputDir}`)
if (!existsSync(`${this.#outputDir}logs`)) mkdirSync(`${this.#outputDir}logs`)
#checkDir = (directories) => {
switch (typeof directories) {
case "object":
directories.forEach(directory => this.#makeDirIfNotExists(directory))
break;
case "string":
this.#makeDirIfNotExists(directories)
break;
}
}

start = () => {
if (this.options?.consoleLog) console.log(this.options)
#makeDirIfNotExists = (location) => {
if (!existsSync(location)) mkdirSync(location)
}

start = () => {
const isOptionsCategories = getCategoriesFlags(this.options?.categories)
const currentFlags = `${isOptionsCategories}\n\t--output json \n\t--disable-full-page-screenshot \n\t--chrome-flags="\n\t\t--no-sandbox \n\t\t--headless \n\t\t--disable-gpu"`

console.log(`ThesisLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
console.log(`Running with these flags: ${currentFlags}\n`)
Logger(`Copyright (c) 2023 Stevarth`)
Logger(`ThesisLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
Logger(this.options, LoggerType.info, this.options?.consoleLog)
Logger(`Running with these flags: ${currentFlags}\n`)

this.urlList.forEach((url, index) => { this.testURL(url, this.options) })
this.urlList.forEach((url, index) => { this.testURL(url, this.options, index) })
}
}
21 changes: 20 additions & 1 deletion src/lib/utilities.class.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { existsSync, copyFileSync } from 'fs'

class Utility {
LoggerType = {
'info': "Info",
'warning': "Warning",
'error': "Error",
'empty': ""
}

isEmpty = data => {
switch (typeof data) {
case "array":
Expand All @@ -10,6 +19,15 @@ class Utility {
}
}

Logger = (text, type = LoggerType.empty, condition = true) => {
const typeFormatted = (type === LoggerType.empty) ? `${type}` : `${type}:`
if (condition) console.log(`${typeFormatted}`, text)
}

copyIfNotExists = (location, source) => {
if (!existsSync(location)) copyFileSync(source, location)
}

#isArrayEmpty = (data = []) => {
return (data === undefined || data.length === 0) ? false : true
}
Expand All @@ -21,4 +39,5 @@ class Utility {
}
}

export default new Utility()
export default new Utility()
export const { Logger, LoggerType, copyIfNotExists } = new Utility()
33 changes: 32 additions & 1 deletion test/lib/utilites.class.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Utility from "../../src/lib/utilities.class.js"
import Utility, { LoggerType } from "../../src/lib/utilities.class.js"

test('isEmpty of an empty Array', () => {
expect(
Expand Down Expand Up @@ -49,3 +49,34 @@ test('Not isEmpty of not an empty Object', () => {
).toBe(true);
});

test('Logger test', () => {
const spyOn = jest.spyOn(console, 'log')
Utility.Logger("Running Test on localhost", "Info", false)
expect(
spyOn
).not.toHaveBeenCalled()
})

test('Logger test', () => {
const spyOn = jest.spyOn(console, 'log')
Utility.Logger("Running Test on localhost", "Info")
expect(
spyOn
).toHaveBeenCalledWith("Info:", "Running Test on localhost")
})

test('LoggerType.empty', () => {
expect(LoggerType.empty).toStrictEqual("")
})

test('LoggerType.info', () => {
expect(LoggerType.info).toStrictEqual("Info")
})

test('LoggerType.warning', () => {
expect(LoggerType.warning).toStrictEqual("Warning")
})

test('LoggerType.error', () => {
expect(LoggerType.error).toStrictEqual("Error")
})

0 comments on commit 551016b

Please sign in to comment.