Skip to content

Commit d2444df

Browse files
author
Ivan Demidov
committed
Update tests for read/write folder and replace
1 parent fbee998 commit d2444df

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

test/test-cli.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const execa = require('execa');
33
const tempWrite = require('temp-write');
44
const pathExists = require('path-exists');
55
const path = require('path');
6+
const del = require('del');
67
const readPkg = require('read-pkg');
8+
const copy = require('cpy');
79
const readFile = require('fs').readFile;
810

9-
function read(path) {
11+
function read(pathFile) {
1012
return new Promise((resolve, reject) => {
11-
readFile(path, 'utf8', (err, data) => {
13+
readFile(pathFile, 'utf8', (err, data) => {
1214
if (err) {
1315
reject(err);
1416
}
@@ -30,30 +32,52 @@ test('Missing required arguments -i', t => {
3032
t.throws(execa('../cli.js', [`-o ${filename}`]));
3133
});
3234

35+
test('One of the arguments', t => {
36+
const filename = tempWrite.sync('output.html');
37+
t.throws(execa('../cli.js', ['-o', filename, '-r', '-i', 'fixtures/input.html']));
38+
});
39+
3340
test('Check version', async t => {
3441
t.is((await execa('../cli.js', ['-v'])).stdout, (await readPkg(path.dirname(__dirname))).version);
3542
});
3643

3744
test('Transform html witch config in package.json', async t => {
3845
t.plan(2);
39-
const filename = await tempWrite('output.html');
46+
const filename = await tempWrite('output.html', 'output.html');
4047
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename]);
4148
t.true(await pathExists(filename));
4249
t.is((await read('expected/output-config-pkg.html')), (await read(filename)));
4350
});
4451

4552
test('Transform html witch indent', async t => {
4653
t.plan(2);
47-
const filename = await tempWrite('output.html');
54+
const filename = await tempWrite('output.html', 'output.html');
4855
await execa('../cli.js', ['-i', 'fixtures/input-indent.html', '-o', filename]);
4956
t.true(await pathExists(filename));
5057
t.is((await read('expected/output-indent.html')), (await read(filename)));
5158
});
5259

5360
test('Transform html witch config in file', async t => {
5461
t.plan(2);
55-
const filename = await tempWrite('output.html');
62+
const filename = await tempWrite('output.html', 'output.html');
5663
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']);
5764
t.true(await pathExists(filename));
5865
t.is((await read('expected/output-config-file.html')), (await read(filename)));
5966
});
67+
68+
test('Transform html from folder', async t => {
69+
t.plan(2);
70+
await execa('../cli.js', ['-i', 'fixtures/*.html', '-o', 'tmpDefault/']);
71+
t.is((await read('expected/output-config-pkg.html')), (await read('tmpDefault/input.html')));
72+
t.is((await read('expected/output-indent.html')), (await read('tmpDefault/input-indent.html')));
73+
del('tmpDefault/');
74+
});
75+
76+
test('Transform html witch options replace', async t => {
77+
t.plan(2);
78+
await copy(['fixtures/*.html'], 'tmpReplace/');
79+
await execa('../cli.js', ['-i', 'tmpReplace/*.html', '-r']);
80+
t.is((await read('expected/output-config-pkg.html')), (await read('tmpReplace/input.html')));
81+
t.is((await read('expected/output-indent.html')), (await read('tmpReplace/input-indent.html')));
82+
del('tmpReplace/');
83+
});

0 commit comments

Comments
 (0)