11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3+ const util = require ( 'util' ) ;
4+ const readAsync = util . promisify ( fs . readFile ) ;
35const fixturesPath = path . join ( __dirname , 'fixtures' ) ;
46const HtmlDiffer = require ( '../../lib/index' ) . HtmlDiffer ;
57
@@ -9,61 +11,67 @@ const HtmlDiffer = require('../../lib/index').HtmlDiffer;
911 */
1012function readFiles ( basename ) {
1113 const fileName = basename + '.html' ;
12-
13- return {
14- html1 : fs . readFileSync ( path . join ( fixturesPath , 'first' , fileName ) , 'utf-8' ) ,
15- html2 : fs . readFileSync ( path . join ( fixturesPath , 'second' , fileName ) , 'utf-8' )
16- } ;
14+ return Promise . all ( [
15+ readAsync ( path . join ( fixturesPath , 'first' , fileName ) , 'utf-8' ) ,
16+ readAsync ( path . join ( fixturesPath , 'second' , fileName ) , 'utf-8' )
17+ ] ) ;
1718}
1819
1920describe ( '\'isEqual\'' , function ( ) {
2021 it ( 'must be equal' , async function ( ) {
2122 const htmlDiffer = new HtmlDiffer ( ) ;
22- const files = readFiles ( 'equal' ) ;
23+ const files = await readFiles ( 'equal' ) ;
24+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
2325
24- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
26+ isEqual . must . be . true ( ) ;
2527 } ) ;
2628
2729 it ( 'must be not equal' , async function ( ) {
2830 const htmlDiffer = new HtmlDiffer ( ) ;
29- const files = readFiles ( 'not-equal' ) ;
31+ const files = await readFiles ( 'not-equal' ) ;
32+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
3033
31- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . false ( ) ;
34+ isEqual . must . be . false ( ) ;
3235 } ) ;
3336
3437 it ( 'must consider uppercase and lowercase declarations in \'doctype\' to be equal' , async function ( ) {
3538 const htmlDiffer = new HtmlDiffer ( ) ;
36- const files = readFiles ( 'doctype' ) ;
39+ const files = await readFiles ( 'doctype' ) ;
40+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
3741
38- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
42+ isEqual . must . be . true ( ) ;
3943 } ) ;
4044
4145 it ( 'must sort attributes' , async function ( ) {
4246 const htmlDiffer = new HtmlDiffer ( ) ;
43- const files = readFiles ( 'sort-attributes' ) ;
47+ const files = await readFiles ( 'sort-attributes' ) ;
48+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
4449
45- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
50+ isEqual . must . be . true ( ) ;
4651 } ) ;
4752
4853 it ( 'must sort classes\' values' , async function ( ) {
4954 const htmlDiffer = new HtmlDiffer ( ) ;
50- const files = readFiles ( 'sort-classes' ) ;
55+ const files = await readFiles ( 'sort-classes' ) ;
56+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
5157
52- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
58+ isEqual . must . be . true ( ) ;
5359 } ) ;
5460
5561 it ( 'must sort values of attributes as JSON when the content is not a function' , async function ( ) {
5662 const htmlDiffer = new HtmlDiffer ( { compareAttributesAsJSON : [ 'a' , { name : 'b' , isFunction : false } ] } ) ;
57- const files = readFiles ( 'sort-values-in-json-format' ) ;
63+ const files = await readFiles ( 'sort-values-in-json-format' ) ;
64+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
5865
59- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
66+ isEqual . must . be . true ( ) ;
6067 } ) ;
6168
6269 it ( 'must handle invalid JSON' , async function ( ) {
6370 const htmlDiffer = new HtmlDiffer ( { compareAttributesAsJSON : [ 'data-bem' ] } ) ;
64- const files = readFiles ( 'invalid-json' ) ;
71+ const files = await readFiles ( 'invalid-json' ) ;
72+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
6573
66- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
74+ isEqual . must . be . true ( ) ;
6775 } ) ;
6876
6977 it ( 'must sort values of attributes as JSON when the content is a function' , async function ( ) {
@@ -74,80 +82,91 @@ describe('\'isEqual\'', function() {
7482 ]
7583 } ;
7684 const htmlDiffer = new HtmlDiffer ( options ) ;
77- const files = readFiles ( 'sort-functions-in-json-format' ) ;
85+ const files = await readFiles ( 'sort-functions-in-json-format' ) ;
86+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
7887
79- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
88+ isEqual . must . be . true ( ) ;
8089 } ) ;
8190
8291 it ( 'must handle invalid function' , async function ( ) {
8392 const options = { compareAttributesAsJSON : [ { name : 'onclick' , isFunction : true } ] } ;
8493 const htmlDiffer = new HtmlDiffer ( options ) ;
85- const files = readFiles ( 'invalid-function' ) ;
94+ const files = await readFiles ( 'invalid-function' ) ;
95+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
8696
87- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
97+ isEqual . must . be . true ( ) ;
8898 } ) ;
8999
90100 it ( 'must work option \'ignoreAttributes\'' , async function ( ) {
91101 const htmlDiffer = new HtmlDiffer ( { ignoreAttributes : [ 'id' , 'for' ] } ) ;
92- const files = readFiles ( 'ignore-attributes' ) ;
102+ const files = await readFiles ( 'ignore-attributes' ) ;
103+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
93104
94- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
105+ isEqual . must . be . true ( ) ;
95106 } ) ;
96107
97108 it ( 'must work option \'ignoreWhitespaces\'' , async function ( ) {
98109 const htmlDiffer = new HtmlDiffer ( { ignoreWhitespaces : true } ) ;
99- const files = readFiles ( 'ignore-whitespaces' ) ;
110+ const files = await readFiles ( 'ignore-whitespaces' ) ;
111+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
100112
101- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
113+ isEqual . must . be . true ( ) ;
102114 } ) ;
103115
104116 it ( 'must work option \'ignoreComments\'' , async function ( ) {
105117 const htmlDiffer = new HtmlDiffer ( ) ;
106- const files = readFiles ( 'ignore-comments' ) ;
118+ const files = await readFiles ( 'ignore-comments' ) ;
119+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
107120
108- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
121+ isEqual . must . be . true ( ) ;
109122 } ) ;
110123
111124 it ( 'must does NOT work option \'ignoreComments\'' , async function ( ) {
112125 const htmlDiffer = new HtmlDiffer ( { ignoreComments : false } ) ;
113- const files = readFiles ( 'ignore-comments-false' ) ;
126+ const files = await readFiles ( 'ignore-comments-false' ) ;
127+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
114128
115- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
129+ isEqual . must . be . true ( ) ;
116130 } ) ;
117131
118132 it ( 'must work option \'ignoreEndTags\'' , async function ( ) {
119133 const htmlDiffer = new HtmlDiffer ( { ignoreEndTags : true } ) ;
120- const files = readFiles ( 'ignore-end-tags' ) ;
134+ const files = await readFiles ( 'ignore-end-tags' ) ;
135+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
121136
122- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
137+ isEqual . must . be . true ( ) ;
123138 } ) ;
124139
125140 it ( 'must work \'bem\' preset' , async function ( ) {
126141 const htmlDiffer = new HtmlDiffer ( 'bem' ) ;
127- const files = readFiles ( 'bem-preset' ) ;
142+ const files = await readFiles ( 'bem-preset' ) ;
143+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
128144
129- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
145+ isEqual . must . be . true ( ) ;
130146 } ) ;
131147
132148 it ( 'must work mask {{RegExp}}' , async function ( ) {
133149 const htmlDiffer = new HtmlDiffer ( ) ;
134- const files = readFiles ( 'mask' ) ;
150+ const files = await readFiles ( 'mask' ) ;
151+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
135152
136- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
153+ isEqual . must . be . true ( ) ;
137154 } ) ;
138155
139156 it ( 'must not be equal by mask {{RegExp}}' , async function ( ) {
140157 const htmlDiffer = new HtmlDiffer ( ) ;
141- const files = readFiles ( 'mask-false' ) ;
158+ const files = await readFiles ( 'mask-false' ) ;
159+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
142160
143- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . false ( ) ;
161+ isEqual . must . be . false ( ) ;
144162 } ) ;
145163
146164 it ( 'must ignore self closing slash' , async function ( ) {
147165 const htmlDiffer = new HtmlDiffer ( { ignoreSelfClosingSlash : true } ) ;
148- const files = readFiles ( 'strip-self-closing-slash' ) ;
166+ const files = await readFiles ( 'strip-self-closing-slash' ) ;
167+ const isEqual = await htmlDiffer . isEqual ( ...files ) ;
149168
150- ( await htmlDiffer . isEqual ( files . html1 , files . html2 ) ) . must . be . true ( ) ;
169+ isEqual . must . be . true ( ) ;
151170 } ) ;
152171
153172 it ( 'must throw an error for invalid preset' , function ( ) {
0 commit comments