@@ -3,12 +3,14 @@ const execa = require('execa');
3
3
const tempWrite = require ( 'temp-write' ) ;
4
4
const pathExists = require ( 'path-exists' ) ;
5
5
const path = require ( 'path' ) ;
6
+ const del = require ( 'del' ) ;
6
7
const readPkg = require ( 'read-pkg' ) ;
8
+ const copy = require ( 'cpy' ) ;
7
9
const readFile = require ( 'fs' ) . readFile ;
8
10
9
- function read ( path ) {
11
+ function read ( pathFile ) {
10
12
return new Promise ( ( resolve , reject ) => {
11
- readFile ( path , 'utf8' , ( err , data ) => {
13
+ readFile ( pathFile , 'utf8' , ( err , data ) => {
12
14
if ( err ) {
13
15
reject ( err ) ;
14
16
}
@@ -30,30 +32,52 @@ test('Missing required arguments -i', t => {
30
32
t . throws ( execa ( '../cli.js' , [ `-o ${ filename } ` ] ) ) ;
31
33
} ) ;
32
34
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
+
33
40
test ( 'Check version' , async t => {
34
41
t . is ( ( await execa ( '../cli.js' , [ '-v' ] ) ) . stdout , ( await readPkg ( path . dirname ( __dirname ) ) ) . version ) ;
35
42
} ) ;
36
43
37
44
test ( 'Transform html witch config in package.json' , async t => {
38
45
t . plan ( 2 ) ;
39
- const filename = await tempWrite ( 'output.html' ) ;
46
+ const filename = await tempWrite ( 'output.html' , 'output.html' ) ;
40
47
await execa ( '../cli.js' , [ '-i' , 'fixtures/input.html' , '-o' , filename ] ) ;
41
48
t . true ( await pathExists ( filename ) ) ;
42
49
t . is ( ( await read ( 'expected/output-config-pkg.html' ) ) , ( await read ( filename ) ) ) ;
43
50
} ) ;
44
51
45
52
test ( 'Transform html witch indent' , async t => {
46
53
t . plan ( 2 ) ;
47
- const filename = await tempWrite ( 'output.html' ) ;
54
+ const filename = await tempWrite ( 'output.html' , 'output.html' ) ;
48
55
await execa ( '../cli.js' , [ '-i' , 'fixtures/input-indent.html' , '-o' , filename ] ) ;
49
56
t . true ( await pathExists ( filename ) ) ;
50
57
t . is ( ( await read ( 'expected/output-indent.html' ) ) , ( await read ( filename ) ) ) ;
51
58
} ) ;
52
59
53
60
test ( 'Transform html witch config in file' , async t => {
54
61
t . plan ( 2 ) ;
55
- const filename = await tempWrite ( 'output.html' ) ;
62
+ const filename = await tempWrite ( 'output.html' , 'output.html' ) ;
56
63
await execa ( '../cli.js' , [ '-i' , 'fixtures/input.html' , '-o' , filename , '-c' , 'fixtures/config.json' ] ) ;
57
64
t . true ( await pathExists ( filename ) ) ;
58
65
t . is ( ( await read ( 'expected/output-config-file.html' ) ) , ( await read ( filename ) ) ) ;
59
66
} ) ;
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