-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
102 lines (90 loc) · 3.12 KB
/
index.test.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
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
95
96
97
98
99
100
101
import fs from 'fs'
import chalk from 'chalk'
import test from 'ava'
import ansiParse from '.'
const fixtures = {
chalkStylesAnsi: fs.readFileSync('./fixtures/fixture.chalk-styles.ansi').toString()
}
test('cover all chalk styles', t => {
const parsed = ansiParse(fixtures.chalkStylesAnsi).chunks
const actual = JSON.stringify(parsed, null, 2)
const expectFile = `./fixtures/fixture.chalk-styles.ansi.expected.utf8`
// // Save expected:
// fs.writeFileSync(expectFile, actual)
const expected = fs.readFileSync(expectFile).toString()
t.deepEqual(actual, expected)
})
test('gets opening red ansi escape char', t => {
const text = chalk.red('_')
const parsed = ansiParse(text)
const firstAnsi = parsed.chunks[0].value.ansi
t.is(firstAnsi, '\u001B[31m')
})
test('parses colors', t => {
const text = chalk`Your {red wish} is\n {bgYellow my} command.`
const parsed = ansiParse(text).chunks
const actual = JSON.stringify(parsed, null, 2)
const expectFile = `./fixtures/fixture.your-wish-is-my-command.expected.json`
// // Save expected:
// fs.writeFileSync(expectFile, actual)
const expected = fs.readFileSync(expectFile).toString()
t.deepEqual(actual, expected)
})
test('resets styles', t => {
const text = chalk`{red RED}\n{bgGreen GREEN}`
const parsed = ansiParse(text).chunks
const actual = JSON.stringify(parsed, null, 2)
const expectFile = `./fixtures/fixture.reset-styles.expected.json`
// // Save expected:
// fs.writeFileSync(expectFile, actual)
const expected = fs.readFileSync(expectFile).toString()
t.deepEqual(actual, expected)
})
test('parses robot face as string', t => {
const text = '🤖\u001B[31m DANGER\u001B[0m Will Robbinson'
const parsed = ansiParse(text).chunks
const actual = JSON.stringify(parsed, null, 2)
const expectFile = `./fixtures/fixture.robot-face-as-string.expected.json`
// // Save expected:
// fs.writeFileSync(expectFile, actual)
const expected = fs.readFileSync(expectFile).toString()
t.deepEqual(actual, expected)
})
test('reset bold', t => {
const text = `\u001B[1m BOLD\u001B[0m NORMAL`
const parsed = ansiParse(text)
t.deepEqual(parsed.chunks[3].style, {})
})
test('open/close the rainbow', t => {
const text = chalk.red('red ') +
chalk.yellow('yellow ') +
chalk.green('green ') +
chalk.cyan('cyan ') +
chalk.blue('blue ') +
chalk.magenta('magenta')
const parsed = ansiParse(text).chunks
const actual = JSON.stringify(parsed, null, 2)
const expectFile = `./fixtures/fixture.open-close-rainbow.expected.json`
// // Save expected:
// fs.writeFileSync(expectFile, actual)
const expected = fs.readFileSync(expectFile).toString()
t.deepEqual(actual, expected)
})
test('meassures text area', t => {
const x2x3 = '012\n345\n678'
const parsed = ansiParse(x2x3)
t.deepEqual(parsed.textArea, {
columns: 3,
rows: 3
})
})
test('gets raw ansi', t => {
const text = '🤖\u001B[31m DANGER\u001B[0m Will Robbinson'
const parsed = ansiParse(text)
t.is(parsed.raw, '🤖\u001B[31m DANGER\u001B[0m Will Robbinson')
})
test('gets plaintext', t => {
const text = '🤖\u001B[31m DANGER\u001B[0m Will Robbinson'
const parsed = ansiParse(text)
t.is(parsed.plainText, '🤖 DANGER Will Robbinson')
})