Tim van der Lippe | 652ccb7 | 2021-05-27 17:07:12 +0100 | [diff] [blame^] | 1 | 'use strict' |
| 2 | |
| 3 | const rollup = require('rollup').rollup |
| 4 | const minifyHTML = require('..') |
| 5 | const expect = require('chai').expect |
| 6 | const path = require('path') |
| 7 | const fs = require('fs') |
| 8 | |
| 9 | process.chdir(__dirname) |
| 10 | |
| 11 | const 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 | |
| 18 | const 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 | |
| 37 | describe('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 | }) |