rollup-plugin-posthtml-template
Version:
Seamless integration between Rollup and PostHTML.
62 lines (46 loc) • 2.16 kB
JavaScript
import { join } from 'path';
import { rollup } from 'rollup';
import posthtml from '../src';
import sugarml from 'posthtml-sugarml';
import include from 'posthtml-include';
process.chdir(__dirname);
const bundler = (input, options = {}) => rollup({ input, plugins: [posthtml(options)] });
describe('rollup-plugin-posthtml', () => {
it('should import html from file as string', async () => {
const { generate } = await bundler('fixtures/basic/main.js');
const { code } = await generate({ format: 'iife', name: 'posthtml' });
expect(code).toBeDefined();
expect(code).toMatch(/<p>Foo<\/p>/);
});
it('should output empty sourcemap', async () => {
const { generate } = await bundler('fixtures/basic/main.js');
const { map } = await generate({ format: 'es', sourcemap: true });
expect(map).toBeDefined();
expect(map.file).toBe('main.js');
});
it('should be able to use the plugins option', async () => {
const { generate } = await bundler('fixtures/plugins/main.js', { plugins: [include()] });
const { code } = await generate({ format: 'iife', name: 'posthtml' });
expect(code).toBeDefined();
expect(code).toMatch(/<p>Foo<\/p>/);
expect(code).toMatch(/<p>Bar<\/p>/);
});
it('should be able to use the template option', async () => {
const { generate } = await bundler('fixtures/template/main.js', { template: true });
const { code } = await generate({ format: 'iife', name: 'posthtml' });
expect(code).toBeDefined();
expect(code).toMatch(/<p>\${ _.text }<\/p>/);
});
it('should be able to use the parser option', async () => {
const { generate } = await bundler('fixtures/parser/main.js', { parser: sugarml() });
const { code } = await generate({ format: 'iife', name: 'posthtml' });
expect(code).toBeDefined();
expect(code).toMatch(/<p>Foo<\/p>/);
});
// it('should be able to use the directives option', async () => {
// const { generate } = await bundler('fixtures/directives/main.js', { directives: '' });
// const { code } = await generate({ format: 'iife', name: 'posthtml' });
//
// expect(code).toBeDefined();
// });
});