|
- import fs from 'fs'
- import Converter from '../src'
- import English from '../src/systems/en'
-
- describe.each`
- name | system | scale
- ${'English'} | ${English} | ${'short'}
- ${'English'} | ${English} | ${'long'}
- `('$name ($scale count)', ({ system, scale, }) => {
- let converter: Converter
-
- beforeAll(() => {
- converter = new Converter(system, { scale, })
- })
-
- describe('on values', () => {
- test.each`
- value | name
- ${1000000} | ${'one million'}
- ${123456789} | ${'one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine'}
- `('should parse $value as $name', ({ value, name, }) => {
- expect(converter.convert(value)).toBe(name)
- })
- })
-
- describe('on streams', () => {
- const ENCODING = 'utf-8'
-
- test.each([
- 'million',
- 'example1',
- 'example2',
- 'example3',
- 'example4',
- 'example5',
- 'example6',
- ])('should correctly parse a stream', async (filename) => {
- const inputStream = fs.createReadStream(
- `./tests/input/${filename}.txt`,
- {
- encoding: ENCODING,
- }
- )
- const readStream = converter.readStream({
- encoding: ENCODING
- })
- inputStream
- .pipe(readStream)
- .pipe(fs.createWriteStream(`./tests/output/${filename}.${scale}.txt`))
-
- return new Promise((resolve) => {
- readStream.on('end', () => {
- resolve('Hello')
- })
- })
- })
- })
- })
|