-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
file_steps.ts
57 lines (52 loc) · 1.58 KB
/
file_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
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
import { Given, Then } from '../../'
import { expect } from 'chai'
import { normalizeText } from '../support/helpers'
import fs from 'mz/fs'
import fsExtra from 'fs-extra'
import path from 'path'
import Mustache from 'mustache'
import { World } from '../support/world'
Given(/^a file named "(.*)" with:$/, async function(
this: World,
filePath: string,
fileContent: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
if (filePath === '@rerun.txt') {
fileContent = fileContent.replace(/\//g, path.sep)
}
await fsExtra.outputFile(absoluteFilePath, fileContent)
})
Given(/^an empty file named "(.*)"$/, async function(
this: World,
filePath: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
await fsExtra.outputFile(absoluteFilePath, '')
})
Given(/^a directory named "(.*)"$/, async function(
this: World,
filePath: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
await fsExtra.mkdirp(absoluteFilePath)
})
Given(/^"([^"]*)" is an absolute path$/, function(
this: World,
filePath: string
) {
filePath = Mustache.render(filePath, this)
expect(path.isAbsolute(filePath)).to.eql(true)
})
Then(/^the file "([^"]*)" has the text:$/, async function(
this: World,
filePath: string,
text: string
) {
filePath = Mustache.render(filePath, this)
const absoluteFilePath = path.resolve(this.tmpDir, filePath)
const content = await fs.readFile(absoluteFilePath, 'utf8')
const actualContent = normalizeText(content)
const expectedContent = normalizeText(text)
expect(actualContent).to.eql(expectedContent)
})