Skip to content

Commit 0bb76e4

Browse files
committed
test: for config io, #280, #256
1 parent e3222b8 commit 0bb76e4

File tree

12 files changed

+171
-24
lines changed

12 files changed

+171
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>input-1</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>

test/test-cfg-resolve.js

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import test from 'ava';
2-
import isPromise from 'is-promise';
32
import cfgResolve from '../lib/cfg-resolve';
43

54
test('should return function', t => {
65
t.true(typeof cfgResolve === 'function');
76
});
87

9-
test('should return promise', t => {
10-
t.true(isPromise(cfgResolve()));
11-
});
12-
138
test('should return config with one use key without property', async t => {
149
const flags = {
1510
use: 'posthtml-bem'
1611
};
17-
const config = await cfgResolve(flags);
18-
const expected = {plugins: {'posthtml-bem': {}}};
12+
const config = await cfgResolve({flags});
13+
const expected = {'posthtml-bem': {}};
1914

20-
t.deepEqual(config, expected);
15+
t.deepEqual(config.plugins, expected);
2116
});
2217

2318
test('should return config with one use key with one property', async t => {
@@ -27,30 +22,30 @@ test('should return config with one use key with one property', async t => {
2722
prefix: '__'
2823
}
2924
};
30-
const config = await cfgResolve(flags);
31-
const expected = {plugins: {'posthtml-bem': {prefix: '__'}}};
25+
const config = await cfgResolve({flags});
26+
const expected = {'posthtml-bem': {prefix: '__'}};
3227

33-
t.deepEqual(config, expected);
28+
t.deepEqual(config.plugins, expected);
3429
});
3530

3631
test('should return config with key config', async t => {
3732
const flags = {
3833
config: 'test/config/.config'
3934
};
40-
const config = await cfgResolve(flags);
41-
const expected = {plugins: {'posthtml-bem': {}}};
35+
const config = await cfgResolve({flags});
36+
const expected = {'posthtml-bem': {}};
4237

43-
t.deepEqual(config, expected);
38+
t.deepEqual(config.plugins, expected);
4439
});
4540

4641
test('should return config with key config and use key', async t => {
4742
const flags = {
4843
use: 'posthtml-assets',
4944
config: 'test/config/.config'
5045
};
51-
const config = await cfgResolve(flags);
52-
const expected = {plugins: {'posthtml-bem': {}, 'posthtml-assets': {}}};
46+
const config = await cfgResolve({flags});
47+
const expected = {'posthtml-bem': {}, 'posthtml-assets': {}};
5348

54-
t.deepEqual(config, expected);
49+
t.deepEqual(config.plugins, expected);
5550
});
5651

test/test-cli.js

+50-6
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ test('Transform html from two file', async t => {
5858
t.plan(2);
5959
const folder = await tempfile();
6060
await execa(cli, ['test/fixtures/input.html', 'test/fixtures/input-indent.html', '-o', folder]);
61-
t.is((await read('test/expected/output-config-pkg.html')), (await read(`${folder}/test/fixtures/input.html`)));
62-
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/test/fixtures/input-indent.html`)));
61+
t.is((await read('test/expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
62+
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
6363
});
6464

6565
test('Transform html witch options replace', async t => {
6666
t.plan(2);
6767
const folder = await tempfile();
68-
await copy(['test/fixtures/input.html', 'test/fixtures/input-indent.html'], folder, {parents: true});
69-
await execa(cli, [`${folder}/test/fixtures/input.html`, `${folder}/test/fixtures/input-indent.html`]);
70-
t.is((await read('test/expected/output-config-pkg.html')), (await read(`${folder}/test/fixtures/input.html`)));
71-
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/test/fixtures/input-indent.html`)));
68+
await copy(['test/fixtures/input.html', 'test/fixtures/input-indent.html'], folder);
69+
await execa(cli, [`${folder}/input.html`, `${folder}/input-indent.html`]);
70+
t.is((await read('test/expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
71+
t.is((await read('test/expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
7272
});
7373

7474
test('Transform html witch config in file and stdin options use', async t => {
@@ -144,3 +144,47 @@ test('Transform html stdin options use witch modules', async t => {
144144
t.true(await pathExists(filename));
145145
t.is((await read('test/expected/output-modules.html')), (await read(filename)));
146146
});
147+
148+
test('Transform html stdin options only config one-io', async t => {
149+
t.plan(2);
150+
await execa(cli, [
151+
'-c',
152+
'test/fixtures/by-config/one-io/config.json'
153+
]);
154+
t.true(await pathExists('test/expected/by-config/one-io/output.html'));
155+
t.is(
156+
(await read('test/expected/by-config/one-io/output.html')),
157+
(await read('test/fixtures/by-config/one-io/input.html'))
158+
);
159+
});
160+
161+
test('Transform html stdin options only config two-io to dir', async t => {
162+
t.plan(4);
163+
await execa(cli, [
164+
'-c',
165+
'test/fixtures/by-config/two-io/config.json'
166+
]);
167+
t.true(await pathExists('test/expected/by-config/two-io/input-1.html'));
168+
t.true(await pathExists('test/expected/by-config/two-io/input-2.html'));
169+
t.is(
170+
(await read('test/expected/by-config/two-io/input-1.html')),
171+
(await read('test/fixtures/by-config/two-io/input-1.html'))
172+
);
173+
t.is(
174+
(await read('test/expected/by-config/two-io/input-2.html')),
175+
(await read('test/fixtures/by-config/two-io/input-2.html'))
176+
);
177+
});
178+
179+
test('Transform html stdin options only config one-io-by-pattern', async t => {
180+
t.plan(2);
181+
await execa(cli, [
182+
'-c',
183+
'test/fixtures/by-config/one-io-by-pattern/config.json'
184+
]);
185+
t.true(await pathExists('test/expected/by-config/one-io-by-pattern/input-1.html'));
186+
t.is(
187+
(await read('test/expected/by-config/one-io-by-pattern/input-1.html')),
188+
(await read('test/fixtures/by-config/one-io-by-pattern/input-1.html'))
189+
);
190+
});

test/test-out-resolve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('input file and output folder should return tmp/file.ext', async t => {
2828
});
2929

3030
test('input files and output folder should return tmp/test/*.ext', async t => {
31-
t.is(await outResolve('test/*.ext', 'tmp'), path.normalize('tmp/test/*.ext'));
31+
t.is(await outResolve('tmp/test/*.ext', undefined), path.normalize('tmp/test/*.ext'));
3232
});
3333

3434
test('input files and output file should return output.ext', async t => {

0 commit comments

Comments
 (0)