diff --git a/index.js b/index.js
index b064bdf1..8fa1f310 100644
--- a/index.js
+++ b/index.js
@@ -3,9 +3,9 @@ var gutil = require('gulp-util');
var through = require('through2');
var juice = require('juice2');
-module.exports = function(opt){
+module.exports = function(main_opt){
return through.obj(function (file, enc, cb) {
- opt = opt || {};
+ var opt = JSON.parse(JSON.stringify(main_opt || {}));
// 'url' option is required
// set it automatically if not provided
diff --git a/test/expected/multiple/one/out.html b/test/expected/multiple/one/out.html
new file mode 100644
index 00000000..6a367580
--- /dev/null
+++ b/test/expected/multiple/one/out.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ Hi
+
+
+
+
diff --git a/test/expected/multiple/two/out.html b/test/expected/multiple/two/out.html
new file mode 100644
index 00000000..3e853750
--- /dev/null
+++ b/test/expected/multiple/two/out.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ Hi
+
+
+
+
diff --git a/test/fixtures/multiple/one/file.css b/test/fixtures/multiple/one/file.css
new file mode 100644
index 00000000..b7d86eea
--- /dev/null
+++ b/test/fixtures/multiple/one/file.css
@@ -0,0 +1,13 @@
+body {
+ font-family: Arial;
+}
+h1 {
+ color: blue;
+}
+.headline {
+ font-size: 24px;
+}
+
+td {
+ padding: 5px;
+}
diff --git a/test/fixtures/multiple/one/in.html b/test/fixtures/multiple/one/in.html
new file mode 100644
index 00000000..2179df35
--- /dev/null
+++ b/test/fixtures/multiple/one/in.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ Hi
+
+
+
diff --git a/test/fixtures/multiple/two/file.css b/test/fixtures/multiple/two/file.css
new file mode 100644
index 00000000..ee08e95d
--- /dev/null
+++ b/test/fixtures/multiple/two/file.css
@@ -0,0 +1,13 @@
+body {
+ font-family: Arial;
+}
+h1 {
+ color: red;
+}
+.headline {
+ font-size: 24px;
+}
+
+td {
+ padding: 5px;
+}
diff --git a/test/fixtures/multiple/two/in.html b/test/fixtures/multiple/two/in.html
new file mode 100644
index 00000000..2179df35
--- /dev/null
+++ b/test/fixtures/multiple/two/in.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ Hi
+
+
+
diff --git a/test/main.js b/test/main.js
index 8e51ec31..25616971 100644
--- a/test/main.js
+++ b/test/main.js
@@ -7,15 +7,18 @@ var path = require('path');
var gutil = require('gulp-util');
var inlineCss = require('../index');
-function compare(input, options, done) {
+function compare(inputPath, outputPath, options, done) {
+
+ var input = fs.readFileSync(inputPath);
+
var fakeFile = new gutil.File({
- path: path.resolve('./test/fixtures/in.html'),
+ path: path.resolve('./'+inputPath),
cwd: './test/',
base: './test/fixtures/',
contents: new Buffer(String(input))
});
- var output = fs.readFileSync(path.join('test', 'expected', 'out.html'));
+ var output = fs.readFileSync(outputPath);
// Create a plugin stream
var stream = inlineCss(options);
@@ -36,8 +39,19 @@ function compare(input, options, done) {
describe('gulp-inline-css', function() {
it('Should convert linked css to inline css', function(done) {
- var input = fs.readFileSync(path.join('test', 'fixtures', 'in.html'));
+ var inputPath = path.join('test', 'fixtures', 'in.html');
+ var outputPath = path.join('test', 'expected', 'out.html');
var options = {};
- compare(input, options, done);
+ compare(inputPath, outputPath, options, done);
});
-});
\ No newline at end of file
+ it('Should handle multiple HTML files with relative stylesheets', function(done){
+ var one = path.join('test', 'fixtures', 'multiple', 'one', 'in.html');
+ var two = path.join('test', 'fixtures', 'multiple', 'two', 'in.html');
+ var options = {};
+ var doneCount = 0;
+ var bothDone = function(){ doneCount++; if(doneCount == 2){ done(); } };
+ compare(one, path.join('test', 'expected', 'multiple', 'one', 'out.html'), options, bothDone);
+ compare(two, path.join('test', 'expected', 'multiple', 'two', 'out.html'), options, bothDone);
+ });
+});
+