Skip to content

Commit

Permalink
Add tests for the format params while using WikimediaMobile render
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Oct 4, 2023
1 parent 6dc7d7a commit a5cbf51
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
126 changes: 126 additions & 0 deletions test/e2e/mobileRenderFormatParams.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'dotenv/config.js'
import * as mwoffliner from '../../src/mwoffliner.lib.js'
import * as logger from '../../src/Logger.js'
import domino from 'domino'
import rimraf from 'rimraf'
import { execa } from 'execa'
import { jest } from '@jest/globals'
import { zimdumpAvailable, zimdump } from '../util.js'

jest.setTimeout(200000)

let zimdumpIsAvailable

beforeAll(async () => {
zimdumpIsAvailable = await zimdumpAvailable()
if (!zimdumpIsAvailable) {
logger.error('Zimdump not installed, exiting test')
process.exit(1)
}
})

async function getOutFiles(testId: string, articleList: string, mwUrl: string, format?: string): Promise<any> {
const parameters = {
mwUrl,
adminEmail: '[email protected]',
outputDirectory: testId,
redis: process.env.REDIS,
articleList,
forceRender: 'WikimediaMobile',
format,
}

await execa('redis-cli flushall', { shell: true })
const outFiles = await mwoffliner.execute(parameters)

return outFiles
}

// TODO: articulate this test with /pull/1898 once merged
describe('Mobile render with multiple format params', () => {
const mwUrl = 'https://en.wikipedia.org'

test('Test WikimediaMobile with en.wikipedia.org using format:nopic param', async () => {
const articleList = 'BMW'
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await getOutFiles(testId, articleList, mwUrl, 'nopic')
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

const imgElements = Array.from(articleDoc.querySelectorAll('img'))

expect(imgElements).toHaveLength(0)

rimraf.sync(`./${testId}`)
})

test('Test WikimediaMobile render with en.wikipedia.org using format:nodet param', async () => {
const articleList = 'BMW'
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await getOutFiles(testId, articleList, mwUrl, 'nodet')
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

const sectionsElements = Array.from(articleDoc.querySelectorAll('section'))

expect(sectionsElements).toHaveLength(1)
expect(sectionsElements[0].getAttribute('data-mw-section-id')).toEqual('0')

rimraf.sync(`./${testId}`)
})

test('Test WikimediaMobile render with en.wikipedia.org using format:novid param to check no video tags', async () => {
const articleList = 'Animation'
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await getOutFiles(testId, articleList, mwUrl, 'novid')
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

const videoElements = Array.from(articleDoc.querySelectorAll('video'))

expect(videoElements).toHaveLength(0)

rimraf.sync(`./${testId}`)
})

test('Test WikimediaMobile render with en.wikipedia.org using format:novid param to check no audio tags', async () => {
const articleList = 'English_alphabet'
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await getOutFiles(testId, articleList, mwUrl, 'novid')
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

const audioElements = Array.from(articleDoc.querySelectorAll('audio'))

expect(audioElements).toHaveLength(0)

rimraf.sync(`./${testId}`)
})

// TODO: secure nppdf format for all renders
test.skip('Test WikimediaMobile render with en.wikipedia.org using format:nopdf', async () => {
const articleList = 'PDF'
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await getOutFiles(testId, articleList, mwUrl, 'nopdf')
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

const anchorElements = Array.from(articleDoc.querySelectorAll('a'))

anchorElements.forEach((anchor) => {
expect(anchor.href).not.toContain('.pdf')
})

rimraf.sync(`./${testId}`)
})
})
1 change: 1 addition & 0 deletions test/e2e/mobileRenderIntegrity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const commonTreatmentTest = async (articleList: string, mwUrl: string) => {
rimraf.sync(`./${testId}`)
}

// TODO: articulate this test with /pull/1898 once merged
describe('Mobile render zim file integrity', () => {
const mwUrl = 'https://en.wikipedia.org'
// TODO: some articles such as 'Canada' don't pass this test even with desktop renderer
Expand Down

0 comments on commit a5cbf51

Please sign in to comment.