Skip to content

Commit d8cacf8

Browse files
author
Ivan Demidov
committed
Fixed #4, write tests
1 parent 8d7bac8 commit d8cacf8

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

test/expected/output-config-file.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<span class="mycomponent"><span class="mytitle">Super Title</span><span class="mytext">Awesome Text</span></span>

test/expected/output-config-pkg.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mycomponent"><div class="mytitle">Super Title</div><div class="mytext">Awesome Text</div></div>

test/fixtures/config.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": ["posthtml-custom-elements"],
3+
"posthtml-custom-elements": {
4+
"defaultTag": "span"
5+
}
6+
}

test/fixtures/input.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<myComponent><myTitle>Super Title</myTitle><myText>Awesome Text</myText></myComponent>

test/test-cli.js

+58-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
1-
var test = require('ava');
2-
var execa = require('execa');
1+
const test = require('ava');
2+
const execa = require('execa');
3+
const tempWrite = require('temp-write');
4+
const pathExists = require('path-exists');
5+
const path = require('path');
6+
const readPkg = require('read-pkg');
7+
const readFile = require('fs').readFile;
38

4-
test('Missing required arguments', t => {
5-
t.throws(execa('../cli.js'));
9+
test('Missing required arguments -i, -o', t => {
10+
t.throws(execa('../cli.js', []));
11+
});
12+
13+
test('Missing required arguments -o', t => {
14+
t.throws(execa('../cli.js', ['-i', 'fixtures/input.html']));
15+
});
16+
17+
test('Missing required arguments -i', t => {
18+
const filename = tempWrite.sync('output.html');
19+
t.throws(execa('../cli.js', [`-o ${filename}`]));
20+
});
21+
22+
test('Check version', async t => {
23+
t.is((await execa('../cli.js', ['-v'])).stdout, (await readPkg(path.dirname(__dirname))).version);
24+
});
25+
26+
test('Transform html witch config in package.json', async t => {
27+
t.plan(2);
28+
function read(path) {
29+
return new Promise((resolve, reject) => {
30+
readFile(path, 'utf8', (err, data) => {
31+
if (err) {
32+
reject(err);
33+
}
34+
return resolve(data);
35+
});
36+
});
37+
}
38+
const filename = await tempWrite('output.html');
39+
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename]);
40+
t.true(await pathExists(filename));
41+
t.is((await read('expected/output-config-pkg.html')), (await read(filename)));
42+
});
43+
44+
test('Transform html witch config in file', async t => {
45+
t.plan(2);
46+
function read(path) {
47+
return new Promise((resolve, reject) => {
48+
readFile(path, 'utf8', (err, data) => {
49+
if (err) {
50+
reject(err);
51+
}
52+
return resolve(data);
53+
});
54+
});
55+
}
56+
const filename = await tempWrite('output.html');
57+
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']);
58+
t.true(await pathExists(filename));
59+
t.is((await read('expected/output-config-file.html')), (await read(filename)));
660
});

0 commit comments

Comments
 (0)