Skip to content

Commit ffacaa9

Browse files
author
Ivan Demidov
committed
Update tests for option use
1 parent 89732b5 commit ffacaa9

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

test/expected/output-bem.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="myComponent MadTeaParty">
2+
<div class="myTitle MadTeaParty__march-title">Super Title</div>
3+
<div class="myText MadTeaParty__march-text">Awesome Text</div>
4+
</div>

test/fixtures/config-for-bem.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"bem": {
3+
"elemPrefix": "__",
4+
"modPrefix": "-",
5+
"modDlmtr": "--"
6+
},
7+
"customElements": {
8+
"defaultTag": "span"
9+
}
10+
}

test/fixtures/input-bem.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<myComponent block="MadTeaParty">
2+
<myTitle elem="march-title">Super Title</myTitle>
3+
<myText elem="march-text">Awesome Text</myText>
4+
</myComponent>

test/test-cli.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
const path = require('path');
2-
const readFile = require('fs').readFile;
2+
const fs = require('fs');
33
const test = require('ava');
44
const execa = require('execa');
5-
const tempWrite = require('temp-write');
65
const pathExists = require('path-exists');
76
const readPkg = require('read-pkg');
87
const copy = require('cpy');
98
const tempfile = require('tempfile');
109

1110
function read(pathFile) {
1211
return new Promise((resolve, reject) => {
13-
readFile(pathFile, 'utf8', (err, data) => {
12+
fs.readFile(pathFile, 'utf8', (err, data) => {
1413
if (err) {
1514
reject(err);
1615
}
@@ -19,7 +18,7 @@ function read(pathFile) {
1918
});
2019
}
2120

22-
test('Missing required arguments -i, -o', t => {
21+
test('Missing required arguments -i, -o, -u', t => {
2322
t.throws(execa('../cli.js', []));
2423
});
2524

@@ -28,12 +27,17 @@ test('Missing required arguments -o', t => {
2827
});
2928

3029
test('Missing required arguments -i', t => {
31-
const filename = tempWrite.sync('output.html');
30+
const filename = tempfile('.html');
3231
t.throws(execa('../cli.js', [`-o ${filename}`]));
3332
});
3433

34+
test('Missing required arguments -u', t => {
35+
const filename = tempfile('.html');
36+
t.throws(execa('../cli.js', [`-o ${filename} -i fixtures/input.html`]));
37+
});
38+
3539
test('One of the arguments', t => {
36-
const filename = tempWrite.sync('output.html');
40+
const filename = tempfile('.html');
3741
t.throws(execa('../cli.js', ['-o', filename, '-r', '-i', 'fixtures/input.html']));
3842
});
3943

@@ -43,41 +47,64 @@ test('Check version', async t => {
4347

4448
test('Transform html witch config in package.json', async t => {
4549
t.plan(2);
46-
const filename = await tempWrite('output.html', 'output.html');
50+
const filename = tempfile('.html');
4751
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename]);
4852
t.true(await pathExists(filename));
4953
t.is((await read('expected/output-config-pkg.html')), (await read(filename)));
5054
});
5155

5256
test('Transform html witch indent', async t => {
5357
t.plan(2);
54-
const filename = await tempWrite('output.html', 'output.html');
58+
const filename = tempfile('.html');
5559
await execa('../cli.js', ['-i', 'fixtures/input-indent.html', '-o', filename]);
5660
t.true(await pathExists(filename));
5761
t.is((await read('expected/output-indent.html')), (await read(filename)));
5862
});
5963

6064
test('Transform html witch config in file', async t => {
6165
t.plan(2);
62-
const filename = await tempWrite('output.html', 'output.html');
66+
const filename = tempfile('.html');
6367
await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']);
6468
t.true(await pathExists(filename));
6569
t.is((await read('expected/output-config-file.html')), (await read(filename)));
6670
});
6771

6872
test('Transform html from folder', async t => {
6973
t.plan(2);
70-
const folder = await tempfile();
74+
const folder = tempfile();
7175
await execa('../cli.js', ['-i', 'fixtures/*.html', '-o', `${folder}/`]);
7276
t.is((await read('expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
7377
t.is((await read('expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
7478
});
7579

7680
test('Transform html witch options replace', async t => {
7781
t.plan(2);
78-
const folder = await tempfile();
82+
const folder = tempfile();
7983
await copy(['fixtures/*.html'], `${folder}/`);
8084
await execa('../cli.js', ['-i', `${folder}/*.html`, '-r']);
8185
t.is((await read('expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
8286
t.is((await read('expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
8387
});
88+
89+
test('Transform html witch config in file and stdin options use', async t => {
90+
t.plan(2);
91+
const filename = tempfile('.html');
92+
await execa('../cli.js', [
93+
'-o',
94+
filename,
95+
'-i',
96+
'fixtures/input-bem.html',
97+
'-c',
98+
'fixtures/config.json',
99+
'-u',
100+
'posthtml-bem',
101+
'--posthtml-bem.elemPrefix',
102+
'__',
103+
'--posthtml-bem.elemMod',
104+
'_',
105+
'-u',
106+
'posthtml-custom-elements'
107+
]);
108+
t.true(await pathExists(filename));
109+
t.is((await read('expected/output-bem.html')), (await read(filename)));
110+
});

0 commit comments

Comments
 (0)