@@ -33,10 +33,12 @@ const baseEslintOpts = {
3333 * @param object opts
3434 * @param function done
3535 */
36- function lint ( opts , done ) {
37- readFixture ( opts . fixture , ( err , src ) => {
38- if ( err ) return done ( err ) ;
39- done ( null , eslint . linter . verify ( src , opts . eslint ) ) ;
36+ function lint ( opts ) {
37+ return new Promise ( ( resolve , reject ) => {
38+ readFixture ( opts . fixture , ( err , src ) => {
39+ if ( err ) return reject ( err ) ;
40+ resolve ( eslint . linter . verify ( src , opts . eslint ) ) ;
41+ } ) ;
4042 } ) ;
4143}
4244
@@ -66,18 +68,14 @@ function strictSuite() {
6668 eslintOpts . rules [ ruleId ] = [ errorLevel , "never" ] ;
6769
6870 [ "global-with" , "function-with" ] . forEach ( fixture => {
69- it ( `should error on ${ fixture . match ( / ^ [ ^ - ] + / ) [ 0 ] } directive` , done => {
70- lint (
71- {
72- fixture : [ "strict" , fixture ] ,
73- eslint : eslintOpts ,
74- } ,
75- ( err , report ) => {
76- if ( err ) return done ( err ) ;
77- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
78- done ( ) ;
79- } ,
80- ) ;
71+ it ( `should error on ${
72+ fixture . match ( / ^ [ ^ - ] + / ) [ 0 ]
73+ } directive`, async ( ) => {
74+ const report = await lint ( {
75+ fixture : [ "strict" , fixture ] ,
76+ eslint : eslintOpts ,
77+ } ) ;
78+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
8179 } ) ;
8280 } ) ;
8381 } ) ;
@@ -88,65 +86,41 @@ function strictSuite() {
8886 } ) ;
8987 eslintOpts . rules [ ruleId ] = [ errorLevel , "global" ] ;
9088
91- it ( "shouldn't error on single global directive" , done => {
92- lint (
93- {
94- fixture : [ "strict" , "global-with" ] ,
95- eslint : eslintOpts ,
96- } ,
97- ( err , report ) => {
98- if ( err ) return done ( err ) ;
99- expect ( report . length ) . toBe ( 0 ) ;
100- done ( ) ;
101- } ,
102- ) ;
89+ it ( "shouldn't error on single global directive" , async ( ) => {
90+ const report = await lint ( {
91+ fixture : [ "strict" , "global-with" ] ,
92+ eslint : eslintOpts ,
93+ } ) ;
94+ expect ( report . length ) . toBe ( 0 ) ;
10395 } ) ;
10496
105- it ( "should error twice on global directive: no and function directive: yes" , done => {
106- lint (
107- {
108- fixture : [ "strict" , "function-with" ] ,
109- eslint : eslintOpts ,
110- } ,
111- ( err , report ) => {
112- if ( err ) return done ( err ) ;
113- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
114- done ( ) ;
115- } ,
116- ) ;
97+ it ( "should error twice on global directive: no and function directive: yes" , async ( ) => {
98+ const report = await lint ( {
99+ fixture : [ "strict" , "function-with" ] ,
100+ eslint : eslintOpts ,
101+ } ) ;
102+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
117103 } ) ;
118104
119- it ( "should error on function directive" , done => {
120- lint (
121- {
122- fixture : [ "strict" , "global-with-function-with" ] ,
123- eslint : eslintOpts ,
124- } ,
125- ( err , report ) => {
126- if ( err ) return done ( err ) ;
127- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
128- // This is to make sure the test fails prior to adapting Babel AST
129- // directive representation to ESLint format. Otherwise it reports an
130- // error for missing global directive that masquerades as the expected
131- // result of the previous assertion.
132- expect ( report [ 0 ] . nodeType ) . not . toBe ( "Program" ) ;
133- done ( ) ;
134- } ,
135- ) ;
105+ it ( "should error on function directive" , async ( ) => {
106+ const report = await lint ( {
107+ fixture : [ "strict" , "global-with-function-with" ] ,
108+ eslint : eslintOpts ,
109+ } ) ;
110+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
111+ // This is to make sure the test fails prior to adapting Babel AST
112+ // directive representation to ESLint format. Otherwise it reports an
113+ // error for missing global directive that masquerades as the expected
114+ // result of the previous assertion.
115+ expect ( report [ 0 ] . nodeType ) . not . toBe ( "Program" ) ;
136116 } ) ;
137117
138- it ( "should error on no directive" , done => {
139- lint (
140- {
141- fixture : [ "strict" , "none" ] ,
142- eslint : eslintOpts ,
143- } ,
144- ( err , report ) => {
145- if ( err ) return done ( err ) ;
146- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
147- done ( ) ;
148- } ,
149- ) ;
118+ it ( "should error on no directive" , async ( ) => {
119+ const report = await lint ( {
120+ fixture : [ "strict" , "none" ] ,
121+ eslint : eslintOpts ,
122+ } ) ;
123+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
150124 } ) ;
151125 } ) ;
152126
@@ -156,63 +130,39 @@ function strictSuite() {
156130 } ) ;
157131 eslintOpts . rules [ ruleId ] = [ errorLevel , "function" ] ;
158132
159- it ( "shouldn't error on single function directive" , done => {
160- lint (
161- {
162- fixture : [ "strict" , "function-with" ] ,
163- eslint : eslintOpts ,
164- } ,
165- ( err , report ) => {
166- if ( err ) return done ( err ) ;
167- expect ( report . length ) . toBe ( 0 ) ;
168- done ( ) ;
169- } ,
170- ) ;
133+ it ( "shouldn't error on single function directive" , async ( ) => {
134+ const report = await lint ( {
135+ fixture : [ "strict" , "none" ] ,
136+ eslint : eslintOpts ,
137+ } ) ;
138+ expect ( report . length ) . toBe ( 0 ) ;
171139 } ) ;
172140
173- it ( "should error twice on function directive: no and global directive: yes" , done => {
174- lint (
175- {
176- fixture : [ "strict" , "global-with-function-without" ] ,
177- eslint : eslintOpts ,
178- } ,
179- ( err , report ) => {
180- if ( err ) return done ( err ) ;
181- [ 0 , 1 ] . forEach ( i => {
182- expect ( report [ i ] . ruleId ) . toBe ( ruleId ) ;
183- } ) ;
184- done ( ) ;
185- } ,
186- ) ;
141+ it ( "should error twice on function directive: no and global directive: yes" , async ( ) => {
142+ const report = await lint ( {
143+ fixture : [ "strict" , "global-with-function-without" ] ,
144+ eslint : eslintOpts ,
145+ } ) ;
146+ [ 0 , 1 ] . forEach ( i => {
147+ expect ( report [ i ] . ruleId ) . toBe ( ruleId ) ;
148+ } ) ;
187149 } ) ;
188150
189- it ( "should error on only global directive" , done => {
190- lint (
191- {
192- fixture : [ "strict" , "global-with" ] ,
193- eslint : eslintOpts ,
194- } ,
195- ( err , report ) => {
196- if ( err ) return done ( err ) ;
197- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
198- done ( ) ;
199- } ,
200- ) ;
151+ it ( "should error on only global directive" , async ( ) => {
152+ const report = await lint ( {
153+ fixture : [ "strict" , "global-with" ] ,
154+ eslint : eslintOpts ,
155+ } ) ;
156+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
201157 } ) ;
202158
203- it ( "should error on extraneous global directive" , done => {
204- lint (
205- {
206- fixture : [ "strict" , "global-with-function-with" ] ,
207- eslint : eslintOpts ,
208- } ,
209- ( err , report ) => {
210- if ( err ) return done ( err ) ;
211- expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
212- expect ( report [ 0 ] . nodeType . indexOf ( "Function" ) ) . toBe ( - 1 ) ;
213- done ( ) ;
214- } ,
215- ) ;
159+ it ( "should error on extraneous global directive" , async ( ) => {
160+ const report = await lint ( {
161+ fixture : [ "strict" , "global-with-function-with" ] ,
162+ eslint : eslintOpts ,
163+ } ) ;
164+ expect ( report [ 0 ] . ruleId ) . toBe ( ruleId ) ;
165+ expect ( report [ 0 ] . nodeType . indexOf ( "Function" ) ) . toBe ( - 1 ) ;
216166 } ) ;
217167 } ) ;
218168}
0 commit comments