UNPKG

3.27 kBJavaScriptView Raw
1var cpExec = require('child_process').exec
2var path = require('path')
3
4var test = require('tape')
5
6var cssFile = path.join(__dirname, '/cases/gradient.css')
7var pathToCli = ' node ' + path.join(__dirname, '../cli.js')
8var catCss = ' cat ' + cssFile + ' | tee /dev/tty '
9
10var expectedCssGradients = '<streaming css input>:8:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n' +
11 '<streaming css input>:12:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n'
12var expectedCssRepeatingGradients = '<streaming css input>:16:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n' +
13 '<streaming css input>:20:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n'
14var expected = expectedCssGradients + expectedCssRepeatingGradients
15
16var commands = {
17 cat: catCss,
18 doiuse: pathToCli + ' --browsers="IE >= 8" '
19}
20
21var expectedWithIgnore = expectedCssRepeatingGradients
22var commandsWithIgnore = {
23 cat: catCss,
24 doiuse: pathToCli + ' --browsers="IE >= 8" --ignore="css-gradients" '
25}
26
27var exec = function (cmd, cb) {
28 console.log(cmd)
29 cpExec(cmd, cb)
30}
31
32test('cli command: piped input', function (t) {
33 exec(commands.cat + ' | ' + commands.doiuse, function (error, stdout, stderr) {
34 t.equal(stdout, expected)
35 t.end(error)
36 })
37})
38
39test('should take filename as input', function (t) {
40 exec(commands.doiuse + cssFile, function (error, stdout, stderr) {
41 t.equal(stdout, expected.replace(/<streaming css input>/g, cssFile))
42 t.end(error)
43 })
44})
45
46test('cli command with ignore: piped input', function (t) {
47 exec(commandsWithIgnore.cat + ' | ' + commandsWithIgnore.doiuse, function (error, stdout, stderr) {
48 t.equal(stdout, expectedWithIgnore)
49 t.end(error)
50 })
51})
52
53test('should take filename as input with ignore', function (t) {
54 exec(commandsWithIgnore.doiuse + cssFile, function (error, stdout, stderr) {
55 t.equal(stdout, expectedWithIgnore.replace(/<streaming css input>/g, cssFile))
56 t.end(error)
57 })
58})
59
60test('--json option should work', function (t) {
61 exec(commands.doiuse + '--json ' + cssFile, function (error, stdout, stderr) {
62 var result = stdout.trim()
63 .split(/\r?\n/)
64 .map(JSON.parse.bind(JSON))
65 .map(function (usage) { return usage.feature })
66 t.deepEqual(result, [
67 'css-gradients',
68 'css-gradients',
69 'css-repeating-gradients',
70 'css-repeating-gradients' ])
71
72 t.end(error)
73 })
74})
75
76test('--list-only should work', function (t) {
77 exec(commands.doiuse + '--list-only', function (error, stdout, stderr) {
78 t.equal(stdout.trim(), '[doiuse] Browsers: IE 8, IE 9, IE 10, IE 11')
79 t.end(error)
80 })
81})
82
83test('-c config file should work as input parameters', function (t) {
84 var configFile = path.join(__dirname, '/fixtures/doiuse.config.json')
85 var overflowWrapCssFile = path.join(__dirname, '/cases/overflow-wrap.css')
86 var expectedOverflowWrapConfig = '<streaming css input>:7:1: CSS3 Overflow-wrap only partially supported by: IE (11) (wordwrap)\n'
87
88 exec(commands.doiuse + '-c ' + configFile + ' ' + overflowWrapCssFile, function (error, stdout, stderr) {
89 t.equal(stdout, expectedOverflowWrapConfig.replace(/<streaming css input>/g, overflowWrapCssFile))
90 t.end(error)
91 })
92})