@@ -7,8 +7,11 @@ var rewire = require('rewire');
77var suitcss = rewire ( '../lib' ) ;
88var path = require ( 'path' ) ;
99var sinonChai = require ( 'sinon-chai' ) ;
10+ var chaiAsPromised = require ( 'chai-as-promised' ) ;
11+ require ( 'sinon-as-promised' ) ;
1012
1113chai . use ( sinonChai ) ;
14+ chai . use ( chaiAsPromised ) ;
1215var expect = chai . expect ;
1316
1417/**
@@ -151,27 +154,37 @@ describe('suitcss', function() {
151154 } ) ;
152155
153156 describe ( 'stylelint' , function ( ) {
154- it ( 'should check the input conforms to SUIT style rules' , function ( done ) {
155- suitcss ( '@import "./stylelint.css"' , {
156- lint : true ,
157- root : 'test/fixtures' ,
158- 'postcss-reporter' : {
159- throwError : true
160- }
161- } ) . then ( function ( ) {
162- done ( new Error ( 'stylelint should have failed conformance' ) ) ;
163- } ) . catch ( function ( err ) {
164- expect ( err . message ) . to . contain ( 'postcss-reporter: warnings or errors were found' ) ;
165- done ( ) ;
166- } ) ;
157+ it ( 'should lint the component' , function ( ) {
158+ return expect (
159+ suitcss ( read ( 'fixtures/component' ) , {
160+ lint : true ,
161+ root : 'test/fixtures' ,
162+ 'postcss-reporter' : {
163+ throwError : true
164+ }
165+ } )
166+ ) . to . be . fulfilled ;
167+ } ) ;
168+
169+ it ( 'should throw an error if stylelint fails' , function ( ) {
170+ return expect (
171+ suitcss ( '@import "./stylelint.css"' , {
172+ lint : true ,
173+ root : 'test/fixtures' ,
174+ 'postcss-reporter' : {
175+ throwError : true
176+ }
177+ } )
178+ ) . to . be . rejectedWith ( Error , 'postcss-reporter: warnings or errors were found' ) ;
167179 } ) ;
168180 } ) ;
169181
170182 describe ( 'transforming css before linting' , function ( ) {
171183 var lintImportedFilesStub , beforeLintStub , revert ;
172184
173185 beforeEach ( function ( ) {
174- lintImportedFilesStub = sinon . stub ( ) . returns ( '/*linting done*/' ) ;
186+ var postcssPromise = sinon . stub ( ) . resolves ( '/*linting done*/' ) ( ) ;
187+ lintImportedFilesStub = sinon . stub ( ) . returns ( postcssPromise ) ;
175188 beforeLintStub = sinon . stub ( ) . returns ( '/*before lint*/' ) ;
176189 revert = suitcss . __set__ ( 'lintImportedFiles' , lintImportedFilesStub ) ;
177190 } ) ;
@@ -184,35 +197,38 @@ describe('suitcss', function() {
184197 suitcss ( read ( 'fixtures/component' ) , {
185198 root : 'test/fixtures' ,
186199 beforeLint : beforeLintStub
187- } ) . catch ( done ) ;
188-
189- expect ( lintImportedFilesStub ) . to . be . calledOnce ;
190- expect ( beforeLintStub ) . to . be . calledOnce ;
191- expect ( beforeLintStub ) . to . have . been . calledBefore ( lintImportedFilesStub ) ;
192-
193- done ( ) ;
200+ } )
201+ . then ( function ( ) {
202+ expect ( beforeLintStub ) . to . be . calledOnce ;
203+ expect ( lintImportedFilesStub ) . to . be . calledOnce ;
204+ expect ( beforeLintStub ) . to . have . been . calledBefore ( lintImportedFilesStub ) ;
205+ done ( ) ;
206+ } )
207+ . catch ( done ) ;
194208 } ) ;
195209
196210 it ( 'should pass the result of `beforeLint` to `lintImportedFiles`' , function ( done ) {
197211 suitcss ( read ( 'fixtures/component' ) , {
198212 root : 'test/fixtures' ,
199213 beforeLint : beforeLintStub
200- } ) . catch ( done ) ;
201-
202- expect ( lintImportedFilesStub . args [ 0 ] [ 1 ] ) . to . equal ( '/*before lint*/' ) ;
203-
204- done ( ) ;
214+ } )
215+ . then ( function ( ) {
216+ expect ( lintImportedFilesStub . args [ 0 ] [ 1 ] ) . to . equal ( '/*before lint*/' ) ;
217+ done ( ) ;
218+ } )
219+ . catch ( done ) ;
205220 } ) ;
206221
207222 it ( 'should pass the options object to the beforeLint function as the third parameter' , function ( done ) {
208223 suitcss ( read ( 'fixtures/component' ) , {
209224 root : 'test/fixtures' ,
210225 beforeLint : beforeLintStub
211- } ) . catch ( done ) ;
212-
213- expect ( beforeLintStub . args [ 0 ] [ 2 ] ) . to . contain ( { root : 'test/fixtures' } ) ;
214-
215- done ( ) ;
226+ } )
227+ . then ( function ( ) {
228+ expect ( beforeLintStub . args [ 0 ] [ 2 ] ) . to . contain ( { root : 'test/fixtures' } ) ;
229+ done ( ) ;
230+ } )
231+ . catch ( done ) ;
216232 } ) ;
217233 } ) ;
218234 } ) ;
0 commit comments