-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
324141b
commit 4420c39
Showing
1 changed file
with
67 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
@@ -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('') | ||
} | ||
} | ||
}) | ||
}) |