Skip to content

Commit

Permalink
Refactor rimraf invocation in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Nov 3, 2023
1 parent d441e40 commit 9240879
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 220 deletions.
4 changes: 3 additions & 1 deletion test/e2e/articleLists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ await testAllRenders(parameters, async (outFiles) => {
}
*/

rimraf.sync(`./${testId}`)
const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
})
afterAll(() => {
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})
66 changes: 34 additions & 32 deletions test/e2e/bm.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as mwoffliner from '../../src/mwoffliner.lib.js'
import { zimdump } from '../util.js'
import { testAllRenders } from '../testAllRenders.js'
import { execa } from 'execa'
Expand All @@ -18,43 +17,46 @@ const parameters = {
}

await testAllRenders(parameters, async (outFiles) => {
describe('e2e test for bm.wikipedia.org', () => {
// TODO: blocked by issues/1931
/*
// TODO: blocked by issues/1931
/*
test(`test zim integrity for ${outFiles[0]?.renderer} renderer`, async () => {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
})
*/

test(`Simple articleList for ${outFiles[0]?.renderer} renderer`, async () => {
// Created 1 output
expect(outFiles).toHaveLength(1)

for (const dump of outFiles) {
if (dump.nopic) {
// nopic has enough files
expect(dump.status.files.success).toBeGreaterThan(14)
// nopic has enough redirects
expect(dump.status.redirects.written).toBeGreaterThan(170)
// nopic has enough articles
expect(dump.status.articles.success).toBeGreaterThan(700)
}
*/

test(`Simple articleList for ${outFiles[0]?.renderer} renderer for bm.wikipedia.org`, async () => {
await execa('redis-cli flushall', { shell: true })
// Created 1 output
expect(outFiles).toHaveLength(1)

for (const dump of outFiles) {
if (dump.nopic) {
// nopic has enough files
expect(dump.status.files.success).toBeGreaterThan(14)
// nopic has enough redirects
expect(dump.status.redirects.written).toBeGreaterThan(170)
// nopic has enough articles
expect(dump.status.articles.success).toBeGreaterThan(700)
}
})
}
})

test(`Articles with "Discussion" namespace for ${outFiles[0]?.renderer} renderer`, async () => {
await execa('redis-cli flushall', { shell: true })
const outFiles = await mwoffliner.execute({ ...parameters, addNamespaces: 1 })
afterAll(() => {
rimraf.sync(`./${outFiles[0].testId}`)
})
})

// Created 1 output
expect(outFiles).toHaveLength(1)
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
const discussionArticlesList = discussionArticlesStr.match(/Discussion:/g)
expect(discussionArticlesList.length).toBeGreaterThan(30)
})
await testAllRenders({ ...parameters, addNamespaces: 1 }, async (outFiles) => {
test(`Articles with "Discussion" namespace for ${outFiles[0]?.renderer} renderer for bm.wikipedia.org`, async () => {
await execa('redis-cli flushall', { shell: true })

afterAll(() => {
rimraf.sync(`./${outFiles[0].testId}`)
})
// Created 1 output
expect(outFiles).toHaveLength(1)
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
const discussionArticlesList = discussionArticlesStr.match(/Discussion:/g)
expect(discussionArticlesList.length).toBeGreaterThan(30)
})
afterAll(() => {
rimraf.sync(`./${outFiles[0].testId}`)
})
})
16 changes: 14 additions & 2 deletions test/e2e/formatParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,76 @@ const parameters = {
await testAllRenders({ ...parameters, format: 'nopic', articleList: 'BMW' }, async (outFiles) => {
describe('format:nopic', () => {
test(`Test en.wikipedia.org using format:nopic for ${outFiles[0]?.renderer} renderer`, async () => {
await execa('redis-cli flushall', { shell: true })
const articleFromDump = await zimdump(`show --url A/BMW ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

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

expect(imgElements).toHaveLength(0)
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})

await testAllRenders({ ...parameters, format: 'nodet', articleList: 'BMW' }, async (outFiles) => {
describe('format:nodet', () => {
test(`Test en.wikipedia.org using format:nodet for ${outFiles[0]?.renderer} renderer`, async () => {
await execa('redis-cli flushall', { shell: true })
const articleFromDump = await zimdump(`show --url A/BMW ${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(`./${outFiles[0].testId}`)
})
})
})

await testAllRenders({ ...parameters, format: 'novid', articleList: 'Animation' }, async (outFiles) => {
describe('format:novid to check no video tags', () => {
test(`Test en.wikipedia.org using format:novid for ${outFiles[0]?.renderer} renderer (no video)`, async () => {
await execa('redis-cli flushall', { shell: true })
const articleFromDump = await zimdump(`show --url A/Animation ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

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

expect(audioElements).toHaveLength(0)
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})

await testAllRenders({ ...parameters, format: 'novid', articleList: 'English_alphabet' }, async (outFiles) => {
describe('format:novid to check no audio tags', () => {
test(`Test en.wikipedia.org using format:novid for ${outFiles[0]?.renderer} renderer (no audio)`, async () => {
await execa('redis-cli flushall', { shell: true })
const articleFromDump = await zimdump(`show --url A/English_alphabet ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)

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

expect(videoElements).toHaveLength(0)
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})

// TODO: blocked by issues/1928
/*
await testAllRenders({ ...parameters, format: 'nopdf', articleList: 'PDF' }, async (outFiles) => {
describe('format:pdf to check no internal links pdf files', () => {
test.skip(`Test en.wikipedia.org using format:nopdf for ${outFiles[0]?.renderer} renderer`, async () => {
test(`Test en.wikipedia.org using format:nopdf for ${outFiles[0]?.renderer} renderer`, async () => {
await execa('redis-cli flushall', { shell: true })
const articleFromDump = await zimdump(`show --url A/PDF ${outFiles[0].outFile}`)
const articleDoc = domino.createDocument(articleFromDump)
// TODO: blocked by issues/1928
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const anchorElements = Array.from(articleDoc.querySelectorAll('a'))
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})
*/
Loading

0 comments on commit 9240879

Please sign in to comment.