-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1898 from openzim/1887-e2e-modularized
Modularizing e2e tests
- Loading branch information
Showing
6 changed files
with
150 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { testAllRenders } from '../testAllRenders.js' | ||
import domino from 'domino' | ||
import { zimdump } from '../util.js' | ||
import 'dotenv/config.js' | ||
import { jest } from '@jest/globals' | ||
import rimraf from 'rimraf' | ||
|
||
jest.setTimeout(60000) | ||
|
||
// Check the integrity of img elements between zim file and article html taken from it | ||
const verifyImgElements = (imgFilesArr, imgElements) => { | ||
for (const img of imgElements) { | ||
for (const imgFile of imgFilesArr) { | ||
if (img.getAttribute('src').includes(imgFile)) { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
|
||
const mwUrl = 'https://en.wikipedia.org' | ||
const articleList = 'User:Kelson/MWoffliner_CI_reference' | ||
const format = '' | ||
|
||
await testAllRenders(mwUrl, articleList, format, async (outFiles) => { | ||
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`) | ||
describe('e2e test for en.wikipedia.org', () => { | ||
const articleDoc = domino.createDocument(articleFromDump) | ||
test(`test article header for ${outFiles[0]?.renderer} renderer`, async () => { | ||
expect(articleDoc.querySelector('h1.article-header')).toBeTruthy() | ||
}) | ||
test(`test article image integrity for ${outFiles[0]?.renderer} renderer`, async () => { | ||
const mediaFiles = await zimdump(`list --ns I ${outFiles[0].outFile}`) | ||
const mediaFilesArr = mediaFiles.split('\n') | ||
const imgFilesArr = mediaFilesArr.filter((elem) => elem.endsWith('pdf') || elem.endsWith('png') || elem.endsWith('jpg')) | ||
const imgElements = Array.from(articleDoc.querySelectorAll('img')) | ||
expect(verifyImgElements(imgFilesArr, imgElements)).toBe(true) | ||
}) | ||
|
||
afterAll(() => { | ||
rimraf.sync(`./${outFiles[0].testId}`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as logger from '../src/Logger.js' | ||
import * as mwoffliner from '../src/mwoffliner.lib.js' | ||
import { execa } from 'execa' | ||
import { RENDERERS_LIST } from '../src/util/const.js' | ||
import { zimcheckAvailable, zimdumpAvailable } from './util.js' | ||
|
||
/* | ||
This is the template for e2e tests of different wikis | ||
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, | ||
adminEmail: 'test@kiwix.org', | ||
outputDirectory: testId, | ||
redis: process.env.REDIS, | ||
articleList, | ||
forceRender: renderName, | ||
format, | ||
} | ||
|
||
await execa('redis-cli flushall', { shell: true }) | ||
const outFiles = await mwoffliner.execute(parameters) | ||
|
||
return outFiles | ||
} | ||
|
||
export async function testAllRenders(mwUrl: string, articleList: string, format: string | string[], callback) { | ||
await checkZimTools() | ||
for (const renderer of RENDERERS_LIST) { | ||
const now = new Date() | ||
const testId = `mwo-test-${+now}` | ||
const outFiles = await getOutFiles(renderer, testId, articleList, mwUrl, format) | ||
outFiles[0].testId = testId | ||
outFiles[0].renderer = renderer | ||
await callback(outFiles) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters