Skip to content

Commit

Permalink
Update e2e test for bm wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Aug 31, 2023
1 parent 324141b commit 4420c39
Showing 1 changed file with 67 additions and 53 deletions.
120 changes: 67 additions & 53 deletions test/e2e/bm.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { renderers } from './rendererList.js'
import rimraf from 'rimraf'
import { zimcheckAvailable, zimcheck } from '../util.js'
import 'dotenv/config.js'
import { jest } from '@jest/globals'
import { jest, test } from '@jest/globals'
import { zimdumpAvailable, zimdump } from '../util.js'

jest.setTimeout(200000)

describe('bm', () => {
for (const renderer of renderers) {
test.each(renderers)('Simple articleList', async (renderer) => {
// Test only render API that is supported by the wiki
if (renderer === 'WikimediaDesktop') {
const now = new Date()
Expand All @@ -26,69 +26,83 @@ describe('bm', () => {

const renderParameters = { ...parameters, renderName: renderer }

test('Simple articleList', async () => {
await execa('redis-cli flushall', { shell: true })
await execa('redis-cli flushall', { shell: true })

const outFiles = await mwoffliner.execute(renderParameters)
const outFiles = await mwoffliner.execute(renderParameters)

// Created 1 output
expect(outFiles).toHaveLength(1)
// 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)
}
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)
}
}

if (await zimcheckAvailable()) {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
} else {
console.log('Zimcheck not installed, skipping test')
}
if (await zimcheckAvailable()) {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
} else {
console.log('Zimcheck not installed, skipping test')
}

if (await zimdumpAvailable()) {
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
// Articles with "Discussion" namespace should be only with option addNamespaces: 1
expect(discussionArticlesStr.length).toBe(0)
} else {
console.log('Zimdump not installed, skipping test')
}
if (await zimdumpAvailable()) {
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
// Articles with "Discussion" namespace should be only with option addNamespaces: 1
expect(discussionArticlesStr.length).toBe(0)
} else {
console.log('Zimdump not installed, skipping test')
}

// TODO: clear test dir
rimraf.sync(`./${testId}`)
// TODO: clear test dir
rimraf.sync(`./${testId}`)

const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
})
const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
}
})

test('Articles with "Discussion" namespace', async () => {
await execa('redis-cli flushall', { shell: true })
test.each(renderers)('Articles with "Discussion" namespace', async (renderer) => {
// Test only render API that is supported by the wiki
if (renderer === 'WikimediaDesktop') {
const now = new Date()
const testId = `mwo-test-${+now}`

const outFiles = await mwoffliner.execute({ ...renderParameters, addNamespaces: 1 })
// Created 1 output
expect(outFiles).toHaveLength(1)
const parameters = {
mwUrl: 'https://bm.wikipedia.org',
adminEmail: '[email protected]',
outputDirectory: testId,
redis: process.env.REDIS,
format: ['nopic'],
}

if (await zimdumpAvailable()) {
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
const discussionArticlesList = discussionArticlesStr.match(/Discussion:/g)
expect(discussionArticlesList.length).toBeGreaterThan(30)
} else {
console.log('Zimdump not installed, skipping test')
}
await execa('redis-cli flushall', { shell: true })

const renderParameters = { ...parameters, renderName: renderer }

const outFiles = await mwoffliner.execute({ ...renderParameters, addNamespaces: 1 })
// Created 1 output
expect(outFiles).toHaveLength(1)

if (await zimdumpAvailable()) {
const discussionArticlesStr = await zimdump(`list --ns A/Discussion ${outFiles[0].outFile}`)
const discussionArticlesList = discussionArticlesStr.match(/Discussion:/g)
expect(discussionArticlesList.length).toBeGreaterThan(30)
} else {
console.log('Zimdump not installed, skipping test')
}

// TODO: clear test dir
rimraf.sync(`./${testId}`)
// TODO: clear test dir
rimraf.sync(`./${testId}`)

const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
})
const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
}
}
})
})

0 comments on commit 4420c39

Please sign in to comment.