import { describe, it, afterAll } from 'vitest'; import { createReadStream, createWriteStream } from 'fs'; import { unlink } from 'fs/promises'; import { createDownloader, createXmlToJsonLines, Kanjidic } from '../../src'; const DOWNLOAD_FILENAME = 'kanjidic2.xml' as const; const PROCESS_OUTPUT_FILENAME = 'kanjidic2.jsonl' as const; // FIXME use tests that do not download the source data describe.skip('kanjidic', () => { 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: Kanjidic.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); }); }); }); 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: 'character', }); 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); })); }); });