|
- 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)
- })
-
- 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, { scale })).toBe(name)
- })
- })
-
- describe('on streams', () => {
- const ENCODING = 'utf-8'
-
- test.each([
- 'million.txt'
- ])('should correctly parse a stream', async (filename) => {
- const inputStream = fs.createReadStream(
- `./tests/input/${filename}`,
- {
- encoding: ENCODING,
- highWaterMark: 3, // this is required to parse kilos correctly
- }
- )
- const readStream = converter.readStream({
- scale,
- encoding: ENCODING
- })
- inputStream
- .pipe(readStream)
- .pipe(fs.createWriteStream(`./tests/output/${filename}`))
-
- return new Promise((resolve) => {
- readStream.on('end', () => {
- resolve('Hello')
- })
- })
- })
- })
- })
|