Skip to content

Commit

Permalink
Refactor zim tool checking as lazy method
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Oct 4, 2023
1 parent d84b294 commit 3c5a0d0
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions test/testAllRenders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ import { zimcheckAvailable, zimdumpAvailable } from './util.js'

/*
This is the template for e2e tests of different wikis
1. Verify zimcheck and zimdump availability
1. Verify zimcheck and zimdump availability and caches result
2. Gets output file and checks its integrity
3. Returns output file per renderer in the callback function
*/

let zimToolsChecked = false
async function checkZimTools() {
if (zimToolsChecked) {
return
}

const zimcheckIsAvailable = await zimcheckAvailable()
const zimdumpIsAvailable = await zimdumpAvailable()

if (!zimcheckIsAvailable || !zimdumpIsAvailable) {
const missingTool = !zimcheckIsAvailable ? 'Zimcheck' : 'Zimdump'
logger.error(`${missingTool} not installed, exiting test`)
process.exit(1)
}

zimToolsChecked = true
}

async function getOutFiles(renderName: string, testId: string, articleList: string, mwUrl: string, format?: string | string[]): Promise<any> {
const parameters = {
mwUrl,
Expand All @@ -29,15 +47,7 @@ async function getOutFiles(renderName: string, testId: string, articleList: stri
}

export async function testAllRenders(mwUrl: string, articleList: string, format: string | string[], callback) {
const zimcheckIsAvailable = await zimcheckAvailable()
const zimdumpIsAvailable = await zimdumpAvailable()

if (!zimcheckIsAvailable || !zimdumpIsAvailable) {
const missingTool = !zimcheckIsAvailable ? 'Zimcheck' : 'Zimdump'
logger.error(`${missingTool} not installed, exiting test`)
process.exit(1)
}

await checkZimTools()
for (const renderer of RENDERERS_LIST) {
const now = new Date()
const testId = `mwo-test-${+now}`
Expand Down

0 comments on commit 3c5a0d0

Please sign in to comment.