UNPKG

1.91 kBJavaScriptView Raw
1var dedent = require('dedent')
2var path = require('path')
3var tape = require('tape')
4var tmp = require('tmp')
5var fs = require('fs')
6
7var bankai = require('../')
8
9tape('extract style from script', function (assert) {
10 assert.plan(3)
11 var expected = '.foo{color:#00f}'
12 var script = dedent`
13 var css = require('sheetify')
14 var html = require('bel')
15 css\`
16 .foo { color: blue }
17 \`
18 html\`<foo class="foo">hello</foo>\`
19 `
20
21 var tmpDir = tmp.dirSync({ dir: path.join(__dirname, '../tmp'), unsafeCleanup: true })
22 assert.on('end', tmpDir.removeCallback)
23 var tmpScriptname = path.join(tmpDir.name, 'index.js')
24
25 fs.writeFileSync(tmpScriptname, script)
26
27 var compiler = bankai(tmpScriptname, { watch: false })
28 compiler.styles('bundle.css', function (err, res) {
29 assert.error(err, 'no error writing style')
30 assert.equal(res.buffer.toString(), expected, 'res was equal')
31 })
32
33 compiler.scripts('bundle.js', function (err, res) {
34 assert.error(err, 'no error writing script')
35 })
36})
37
38tape('remove unused styles', function (assert) {
39 assert.plan(3)
40 var expected = '.foo{color:#00f}'
41 var script = dedent`
42 var css = require('sheetify')
43 var html = require('bel')
44 css\`
45 .foo { color: blue }
46 .bar { color: purple }
47 \`
48 html\`<foo class="foo">hello</foo>\`
49 `
50
51 var tmpDir = tmp.dirSync({ dir: path.join(__dirname, '../tmp'), unsafeCleanup: true })
52 assert.on('end', tmpDir.removeCallback)
53 var tmpScriptname = path.join(tmpDir.name, 'index.js')
54
55 fs.writeFileSync(tmpScriptname, script)
56
57 var compiler = bankai(tmpScriptname, { watch: false })
58 compiler.styles('bundle.css', function (err, res) {
59 assert.error(err, 'no error writing style')
60 assert.equal(res.buffer.toString(), expected, 'res was equal')
61 })
62
63 compiler.scripts('bundle.js', function (err, res) {
64 assert.error(err, 'no error writing script')
65 })
66})