Skip to content

Commit

Permalink
test: resolve local plugin, issue #336, #338
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Jun 11, 2021
1 parent 8307ed3 commit 2a0cb7d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/plugins/custom-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function (options) {
return function (tree) {
return tree;
};
}
13 changes: 13 additions & 0 deletions test/test-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ test('Transform html from two file', async t => {
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
});

test('Dont not transform html with local plugin', async t => {
const filename = tempfile('.html');
await execa(cli, [
'test/fixtures/input.html',
'-o',
filename,
'-u',
'test/plugins/custom-plugin.js',
]);
t.true(await pathExists(filename));
t.is((await read('test/fixtures/input.html')), (await read(filename)));
});

// test('Transform html with options replace', async t => {
// t.plan(2);
// const folder = await tempfile();
Expand Down
19 changes: 19 additions & 0 deletions test/test-plugin-resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import path from 'path';
import test from 'ava';
import pluginResolve from '../src/plugin-resolve';

test('should return function', t => {
t.true(typeof pluginResolve === 'function');
});

test('should return node_modules module path', t => {
const pluginName = 'posthtml-custom-elements';
const pluginPath = pluginResolve(pluginName);
t.is(pluginPath, pluginName);
});

test('should return custom module path', t => {
const pluginName = 'test/plugins/custom-plugin.js';
const pluginPath = pluginResolve(pluginName);
t.is(pluginPath, path.resolve(path.join('./', pluginName)));
});

0 comments on commit 2a0cb7d

Please sign in to comment.