|
| 1 | +import * as mwoffliner from '../../src/mwoffliner.lib.js' |
| 2 | +import { execa } from 'execa' |
| 3 | +import rimraf from 'rimraf' |
| 4 | +import { zimcheckAvailable, zimcheck, zimdumpAvailable, zimdump } from '../util.js' |
| 5 | +import 'dotenv/config' |
| 6 | +import { jest } from '@jest/globals' |
| 7 | + |
| 8 | +jest.setTimeout(20000) |
| 9 | + |
| 10 | +describe('Multimedia', () => { |
| 11 | + const now = new Date() |
| 12 | + const testId = `mwo-test-${+now}` |
| 13 | + |
| 14 | + const parameters = { |
| 15 | + mwUrl: 'https://en.m.wikipedia.org', |
| 16 | + |
| 17 | + articleList: 'User:Kelson/MWoffliner_CI_reference', |
| 18 | + outputDirectory: testId, |
| 19 | + redis: process.env.REDIS, |
| 20 | + customZimDescription: 'Example of the description', |
| 21 | + } |
| 22 | + |
| 23 | + test('check multimedia content from wikipedia test page', async () => { |
| 24 | + await execa('redis-cli flushall', { shell: true }) |
| 25 | + |
| 26 | + const [dump] = await mwoffliner.execute(parameters) |
| 27 | + |
| 28 | + expect(dump.status.articles.success).toEqual(1) |
| 29 | + expect(dump.status.articles.fail).toEqual(0) |
| 30 | + |
| 31 | + if (await zimcheckAvailable()) { |
| 32 | + await expect(zimcheck(dump.outFile)).resolves.not.toThrowError() |
| 33 | + } else { |
| 34 | + console.log('Zimcheck not installed, skipping test') |
| 35 | + } |
| 36 | + |
| 37 | + if (await zimdumpAvailable()) { |
| 38 | + const mediaFiles = await zimdump(`list --ns I ${dump.outFile}`) |
| 39 | + |
| 40 | + expect(mediaFiles.split('\n').sort()).toEqual( |
| 41 | + [ |
| 42 | + 'I/Kiwix_-_WikiArabia_Cairo_2017.pdf', |
| 43 | + 'I/Kiwix_Hackathon_2017_Florence_WikiFundi.webm.120p.vp9.webm', |
| 44 | + 'I/Kiwix_Hackathon_2017_Florence_WikiFundi.webm.jpg', |
| 45 | + 'I/Kiwix_icon.svg.png', |
| 46 | + 'I/Local_Forecast_-_Elevator_(ISRC_USUAN1300012).mp3.ogg', |
| 47 | + 'I/page1-120px-Kiwix_-_WikiArabia_Cairo_2017.pdf.jpg', |
| 48 | + 'I/page1-1500px-Kiwix_-_WikiArabia_Cairo_2017.pdf.jpg', |
| 49 | + ].sort(), |
| 50 | + ) |
| 51 | + } else { |
| 52 | + console.log('Zimcheck not installed, skipping test') |
| 53 | + } |
| 54 | + |
| 55 | + rimraf.sync(`./${testId}`) |
| 56 | + const redisScan = await execa('redis-cli --scan', { shell: true }) |
| 57 | + // Redis has been cleared |
| 58 | + expect(redisScan.stdout).toEqual('') |
| 59 | + }) |
| 60 | +}) |
0 commit comments