-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathe2e.js
54 lines (49 loc) · 1.33 KB
/
e2e.js
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
const execa = require('execa')
const snapshot = require('snap-shot-it')
const chalk = require('chalk')
const termToHtml = require('.')
/**
* Replace Mocha's time duration warnings with same value
* @param {string} s output from Mocha converted to HTML
* @returns {string} sanitized result
*/
const sanitize = s => {
const duration1xxx = /\(10\d\dms\)/g
const duration9xx = /\(9\d\dms\)/g
const value = '(1000ms)'
return s.replace(duration1xxx, value).replace(duration9xx, value)
}
it('works', () => {
return execa('npx mocha spec.js --reporter spec | bin/term-to-html.js', {
shell: true,
env: {
FORCE_COLOR: 2,
},
}).then(result => {
const text = sanitize(result.stdout)
snapshot('generated html', text)
})
})
it('supports dark theme', () => {
return execa(
'npx mocha spec.js --reporter spec | bin/term-to-html.js --theme dark',
{
shell: true,
env: {
FORCE_COLOR: 2,
},
},
).then(result => {
const text = sanitize(result.stdout)
snapshot('html with dark theme', text)
})
})
it('can be used as a module', () => {
const ansi =
chalk.red('red') + ' ' + chalk.cyan('cyan') + '\n' + 'second line'
const html = termToHtml.strings(ansi)
snapshot('string to string dark theme', html)
})
it('has themes', () => {
snapshot('themes', termToHtml.themes)
})