import { afterAll, describe, it } from 'vitest'; import { createReadStream, createWriteStream } from 'fs'; import { unlink } from 'fs/promises'; import { createDownloader, createXmlToJsonLines, JMdict } from '../../src'; const DOWNLOAD_FILENAME = 'jmdict.xml' as const; const PROCESS_OUTPUT_FILENAME = 'jmdict.jsonl' as const; // FIXME use tests that do not download the source data describe.skip('jmdict', () => { afterAll(async () => { try { await unlink(DOWNLOAD_FILENAME); } catch { // noop } }); afterAll(async () => { try { await unlink(PROCESS_OUTPUT_FILENAME); } catch { // noop } }); describe('downloader', () => { it('downloads the source data', async () => { const readStream = await createDownloader({ type: JMdict.SOURCE_ID, }); return new Promise((resolve, reject) => { const out = createWriteStream(DOWNLOAD_FILENAME); readStream.on('error', (err) => { reject(err); }); out.on('error', (err) => { reject(err); }); out.on('finish', () => { resolve(); }); readStream.pipe(out); }); }, { timeout: 30000 }); }); describe('converter', () => { it('converts XML to JSON', () => new Promise((resolve, reject) => { const readStream = createReadStream(DOWNLOAD_FILENAME, { encoding: 'utf-8' }); readStream.on('error', (err) => { reject(err); }); const transform = createXmlToJsonLines({ entryTagName: 'entry', }); transform.on('error', (err) => { reject(err); }); const out = createWriteStream(PROCESS_OUTPUT_FILENAME); out.on('error', (err) => { reject(err); }); out.on('finish', () => { resolve(); }); readStream .pipe(transform) .pipe(out); }), { timeout: 30000 }); }); });