blob: fef611796adef32753f2e6ba14d2946f685c1e2b [file] [log] [blame]
Tim van der Lippe652ccb72021-05-27 17:07:12 +01001'use strict'
2
3const rollup = require('rollup').rollup
4const minifyHTML = require('..')
5const expect = require('chai').expect
6const path = require('path')
7const fs = require('fs')
8
9process.chdir(__dirname)
10
11const concat = (name, subdir) => {
12 let filePath = path.join(__dirname, subdir, name)
13 filePath = filePath.replace(/\\/g, '/')
14 if (!path.extname(filePath)) filePath += '.js'
15 return filePath
16}
17
18const test = (done, file, pluginOpts = {}) => {
19 const filePath = concat(file, 'fixtures')
20 const expected = fs.readFileSync(concat(file, 'expected'), 'utf8')
21 ;(async () => {
22 try {
23 const bundle = await rollup({
24 input: filePath,
25 plugins: [minifyHTML(pluginOpts)]
26 })
27 const output = await bundle.generate({ format: 'es' })
28 const code = output.output[0].code
29 expect(code).to.equal(expected)
30 done()
31 } catch (err) {
32 done(err)
33 }
34 })()
35}
36
37describe('rollup-plugin-minify-html-template-literals', () => {
38 it('works for me', done => {
39 test(done, 'default')
40 })
41 it('excludes what i hate', done => {
42 test(done, 'filter', { exclude: 'fixtures/exclude.js' })
43 })
44})