-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: drop need for iconv-lite and iterable-to-stream (#1677)
- iterable-to-stream - was replaced with the now built-in method. - iconv-lite - was never really needed since all files are expected to be in `utf-8`. - Bump the minimum version of not to the original LTS version 12.13.0 - cspell-io - remove unused async line reader and other unused async functions. NOTE: This might be a breaking change for any external party that depends upon cspell-io.
- Loading branch information
Showing
21 changed files
with
51 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { toArray } from './asyncIterable'; | ||
|
||
describe('asyncIterable', () => { | ||
test('toArray', async () => { | ||
const r = toArray(emit([1, 2, 3, Promise.resolve(4), 5])); | ||
await expect(r).resolves.toEqual([1, 2, 3, 4, 5]); | ||
}); | ||
}); | ||
|
||
async function* emit<T>(values: Iterable<T | Promise<T>>): AsyncIterableIterator<T> { | ||
for await (const v of values) { | ||
yield v; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,15 @@ | ||
import * as fReader from './fileReader'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { Readable } from 'stream'; | ||
import * as asyncIterable from '../async/asyncIterable'; | ||
|
||
describe('Validate the fileReader', () => { | ||
const samplePath = path.join(__dirname, '..', '..', 'samples'); | ||
const fileCities = path.join(samplePath, 'cities.txt'); | ||
const sampleFiles = ['cities.txt', 'cities.CRLF.txt', 'cities.noEOL.txt'].map((f) => path.join(samplePath, f)); | ||
|
||
test('tests reading a file', async () => { | ||
const expected = await fs.readFile(__filename, 'utf8'); | ||
const result = await fReader.readFile(__filename, 'utf8'); | ||
expect(result).toBe(expected); | ||
}); | ||
|
||
test('tests stringsToLines', async () => { | ||
const strings = stringToStream('a1\n2\n3\n4', '5\n6'); | ||
const a = await asyncIterable.toArray(fReader.streamLineByLineAsync(strings)); | ||
expect(a).toEqual(['a1', '2', '3', '45', '6']); | ||
}); | ||
|
||
test('tests stringsToLines trailing new line', async () => { | ||
const strings = stringToStream('a1\n2\n3\n4', '5\n6\n'); | ||
const a = await asyncIterable.toArray(fReader.streamLineByLineAsync(strings)); | ||
expect(a).toEqual(['a1', '2', '3', '45', '6', '']); | ||
}); | ||
|
||
test('the file reader', async () => { | ||
const lines = await asyncIterable.toArray(fReader.streamFileLineByLineAsync(__filename)); | ||
const actual = lines.join('\n'); | ||
const expected = fs.readFileSync(__filename, 'utf8'); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
test('the lineReaderAsync', async () => { | ||
const lines = await asyncIterable.toArray(fReader.lineReaderAsync(__filename)); | ||
const expected = fs.readFileSync(__filename, 'utf8').split('\n'); | ||
expect(lines).toEqual(expected); | ||
}); | ||
|
||
test('tests reading the cities sample', async () => { | ||
const lines = await asyncIterable.toArray(fReader.lineReaderAsync(fileCities)); | ||
const file = await fs.readFile(fileCities, 'utf8'); | ||
expect(lines).toEqual(file.split('\n')); | ||
}); | ||
|
||
test('tests streamFileLineByLineAsync', async () => { | ||
await Promise.all( | ||
sampleFiles.map(async (filename) => { | ||
const lines = await asyncIterable.toArray(fReader.streamFileLineByLineAsync(filename)); | ||
const file = await fs.readFile(filename, 'utf8'); | ||
// compare to file: ${filename} | ||
expect(lines).toEqual(file.split(/\r?\n/)); | ||
}) | ||
); | ||
}); | ||
|
||
test('tests streamFileLineByLineAsync 2', async () => { | ||
const lines = await asyncIterable.toArray(fReader.streamFileLineByLineAsync(__filename)); | ||
const file = await fs.readFile(__filename, 'utf8'); | ||
expect(lines).toEqual(file.split('\n')); | ||
}); | ||
|
||
test('missing file', async () => { | ||
const result = asyncIterable.toArray(fReader.lineReaderAsync(__filename + 'not.found')); | ||
return result.then( | ||
() => { | ||
expect('not to be here').toBe(true); | ||
return; | ||
}, | ||
(e) => { | ||
// expect(e).to.be.instanceof(Error); // Since jest currently mocks Error, this test fails. | ||
expect(e.code).toBe('ENOENT'); | ||
} | ||
); | ||
const result = fReader.readFile(__filename + '.missing.file', 'utf8'); | ||
await expect(result).rejects.toEqual(expect.objectContaining({ code: 'ENOENT' })); | ||
}); | ||
}); | ||
|
||
function stringToStream(...strings: string[]): NodeJS.ReadableStream { | ||
return new Readable({ | ||
read: function () { | ||
for (const s of strings) { | ||
this.push(s); | ||
} | ||
this.push(null); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as index from './index'; | ||
|
||
describe('index', () => { | ||
test('exports', () => { | ||
expect(index.readFile).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.