Skip to content

Commit

Permalink
Merge pull request #1933 from openzim/1930-apply-test-coverage-for-al…
Browse files Browse the repository at this point in the history
…l-endpoins

Apply test coverage for all endpoins
  • Loading branch information
kelson42 authored Oct 26, 2023
2 parents 8ebd7d0 + e9812d3 commit 28adc40
Show file tree
Hide file tree
Showing 20 changed files with 789 additions and 901 deletions.
95 changes: 48 additions & 47 deletions test/e2e/articleLists.test.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import * as mwoffliner from '../../src/mwoffliner.lib.js'
import { execa } from 'execa'
import rimraf from 'rimraf'
import { zimcheckAvailable, zimcheck } from '../util.js'
import 'dotenv/config'
import { jest } from '@jest/globals'
import { testAllRenders } from '../testAllRenders.js'

jest.setTimeout(10000)

describe('articleList', () => {
const now = new Date()
const testId = `mwo-test-${+now}`

const articleList = 'Kiwix,Wikipedia,Internet,Real-time computer graphics'
const articleListToIgnore = 'Wikipedia, Internet'
const listMinusIgnore = 2
const parameters = {
mwUrl: 'https://en.wikipedia.org',
adminEmail: 'test@kiwix.org',
articleList,
articleListToIgnore,
outputDirectory: testId,
redis: process.env.REDIS,
format: ['nopic'],
forceRender: 'WikimediaDesktop',
}

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

const outFiles = await mwoffliner.execute(parameters)

// Created 1 output
expect(outFiles).toHaveLength(1)

for (const dump of outFiles) {
if (dump.nopic) {
// Output has right amount of articles
expect(dump.status.articles.success).toEqual(listMinusIgnore)
// Output has no failed article
expect(dump.status.articles.fail).toEqual(0)
const articleList = 'Kiwix,Wikipedia,Internet,Real-time computer graphics'
const articleListToIgnore = 'Wikipedia, Internet'

const parameters = {
mwUrl: 'https://en.wikipedia.org',
adminEmail: 'test@kiwix.org',
articleList,
articleListToIgnore,
redis: process.env.REDIS,
format: ['nopic'],
}

await testAllRenders(parameters, async (outFiles) => {
describe('articleList', () => {
const now = new Date()
const testId = `mwo-test-${+now}`
const listMinusIgnore = 2

test(`articleList and articleListIgnore check using ${outFiles[0].renderer} renderer`, async () => {
await execa('redis-cli flushall', { shell: true })

// Created 1 output
expect(outFiles).toHaveLength(1)

for (const dump of outFiles) {
if (dump.nopic) {
// Output has right amount of articles
expect(dump.status.articles.success).toEqual(listMinusIgnore)
// Output has no failed article
expect(dump.status.articles.fail).toEqual(0)
}
}
}

// Scraped selected articles from wikipedia en');
if (await zimcheckAvailable()) {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
} else {
console.log('Zimcheck not installed, skipping test')
}

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

// Scraped selected articles from wikipedia en');
// TODO: Blocked by issues/1931
/*
if (await zimcheckAvailable()) {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
} else {
console.log('Zimcheck not installed, skipping test')
}
*/

rimraf.sync(`./${testId}`)
const redisScan = await execa('redis-cli --scan', { shell: true })
// Redis has been cleared
expect(redisScan.stdout).toEqual('')
})
})
})
113 changes: 42 additions & 71 deletions test/e2e/bm.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,58 @@
import * as mwoffliner from '../../src/mwoffliner.lib.js'
import { zimdump } from '../util.js'
import { testAllRenders } from '../testAllRenders.js'
import { execa } from 'execa'
import { jest } from '@jest/globals'
import rimraf from 'rimraf'
import { zimcheckAvailable, zimcheck } from '../util.js'
import 'dotenv/config.js'
import { jest } from '@jest/globals'
import { zimdumpAvailable, zimdump } from '../util.js'

jest.setTimeout(200000)

describe('bm', () => {
const now = new Date()
const testId = `mwo-test-${+now}`

const parameters = {
mwUrl: 'https://bm.wikipedia.org',
adminEmail: 'test@kiwix.org',
outputDirectory: testId,
redis: process.env.REDIS,
format: ['nopic'],
forceRender: 'WikimediaDesktop',
}

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

const outFiles = await mwoffliner.execute(parameters)

// 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)
}
}

if (await zimcheckAvailable()) {
const parameters = {
mwUrl: 'https://bm.wikipedia.org',
adminEmail: 'test@kiwix.org',
redis: process.env.REDIS,
format: ['nopic'],
}

await testAllRenders(parameters, async (outFiles) => {
describe('e2e test for bm.wikipedia.org', () => {
// TODO: blocked by issues/1931
/*
test(`test zim integrity for ${outFiles[0]?.renderer} renderer`, async () => {
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')
}

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

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(`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)
}
}
})

const outFiles = await mwoffliner.execute({ ...parameters, addNamespaces: 1 })
// Created 1 output
expect(outFiles).toHaveLength(1)
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 })

if (await zimdumpAvailable()) {
// 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)
} else {
console.log('Zimdump not installed, skipping test')
}

// TODO: clear test dir
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}`)
})
})
})
53 changes: 22 additions & 31 deletions test/e2e/downloadImage.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
import * as mwoffliner from '../../src/mwoffliner.lib.js'
import { execa } from 'execa'
import { zimcheck } from '../util.js'
import rimraf from 'rimraf'
import { zimcheckAvailable, zimcheck } from '../util.js'
import { testAllRenders } from '../testAllRenders.js'
import 'dotenv/config.js'
import { jest } from '@jest/globals'

jest.setTimeout(200000)

const describeIf = process.env.S3_URL ? describe : describe.skip
describeIf('Check image downloading from S3 using optimisationCacheUrl parameter', () => {
const now = new Date()
const testId = `mwo-test-${+now}`

const parameters = {
mwUrl: 'https://fr.wikipedia.org',
adminEmail: 'test@kiwix.org',
outputDirectory: testId,
redis: process.env.REDIS,
articleList: 'Paris',
format: ['nodet'],
optimisationCacheUrl: process.env.S3_URL,
forceRender: 'WikimediaDesktop',
}

test('right scrapping from fr.wikipedia.org with optimisationCacheUrl parameter', async () => {
await execa('redis-cli flushall', { shell: true })

const outFiles = await mwoffliner.execute(parameters)

if (await zimcheckAvailable()) {
const parameters = {
mwUrl: 'https://fr.wikipedia.org',
adminEmail: 'test@kiwix.org',
redis: process.env.REDIS,
articleList: 'Paris',
format: ['nodet'],
optimisationCacheUrl: process.env.S3_URL,
}

await testAllRenders(parameters, async (outFiles) => {
describeIf('Check image downloading from S3 using optimisationCacheUrl parameter', () => {
test(`right scrapping from fr.wikipedia.org with optimisationCacheUrl parameter for ${outFiles[0]?.renderer} renderer`, async () => {
await expect(zimcheck(outFiles[0].outFile)).resolves.not.toThrowError()
} else {
console.log('Zimcheck not installed, skipping test')
}

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

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

const redisScan = await execa('redis-cli --scan', { shell: true })
expect(redisScan.stdout).toEqual('')
})
afterAll(() => {
rimraf.sync(`./${outFiles[0].testId}`)
})
})
})
17 changes: 11 additions & 6 deletions test/e2e/en.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testAllRenders } from '../testAllRenders.js'
import domino from 'domino'
import { zimdump, zimcheck } from '../util.js'
import { zimdump } from '../util.js'
import 'dotenv/config.js'
import { jest } from '@jest/globals'
import rimraf from 'rimraf'
Expand All @@ -19,17 +19,22 @@ const verifyImgElements = (imgFilesArr, imgElements) => {
return false
}

const mwUrl = 'https://en.wikipedia.org'
const articleList = 'BMW'
const format = ''
const parameters = {
mwUrl: 'https://en.wikipedia.org',
articleList: 'BMW',
adminEmail: 'test@kiwix.org',
}

await testAllRenders(mwUrl, articleList, format, async (outFiles) => {
const articleFromDump = await zimdump(`show --url A/${articleList} ${outFiles[0].outFile}`)
await testAllRenders(parameters, async (outFiles) => {
const articleFromDump = await zimdump(`show --url A/${parameters.articleList} ${outFiles[0].outFile}`)
describe('e2e test for en.wikipedia.org', () => {
const articleDoc = domino.createDocument(articleFromDump)
// 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(`test article header for ${outFiles[0]?.renderer} renderer`, async () => {
expect(articleDoc.querySelector('h1.article-header, h1.pcs-edit-section-title')).toBeTruthy()
})
Expand Down
Loading

0 comments on commit 28adc40

Please sign in to comment.