Skip to content

Commit a19d4c7

Browse files
committed
Merge pull request #24 from suitcss/improve-tests
Improve tests
2 parents 2eca628 + d0953a6 commit a19d4c7

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ language: node_js
22
sudo: false
33
node_js:
44
- "0.12"
5+
- "4"
6+
- "5"

lib/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function mergeOptions(options) {
9999
if (typeof beforeLint === 'function') {
100100
css = beforeLint(css, filename, merged);
101101
}
102-
return lintImportedFiles(merged)(css, filename);
102+
return lintImportedFiles(merged, css, filename);
103103
};
104104

105105
// Allow additional plugins to be merged with the defaults
@@ -119,18 +119,16 @@ function mergeOptions(options) {
119119
* @param {Object} options
120120
* @returns {Function} Used by postcss-import transform
121121
*/
122-
function lintImportedFiles(options) {
123-
return function(css, filename) {
124-
var processor = postcss();
122+
function lintImportedFiles(options, css, filename) {
123+
var processor = postcss();
125124

126-
if (options.lint) {
127-
processor.use(stylelint(options.stylelint));
128-
}
125+
if (options.lint) {
126+
processor.use(stylelint(options.stylelint));
127+
}
129128

130-
processor
131-
.use(bemLinter(options['postcss-bem-linter']))
132-
.use(reporter(options['postcss-reporter']));
129+
processor
130+
.use(bemLinter(options['postcss-bem-linter']))
131+
.use(reporter(options['postcss-reporter']));
133132

134-
return processor.process(css, {from: filename}).css;
135-
};
133+
return processor.process(css, {from: filename}).css;
136134
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
"postcss-property-lookup": "^1.1.4",
4040
"rewire": "^2.5.1",
4141
"sinon": "^1.17.2",
42+
"sinon-chai": "^2.8.0",
4243
"stylelint-config-suitcss": "^1.0.0"
4344
},
4445
"scripts": {
45-
"test": "npm run lint && mocha --reporter spec --slow 400",
46+
"test": "npm run lint && mocha --reporter spec --slow 400 --timeout 3000",
4647
"lint": "eslint lib/index.js test/test.js bin/suitcss",
4748
"watch": "mocha --watch --reporter spec --slow 400"
4849
},

test/test.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
var expect = require('chai').expect;
1+
var chai = require('chai');
22
var sinon = require('sinon');
33
var child = require('child_process');
44
var exec = child.exec;
55
var fs = require('fs');
66
var rewire = require('rewire');
77
var suitcss = rewire('../lib');
88
var path = require('path');
9+
var sinonChai = require('sinon-chai');
10+
11+
chai.use(sinonChai);
12+
var expect = chai.expect;
913

1014
/**
1115
* Node API tests.
@@ -56,7 +60,7 @@ describe('suitcss', function() {
5660
expect(opts.lint).to.be.true;
5761
});
5862

59-
it('should allow an minify option to be set', function() {
63+
it('should allow a minify option to be set', function() {
6064
var opts = mergeOptions({minify: true});
6165
expect(opts.minify).to.be.true;
6266
});
@@ -148,7 +152,7 @@ describe('suitcss', function() {
148152

149153
describe('stylelint', function() {
150154
it('should check the input conforms to SUIT style rules', function(done) {
151-
suitcss('@import ./stylelint.css', {
155+
suitcss('@import "./stylelint.css"', {
152156
lint: true,
153157
root: 'test/fixtures',
154158
'postcss-reporter': {
@@ -163,53 +167,50 @@ describe('suitcss', function() {
163167
});
164168
});
165169

166-
describe('beforeLint option', function() {
167-
var lintImportedFilesStub, bemLintStub, beforeLintStub, revert;
170+
describe('transforming css before linting', function() {
171+
var lintImportedFilesStub, beforeLintStub, revert;
168172

169173
beforeEach(function() {
170-
lintImportedFilesStub = sinon.stub();
171-
bemLintStub = sinon.stub().returns('/* lint */');
172-
beforeLintStub = sinon.stub().returns('/* before lint */');
173-
174-
lintImportedFilesStub.onFirstCall().returns(bemLintStub);
174+
lintImportedFilesStub = sinon.stub().returns('/*linting done*/');
175+
beforeLintStub = sinon.stub().returns('/*before lint*/');
175176
revert = suitcss.__set__('lintImportedFiles', lintImportedFilesStub);
176177
});
177178

178179
afterEach(function() {
179180
revert();
180181
});
181182

182-
it('should call user supplied function before linting', function(done) {
183+
it('should call `beforeLint` function before linting', function(done) {
183184
suitcss(read('fixtures/component'), {
184185
root: 'test/fixtures',
185186
beforeLint: beforeLintStub
186187
}).catch(done);
187188

188-
expect(bemLintStub.calledOnce).to.be.ok;
189-
expect(beforeLintStub.calledOnce).to.be.ok;
190-
expect(beforeLintStub.calledBefore(bemLintStub)).to.be.ok;
189+
expect(lintImportedFilesStub).to.be.calledOnce;
190+
expect(beforeLintStub).to.be.calledOnce;
191+
expect(beforeLintStub).to.have.been.calledBefore(lintImportedFilesStub);
191192

192193
done();
193194
});
194195

195-
it('should pass processed CSS to the linting transform function', function(done) {
196+
it('should pass the result of `beforeLint` to `lintImportedFiles`', function(done) {
196197
suitcss(read('fixtures/component'), {
197198
root: 'test/fixtures',
198199
beforeLint: beforeLintStub
199200
}).catch(done);
200201

201-
expect(bemLintStub.args[0][0]).to.equal('/* before lint */');
202+
expect(lintImportedFilesStub.args[0][1]).to.equal('/*before lint*/');
202203

203204
done();
204205
});
205206

206-
it('should pass the merged options to the beforeLint function', function(done) {
207+
it('should pass the options object to the beforeLint function as the third parameter', function(done) {
207208
suitcss(read('fixtures/component'), {
208209
root: 'test/fixtures',
209210
beforeLint: beforeLintStub
210211
}).catch(done);
211212

212-
expect(beforeLintStub.args[0][2].root).to.equal('test/fixtures');
213+
expect(beforeLintStub.args[0][2]).to.contain({root: 'test/fixtures'});
213214

214215
done();
215216
});

0 commit comments

Comments
 (0)