1
- const grunt = require ( 'grunt' ) ;
1
+ const fs = require ( 'fs' ) ;
2
+ const { readFile, access } = fs . promises ;
2
3
3
4
/*
4
5
======== A Handy Little Nodeunit Reference ========
@@ -20,122 +21,143 @@ const grunt = require('grunt');
20
21
test.ifError(value)
21
22
*/
22
23
24
+ const fileExists = async ( file ) => {
25
+ try {
26
+ await access ( file ) ;
27
+ return true ;
28
+ } catch ( err ) {
29
+ return false ;
30
+ }
31
+ } ;
32
+
23
33
exports . gruntPostcss = {
24
34
25
- defaults : ( test ) => {
35
+ defaults : async ( test ) => {
26
36
const actual = {
27
- css : grunt . file . read ( 'tmp/defaults.css' ) ,
37
+ css : await readFile ( 'tmp/defaults.css' , 'utf8 ') ,
28
38
} ;
29
39
30
40
const expected = {
31
- css : grunt . file . read ( 'test/expected/defaults.css' ) ,
41
+ css : await readFile ( 'test/expected/defaults.css' , 'utf8 ') ,
32
42
} ;
33
43
44
+ const checkExists = await fileExists ( 'tmp/defaults.css.map' ) ;
45
+
34
46
test . strictEqual ( actual . css , expected . css ) ;
35
- test . ok ( ! grunt . file . exists ( 'tmp/defaults.css.map' ) ) ;
47
+ test . ok ( ! checkExists ) ;
36
48
test . done ( ) ;
37
49
} ,
38
50
39
- defaultsFn : ( test ) => {
51
+ defaultsFn : async ( test ) => {
40
52
const actual = {
41
- css : grunt . file . read ( 'tmp/defaultsFn.css' ) ,
53
+ css : await readFile ( 'tmp/defaultsFn.css' , 'utf8 ') ,
42
54
} ;
43
55
44
56
const expected = {
45
- css : grunt . file . read ( 'test/expected/defaults.css' ) ,
57
+ css : await readFile ( 'test/expected/defaults.css' , 'utf8 ') ,
46
58
} ;
47
59
60
+ const checkExists = await fileExists ( 'tmp/defaultsFn.css.map' ) ;
61
+
48
62
test . strictEqual ( actual . css , expected . css ) ;
49
- test . ok ( ! grunt . file . exists ( 'tmp/defaultsFn.css.map' ) ) ;
63
+ test . ok ( ! checkExists ) ;
50
64
test . done ( ) ;
51
65
} ,
52
66
53
- mapInline : ( test ) => {
67
+ mapInline : async ( test ) => {
54
68
const actual = {
55
- css : grunt . file . read ( 'tmp/mapInline.css' ) ,
69
+ css : await readFile ( 'tmp/mapInline.css' , 'utf8 ') ,
56
70
} ;
57
71
58
72
const expected = {
59
- css : grunt . file . read ( 'test/expected/mapInline.css' ) ,
73
+ css : await readFile ( 'test/expected/mapInline.css' , 'utf8 ') ,
60
74
} ;
61
75
76
+ const checkExists = await fileExists ( 'tmp/mapInline.css.map' ) ;
77
+
62
78
test . strictEqual ( actual . css , expected . css ) ;
63
- test . ok ( ! grunt . file . exists ( 'tmp/mapInline.css.map' ) ) ;
79
+ test . ok ( ! checkExists ) ;
64
80
test . done ( ) ;
65
81
} ,
66
82
67
- mapSeparate : ( test ) => {
83
+ mapSeparate : async ( test ) => {
68
84
const actual = {
69
- css : grunt . file . read ( 'tmp/mapSeparate.css' ) ,
70
- map : grunt . file . read ( 'tmp/mapSeparate.css.map' ) ,
85
+ css : await readFile ( 'tmp/mapSeparate.css' , 'utf8 ') ,
86
+ map : await readFile ( 'tmp/mapSeparate.css.map' , 'utf8 ') ,
71
87
} ;
72
88
73
89
const expected = {
74
- css : grunt . file . read ( 'test/expected/mapSeparate.css' ) ,
75
- map : grunt . file . read ( 'test/expected/mapSeparate.css.map' ) ,
90
+ css : await readFile ( 'test/expected/mapSeparate.css' , 'utf8 ') ,
91
+ map : await readFile ( 'test/expected/mapSeparate.css.map' , 'utf8 ') ,
76
92
} ;
77
93
78
94
test . strictEqual ( actual . css , expected . css ) ;
79
95
test . strictEqual ( actual . map , expected . map ) ;
80
96
test . done ( ) ;
81
97
} ,
82
98
83
- mapAnnotationPath : ( test ) => {
99
+ mapAnnotationPath : async ( test ) => {
84
100
const actual = {
85
- css : grunt . file . read ( 'tmp/mapAnnotationPath.css' ) ,
86
- map : grunt . file . read ( 'tmp/maps/mapAnnotationPath.css.map' ) ,
101
+ css : await readFile ( 'tmp/mapAnnotationPath.css' , 'utf8 ') ,
102
+ map : await readFile ( 'tmp/maps/mapAnnotationPath.css.map' , 'utf8 ') ,
87
103
} ;
88
104
89
105
const expected = {
90
- css : grunt . file . read ( 'test/expected/mapAnnotationPath.css' ) ,
91
- map : grunt . file . read ( 'test/expected/maps/mapAnnotationPath.css.map' ) ,
106
+ css : await readFile ( 'test/expected/mapAnnotationPath.css' , 'utf8 ') ,
107
+ map : await readFile ( 'test/expected/maps/mapAnnotationPath.css.map' , 'utf8 ') ,
92
108
} ;
93
109
110
+ const checkExists = await fileExists ( 'tmp/mapAnnotationPath.css.map' ) ;
111
+
94
112
test . strictEqual ( actual . css , expected . css ) ;
95
113
test . strictEqual ( actual . map , expected . map ) ;
96
- test . ok ( ! grunt . file . exists ( 'tmp/mapAnnotationPath.css.map' ) ) ;
114
+ test . ok ( ! checkExists ) ;
97
115
test . done ( ) ;
98
116
} ,
99
117
100
- diff : ( test ) => {
118
+ diff : async ( test ) => {
101
119
const actual = {
102
- css : grunt . file . read ( 'tmp/diff.css' ) ,
103
- map : grunt . file . read ( 'tmp/diff.css.diff' ) ,
120
+ css : await readFile ( 'tmp/diff.css' , 'utf8 ') ,
121
+ map : await readFile ( 'tmp/diff.css.diff' , 'utf8 ') ,
104
122
} ;
105
123
106
124
const expected = {
107
- css : grunt . file . read ( 'test/expected/diff.css' ) ,
108
- map : grunt . file . read ( 'test/expected/diff.css.diff' ) ,
125
+ css : await readFile ( 'test/expected/diff.css' , 'utf8 ') ,
126
+ map : await readFile ( 'test/expected/diff.css.diff' , 'utf8 ') ,
109
127
} ;
110
128
111
129
test . strictEqual ( actual . css , expected . css ) ;
112
130
test . strictEqual ( actual . map , expected . map ) ;
113
131
test . done ( ) ;
114
132
} ,
115
133
116
- syntax : ( test ) => {
134
+ syntax : async ( test ) => {
117
135
const actual = {
118
- scss : grunt . file . read ( 'tmp/syntax.scss' ) ,
136
+ scss : await readFile ( 'tmp/syntax.scss' , 'utf8 ') ,
119
137
} ;
120
138
121
139
const expected = {
122
- scss : grunt . file . read ( 'test/expected/syntax.scss' ) ,
140
+ scss : await readFile ( 'test/expected/syntax.scss' , 'utf8 ') ,
123
141
} ;
124
142
125
143
test . strictEqual ( actual . scss , expected . scss ) ;
126
144
test . done ( ) ;
127
145
} ,
128
146
129
- writeDest : ( test ) => {
130
- test . ok ( grunt . file . exists ( 'tmp/doWriteDest.scss' ) ) ;
131
- test . ok ( ! grunt . file . exists ( 'tmp/noWriteDest.scss' ) ) ;
147
+ writeDest : async ( test ) => {
148
+ const checkExists = await fileExists ( 'tmp/doWriteDest.css' ) ;
149
+ const checkNoExists = await fileExists ( 'tmp/noWriteDest.css' ) ;
150
+ test . ok ( checkExists ) ;
151
+ test . ok ( ! checkNoExists ) ;
132
152
test . done ( ) ;
133
153
} ,
134
154
135
- sequential : ( test ) => {
136
- test . ok ( grunt . file . exists ( 'tmp/sequential.css' ) ) ;
137
- const actual = grunt . file . read ( 'tmp/sequential.css' ) ;
138
- const expected = grunt . file . read ( 'test/fixtures/a.css' ) ;
155
+ sequential : async ( test ) => {
156
+ const checkExists = await fileExists ( 'tmp/sequential.css' ) ;
157
+ test . ok ( checkExists ) ;
158
+
159
+ const actual = await readFile ( 'tmp/sequential.css' , 'utf8' ) ;
160
+ const expected = await readFile ( 'test/fixtures/a.css' , 'utf8' ) ;
139
161
test . strictEqual ( actual , expected ) ;
140
162
test . done ( ) ;
141
163
} ,
0 commit comments