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