forked from cucumber/gherkin-javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamTest.ts
73 lines (64 loc) · 2.06 KB
/
StreamTest.ts
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
65
66
67
68
69
70
71
72
73
import assert from 'assert'
import { Readable } from 'stream'
import { messages } from '@cucumber/messages'
import Gherkin from '../src/stream/GherkinStreams'
import makeSourceEnvelope from '../src/makeSourceEnvelope'
import { IGherkinOptions, dialects } from '../src'
const defaultOptions: IGherkinOptions = {}
describe('gherkin', () => {
it('parses gherkin from the file system', async () => {
const envelopes = await streamToArray(
Gherkin.fromPaths(['testdata/good/minimal.feature'], defaultOptions)
)
assert.strictEqual(envelopes.length, 3)
})
it('throws an error when the path is a directory', async () => {
assert.rejects(async () =>
streamToArray(Gherkin.fromPaths(['testdata/good'], defaultOptions))
)
})
it('parses gherkin from STDIN', async () => {
const source = makeSourceEnvelope(
`Feature: Minimal
Scenario: minimalistic
Given the minimalism
`,
'test.feature'
)
const envelopes = await streamToArray(
Gherkin.fromSources([source], defaultOptions)
)
assert.strictEqual(envelopes.length, 3)
})
it('parses gherkin using the provided default language', async () => {
const source = makeSourceEnvelope(
`Fonctionnalité: i18n support
Scénario: Support des caractères spéciaux
Soit un exemple de scénario en français
`,
'test.feature'
)
const envelopes = await streamToArray(
Gherkin.fromSources([source], { defaultDialect: 'fr' })
)
assert.strictEqual(envelopes.length, 3)
})
it('outputs dialects', async () => {
assert.strictEqual(dialects.en.name, 'English')
})
})
async function streamToArray(
readableStream: Readable
): Promise<messages.IEnvelope[]> {
return new Promise<messages.IEnvelope[]>(
(
resolve: (wrappers: messages.IEnvelope[]) => void,
reject: (err: Error) => void
) => {
const items: messages.IEnvelope[] = []
readableStream.on('data', items.push.bind(items))
readableStream.on('error', (err: Error) => reject(err))
readableStream.on('end', () => resolve(items))
}
)
}