Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
68 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,140 +1,144 @@ | ||
var should = require('should'); | ||
var gutil = require('gulp-util'); | ||
var preprocess = require('../'); | ||
var fs = require('fs'); | ||
var should = require("should"); | ||
var gutil = require("gulp-util"); | ||
var preprocess = require("../"); | ||
var fs = require("fs"); | ||
|
||
require('mocha'); | ||
require("mocha"); | ||
|
||
function fixtureFile(fileName) { | ||
return new gutil.File({ | ||
base: 'test/fixtures', | ||
cwd: 'test/', | ||
path: 'test/fixtures/' + fileName, | ||
contents: fs.readFileSync('test/fixtures/' + fileName) | ||
base: "test/fixtures", | ||
cwd: "test/", | ||
path: "test/fixtures/" + fileName, | ||
contents: fs.readFileSync("test/fixtures/" + fileName) | ||
}); | ||
}; | ||
} | ||
|
||
process.env['FAKEHOME'] = '/Users/jas'; | ||
process.env["FAKEHOME"] = "/Users/jas"; | ||
|
||
describe('gulp-preprocess', function(){ | ||
describe('preprocess()', function(){ | ||
|
||
it('should preprocess html', function(done){ | ||
describe("gulp-preprocess", function() { | ||
describe("preprocess()", function() { | ||
it("should preprocess html", function(done) { | ||
var stream = preprocess({ | ||
context: { | ||
firstOption: 'bar', | ||
secondOption: 'foo' | ||
firstOption: "bar", | ||
secondOption: "foo" | ||
} | ||
}); | ||
|
||
var fakeFile = fixtureFile('test.html'); | ||
var fakeFile = fixtureFile("test.html"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.html', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test.html", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
it('should preprocess javascript', function(done){ | ||
it("should preprocess javascript", function(done) { | ||
var stream = preprocess({ | ||
context: { | ||
firstOption: 'bar', | ||
secondOption: 'foo' | ||
firstOption: "bar", | ||
secondOption: "foo" | ||
} | ||
}); | ||
|
||
var fakeFile = fixtureFile('test.js'); | ||
var fakeFile = fixtureFile("test.js"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.js', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test.js", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
it('should preprocess coffeescript', function(done){ | ||
it("should preprocess coffeescript", function(done) { | ||
var stream = preprocess({ | ||
context: { | ||
firstOption: 'bar', | ||
secondOption: 'foo' | ||
firstOption: "bar", | ||
secondOption: "foo" | ||
} | ||
}); | ||
|
||
var fakeFile = fixtureFile('test.coffee'); | ||
var fakeFile = fixtureFile("test.coffee"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.coffee', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test.coffee", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
it('should preprocess without options object', function(done){ | ||
it("should preprocess without options object", function(done) { | ||
var stream = preprocess(); | ||
|
||
var fakeFile = fixtureFile('test.coffee'); | ||
var fakeFile = fixtureFile("test.coffee"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.coffee', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test.coffee", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
it('should preprocess html with custom base', function(done){ | ||
it("should preprocess html with custom base", function(done) { | ||
var stream = preprocess({ | ||
includeBase: 'test/fixtures/base', | ||
includeBase: "test/fixtures/base", | ||
context: { | ||
firstOption: 'bar', | ||
secondOption: 'foo' | ||
firstOption: "bar", | ||
secondOption: "foo" | ||
} | ||
}); | ||
|
||
var fakeFile = fixtureFile('test.html'); | ||
var fakeFile = fixtureFile("test.html"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test-base.html', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test-base.html", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
it('should allow custom extension', function(done){ | ||
it("should allow custom extension", function(done) { | ||
var stream = preprocess({ | ||
extension: 'html', | ||
extension: "html", | ||
context: { | ||
firstOption: 'bar', | ||
secondOption: 'foo' | ||
firstOption: "bar", | ||
secondOption: "foo" | ||
} | ||
}); | ||
|
||
var fakeFile = fixtureFile('test.php'); | ||
var fakeFile = fixtureFile("test.php"); | ||
|
||
stream.once('data', function(newFile){ | ||
stream.once("data", function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.html', 'utf8')); | ||
String(newFile.contents).should.equal( | ||
fs.readFileSync("test/expected/test.html", "utf8") | ||
); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
|
||
}); | ||
|
||
}); | ||
}); |