-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
file_steps.ts
73 lines (66 loc) · 2.26 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Given, Then } from '../../'
import { expect } from 'chai'
import hasAnsi from 'has-ansi'
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 {string} 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 {string}',
async function (this: World, filePath: string) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
await fsExtra.outputFile(absoluteFilePath, '')
}
)
Given(
'a directory named {string}',
async function (this: World, filePath: string) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
await fsExtra.mkdirp(absoluteFilePath)
}
)
Given('{string} is an absolute path', function (this: World, filePath: string) {
filePath = Mustache.render(filePath, this)
expect(path.isAbsolute(filePath)).to.eql(true)
})
Then(
'the file {string} 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)
}
)
Then(
'the file {string} contains colors',
async function (this: World, filePath: string) {
filePath = Mustache.render(filePath, this)
const absoluteFilePath = path.resolve(this.tmpDir, filePath)
const content = await fs.readFile(absoluteFilePath, 'utf8')
expect(hasAnsi(content)).to.be.true
}
)
Then(
"the file {string} doesn't contain colors",
async function (this: World, filePath: string) {
filePath = Mustache.render(filePath, this)
const absoluteFilePath = path.resolve(this.tmpDir, filePath)
const content = await fs.readFile(absoluteFilePath, 'utf8')
expect(hasAnsi(content)).to.be.false
}
)