|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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<void>((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<void>((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);
- }));
- });
- });
|