-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
fixture_steps.ts
30 lines (29 loc) · 1.03 KB
/
fixture_steps.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
import { Then } from '../../'
import { expect } from 'chai'
import {
normalizeMessageOutput,
normalizeJsonOutput,
} from '../support/formatter_output_helpers'
import fs from 'mz/fs'
import path from 'path'
import { messages } from 'cucumber-messages'
import Envelope = messages.Envelope
Then(
'the {string} formatter output matches the fixture {string}',
async function(formatter: string, filePath: string) {
let actual: any
if (formatter === 'message') {
actual = this.lastRun.envelopes.map((e: Envelope) => e.toJSON())
actual = normalizeMessageOutput(actual, this.tmpDir)
} else {
const actualPath = path.join(this.tmpDir, `${formatter}.out`)
actual = await fs.readFile(actualPath, 'utf8')
if (formatter === 'json') {
actual = normalizeJsonOutput(actual, this.tmpDir)
}
}
const fixturePath = path.join(__dirname, '..', 'fixtures', filePath)
const expected = require(fixturePath) // eslint-disable-line @typescript-eslint/no-var-requires
expect(actual).to.eql(expected)
}
)