1
1
const path = require ( 'path' ) ;
2
- const readFile = require ( 'fs' ) . readFile ;
2
+ const fs = require ( 'fs' ) ;
3
3
const test = require ( 'ava' ) ;
4
4
const execa = require ( 'execa' ) ;
5
- const tempWrite = require ( 'temp-write' ) ;
6
5
const pathExists = require ( 'path-exists' ) ;
7
6
const readPkg = require ( 'read-pkg' ) ;
8
7
const copy = require ( 'cpy' ) ;
9
8
const tempfile = require ( 'tempfile' ) ;
10
9
11
10
function read ( pathFile ) {
12
11
return new Promise ( ( resolve , reject ) => {
13
- readFile ( pathFile , 'utf8' , ( err , data ) => {
12
+ fs . readFile ( pathFile , 'utf8' , ( err , data ) => {
14
13
if ( err ) {
15
14
reject ( err ) ;
16
15
}
@@ -19,7 +18,7 @@ function read(pathFile) {
19
18
} ) ;
20
19
}
21
20
22
- test ( 'Missing required arguments -i, -o' , t => {
21
+ test ( 'Missing required arguments -i, -o, -u ' , t => {
23
22
t . throws ( execa ( '../cli.js' , [ ] ) ) ;
24
23
} ) ;
25
24
@@ -28,12 +27,17 @@ test('Missing required arguments -o', t => {
28
27
} ) ;
29
28
30
29
test ( 'Missing required arguments -i' , t => {
31
- const filename = tempWrite . sync ( 'output .html') ;
30
+ const filename = tempfile ( ' .html') ;
32
31
t . throws ( execa ( '../cli.js' , [ `-o ${ filename } ` ] ) ) ;
33
32
} ) ;
34
33
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
+
35
39
test ( 'One of the arguments' , t => {
36
- const filename = tempWrite . sync ( 'output .html') ;
40
+ const filename = tempfile ( ' .html') ;
37
41
t . throws ( execa ( '../cli.js' , [ '-o' , filename , '-r' , '-i' , 'fixtures/input.html' ] ) ) ;
38
42
} ) ;
39
43
@@ -43,41 +47,64 @@ test('Check version', async t => {
43
47
44
48
test ( 'Transform html witch config in package.json' , async t => {
45
49
t . plan ( 2 ) ;
46
- const filename = await tempWrite ( 'output.html' , 'output .html') ;
50
+ const filename = tempfile ( ' .html') ;
47
51
await execa ( '../cli.js' , [ '-i' , 'fixtures/input.html' , '-o' , filename ] ) ;
48
52
t . true ( await pathExists ( filename ) ) ;
49
53
t . is ( ( await read ( 'expected/output-config-pkg.html' ) ) , ( await read ( filename ) ) ) ;
50
54
} ) ;
51
55
52
56
test ( 'Transform html witch indent' , async t => {
53
57
t . plan ( 2 ) ;
54
- const filename = await tempWrite ( 'output.html' , 'output .html') ;
58
+ const filename = tempfile ( ' .html') ;
55
59
await execa ( '../cli.js' , [ '-i' , 'fixtures/input-indent.html' , '-o' , filename ] ) ;
56
60
t . true ( await pathExists ( filename ) ) ;
57
61
t . is ( ( await read ( 'expected/output-indent.html' ) ) , ( await read ( filename ) ) ) ;
58
62
} ) ;
59
63
60
64
test ( 'Transform html witch config in file' , async t => {
61
65
t . plan ( 2 ) ;
62
- const filename = await tempWrite ( 'output.html' , 'output .html') ;
66
+ const filename = tempfile ( ' .html') ;
63
67
await execa ( '../cli.js' , [ '-i' , 'fixtures/input.html' , '-o' , filename , '-c' , 'fixtures/config.json' ] ) ;
64
68
t . true ( await pathExists ( filename ) ) ;
65
69
t . is ( ( await read ( 'expected/output-config-file.html' ) ) , ( await read ( filename ) ) ) ;
66
70
} ) ;
67
71
68
72
test ( 'Transform html from folder' , async t => {
69
73
t . plan ( 2 ) ;
70
- const folder = await tempfile ( ) ;
74
+ const folder = tempfile ( ) ;
71
75
await execa ( '../cli.js' , [ '-i' , 'fixtures/*.html' , '-o' , `${ folder } /` ] ) ;
72
76
t . is ( ( await read ( 'expected/output-config-pkg.html' ) ) , ( await read ( `${ folder } /input.html` ) ) ) ;
73
77
t . is ( ( await read ( 'expected/output-indent.html' ) ) , ( await read ( `${ folder } /input-indent.html` ) ) ) ;
74
78
} ) ;
75
79
76
80
test ( 'Transform html witch options replace' , async t => {
77
81
t . plan ( 2 ) ;
78
- const folder = await tempfile ( ) ;
82
+ const folder = tempfile ( ) ;
79
83
await copy ( [ 'fixtures/*.html' ] , `${ folder } /` ) ;
80
84
await execa ( '../cli.js' , [ '-i' , `${ folder } /*.html` , '-r' ] ) ;
81
85
t . is ( ( await read ( 'expected/output-config-pkg.html' ) ) , ( await read ( `${ folder } /input.html` ) ) ) ;
82
86
t . is ( ( await read ( 'expected/output-indent.html' ) ) , ( await read ( `${ folder } /input-indent.html` ) ) ) ;
83
87
} ) ;
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