-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
64 lines (56 loc) · 1.59 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import baretest from 'baretest'
import { strictEqual } from 'assert'
import replace from './index.js'
import { Readable } from 'stream'
import streamToString from 'stream-to-string'
const test = baretest('Tests')
test('no change', async () => {
strictEqual(await streamToString(Readable.from([
'paper\n',
'pajamas\n',
'socks\n'
]).pipe(replace('pinapple', 'apple'))), 'paper\npajamas\nsocks\n')
})
test('chunk boundary', async () => {
strictEqual(await streamToString(Readable.from([
'pap',
'aper',
'socks'
]).pipe(replace('paper', 'stuff that we write on'))), 'pastuff that we write onsocks')
})
test('within chunk boundary', async () => {
strictEqual(await streamToString(Readable.from([
'red\n',
'grey\n',
'orange\n'
]).pipe(replace('grey', 'gray'))), 'red\ngray\norange\n')
})
test('split over multiple chunks', async () => {
strictEqual(await streamToString(Readable.from([
'|a',
'pp',
'le|'
]).pipe(replace('apple', 'mela'))), '|mela|')
})
test('split over multiple chunks 2', async () => {
strictEqual(await streamToString(Readable.from([
'|apple a',
'pp',
'le|'
]).pipe(replace('apple', 'mela'))), '|mela mela|')
})
test('mystery bug #6', async () => {
strictEqual(await streamToString(Readable.from([
'One two one\n',
'One two one\n',
'One two one two\n',
'One two one two\n'
]).pipe(replace('two', 'three'))), [
'One three one\n',
'One three one\n',
'One three one three\n',
'One three one three\n'
].join(''))
})
const allTestsPassed = await test.run()
if (!allTestsPassed) process.exitCode = 1