-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from joeybaker/add-streaming
fix #17: add a stream output option
- Loading branch information
Showing
6 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
._simple_styles__foo { | ||
color: #F00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../simple/main.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var tape = require('tape'); | ||
|
||
var browserify = require('browserify'); | ||
var proxyquire = require('proxyquire'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var casesDir = path.join(__dirname, 'cases'); | ||
var simpleCaseDir = path.join(casesDir, 'simple'); | ||
var cssFilesTotal = 1; | ||
var cssOutFilename = 'out.css'; | ||
|
||
tape('stream output', function (t) { | ||
var fakeFs = { | ||
writeFile: function (filename, content, cb) { | ||
var expected = fs.readFileSync(path.join(simpleCaseDir, 'expected.css'), 'utf8'); | ||
|
||
t.equal(filename, cssOutFilename, 'correct output filename'); | ||
t.equal(content, expected, 'output matches expected'); | ||
cb(); | ||
} | ||
}; | ||
|
||
var cssModulesify = proxyquire('../', { | ||
fs: fakeFs | ||
}); | ||
|
||
t.plan(cssFilesTotal * 2 + 1); | ||
|
||
var cssFilesCount = 0; | ||
browserify(path.join(simpleCaseDir, 'main.js')) | ||
.plugin(cssModulesify, { | ||
rootDir: path.join(simpleCaseDir) | ||
}) | ||
.on('error', t.error) | ||
.bundle(function noop () {}) | ||
.on('css stream', function (stream) { | ||
stream | ||
.on('data', function onData (css) { | ||
var cssString = css.toString(); | ||
// just get the first class name, use that as an id | ||
var cssId = cssString.split('\n')[0].split(' ')[0]; | ||
|
||
t.ok( | ||
++cssFilesCount <= cssFilesTotal | ||
, 'emits data for ' + cssId | ||
); | ||
|
||
t.ok( | ||
cssString.indexOf('._styles') === 0 | ||
, 'emits compiled css for ' + cssId | ||
); | ||
}) | ||
.on('end', function onEnd () { | ||
t.pass('ends the stream'); | ||
}) | ||
.on('error', t.error); | ||
}); | ||
}); |