-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcck_spec.ts
94 lines (89 loc) · 2.96 KB
/
cck_spec.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import fs from 'node:fs'
import path from 'node:path'
import { PassThrough, pipeline, Writable } from 'node:stream'
import util from 'node:util'
import { describe, it } from 'mocha'
import { config, expect, use } from 'chai'
import chaiExclude from 'chai-exclude'
import { glob } from 'glob'
import * as messages from '@cucumber/messages'
import * as messageStreams from '@cucumber/message-streams'
import { Envelope } from '@cucumber/messages'
import { ignorableKeys } from '../features/support/formatter_output_helpers'
import { runCucumber, IRunConfiguration } from '../src/api'
const asyncPipeline = util.promisify(pipeline)
const PROJECT_PATH = path.join(__dirname, '..')
const CCK_FEATURES_PATH = 'node_modules/@cucumber/compatibility-kit/features'
const CCK_IMPLEMENTATIONS_PATH = 'compatibility/features'
config.truncateThreshold = 100
use(chaiExclude)
describe('Cucumber Compatibility Kit', () => {
const ndjsonFiles = glob.sync(`${CCK_FEATURES_PATH}/**/*.ndjson`)
ndjsonFiles.forEach((fixturePath) => {
const match = /^.+[/\\](.+)(\.feature(?:\.md)?)\.ndjson$/.exec(fixturePath)
const suiteName = match[1]
const extension = match[2]
it(`passes the cck suite for '${suiteName}'`, async () => {
const actualMessages: Envelope[] = []
const stdout = new PassThrough()
const stderr = new PassThrough()
const runConfiguration: IRunConfiguration = {
sources: {
defaultDialect: 'en',
paths: [`${CCK_FEATURES_PATH}/${suiteName}/${suiteName}${extension}`],
names: [],
tagExpression: '',
order: 'defined',
},
support: {
requireModules: ['ts-node/register'],
requirePaths: [
`${CCK_IMPLEMENTATIONS_PATH}/${suiteName}/${suiteName}.ts`,
],
},
runtime: {
dryRun: false,
failFast: false,
filterStacktraces: true,
parallel: 0,
retry: suiteName === 'retry' ? 2 : 0,
retryTagFilter: '',
strict: true,
worldParameters: {},
},
formats: {
stdout: 'summary',
files: {},
options: {},
publish: false,
},
}
await runCucumber(
runConfiguration,
{
cwd: PROJECT_PATH,
stdout,
stderr,
},
(message) => actualMessages.push(JSON.parse(JSON.stringify(message)))
)
stdout.end()
stderr.end()
const expectedMessages: messages.Envelope[] = []
await asyncPipeline(
fs.createReadStream(fixturePath, { encoding: 'utf-8' }),
new messageStreams.NdjsonToMessageStream(),
new Writable({
objectMode: true,
write(envelope: messages.Envelope, _: BufferEncoding, callback) {
expectedMessages.push(envelope)
callback()
},
})
)
expect(actualMessages)
.excludingEvery(ignorableKeys)
.to.deep.eq(expectedMessages)
})
})
})