initial commit
This commit is contained in:
40
node_modules/preprocess/test/context.spec.js
generated
vendored
Normal file
40
node_modules/preprocess/test/context.spec.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('preprocess context', function () {
|
||||
var input;
|
||||
|
||||
it('default to env if not provided', function () {
|
||||
input = "a<!-- @echo FINGERPRINT -->c";
|
||||
process.env.FINGERPRINT = '0xDEADBEEF';
|
||||
|
||||
pp.preprocess(input).should.equal("a0xDEADBEEFc");
|
||||
});
|
||||
|
||||
describe('in nested cases', function () {
|
||||
var context = {'FOO': {'BAR': 'test'}};
|
||||
|
||||
it('and resolve path-s and echo content to nested attrs', function () {
|
||||
input = "// @echo FOO.BAR";
|
||||
pp.preprocess(input, context, 'js').should.equal("test");
|
||||
});
|
||||
|
||||
it('and maintain backwards compatibility', function () {
|
||||
input = "// @echo FOO";
|
||||
pp.preprocess(input, context, 'js').should.equal("[object Object]");
|
||||
});
|
||||
|
||||
it('and be able to compare nested context attrs', function () {
|
||||
input = "a\n" +
|
||||
"// @if FOO.BAR=='test' \n" +
|
||||
"b\n" +
|
||||
"// @endif \n" +
|
||||
"c";
|
||||
pp.preprocess(input, context, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
121
node_modules/preprocess/test/echo.spec.js
generated
vendored
Normal file
121
node_modules/preprocess/test/echo.spec.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@echo directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('and resolve and echo variables', function () {
|
||||
input = "a<!-- @echo FINGERPRINT -->c";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}).should.equal("a0xDEADBEEFc");
|
||||
});
|
||||
|
||||
it('and echo strings', function () {
|
||||
input = "a<!-- @echo '-FOO*' -->c";
|
||||
pp.preprocess(input).should.equal("a-FOO*c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and resolve and echo variables (block)', function () {
|
||||
input = "a/* @echo FINGERPRINT */c";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a0xDEADBEEFc");
|
||||
});
|
||||
|
||||
it('and echo strings (block)', function () {
|
||||
input = "a/* @echo '-FOO*' */c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a-FOO*c");
|
||||
});
|
||||
|
||||
it('and resolve and echo variables (line)', function () {
|
||||
input = "a\n// @echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
|
||||
it('and echo strings (line)', function () {
|
||||
input = "a\n// @echo '-FOO*'\nc";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\n-FOO*\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in plain text files', function () {
|
||||
it('and resolve and echo variables', function () {
|
||||
input = "a\n@echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'simple').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
|
||||
it('and echo strings', function () {
|
||||
input = "a\n@echo '-FOO*'\nc";
|
||||
pp.preprocess(input, {}, 'simple').should.equal("a\n-FOO*\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and resolve and echo variables', function () {
|
||||
input = "a\n# @echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'coffee').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
|
||||
it('and resolve and echo variables (multiple hashes)', function () {
|
||||
input = "a\n## @echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'coffee').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
|
||||
it('and echo strings', function () {
|
||||
input = "a\n# @echo '-FOO*'\nc";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\n-FOO*\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with multiple @echo directives inline in html/js', function () {
|
||||
var input;
|
||||
|
||||
it('without overreaching', function () {
|
||||
input = "a<!-- @echo FOO -->b<!-- @echo BAR -->c";
|
||||
pp.preprocess(input, {FOO: 1, BAR: 2}).should.equal("a1b2c");
|
||||
});
|
||||
|
||||
it('without overreaching (js)', function () {
|
||||
input = "a/* @echo FOO */b/* @echo BAR */c";
|
||||
pp.preprocess(input, {FOO: 1, BAR: 2}, 'js').should.equal("a1b2c");
|
||||
});
|
||||
|
||||
it('without overreaching when string param contains `-` and `*` chars ', function () {
|
||||
input = "a<!-- @echo '-*' -->b<!-- @echo '*-' -->c";
|
||||
pp.preprocess(input, {FOO: 1, BAR: 2}).should.equal("a-*b*-c");
|
||||
});
|
||||
|
||||
it('without overreaching when string param contains `-` and `*` chars (js)', function () {
|
||||
input = "a/* @echo '-*' */b/* @echo '*-' */c";
|
||||
pp.preprocess(input, {FOO: 1, BAR: 2}, 'js').should.equal("a-*b*-c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "a<!--@echo FINGERPRINT-->c";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}).should.equal("a0xDEADBEEFc");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "a/*@echo FINGERPRINT*/c";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a0xDEADBEEFc");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "a\n//@echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'js').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "a\n#@echo FINGERPRINT\nc";
|
||||
pp.preprocess(input, {FINGERPRINT: '0xDEADBEEF'}, 'coffee').should.equal("a\n0xDEADBEEF\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
110
node_modules/preprocess/test/exclude.spec.js
generated
vendored
Normal file
110
node_modules/preprocess/test/exclude.spec.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@exclude directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('with default notation', function () {
|
||||
input = "a<!-- @exclude -->b<!-- @endexclude -->c";
|
||||
pp.preprocess(input, {}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('multiple excludes in one line', function () {
|
||||
input = "a<!-- @exclude -->b<!-- @endexclude -->c<!-- @exclude -->d<!-- @endexclude -->e";
|
||||
pp.preprocess(input, {}).should.equal("ace");
|
||||
});
|
||||
|
||||
it('with newlines', function () {
|
||||
input = "a\n<!-- @exclude -->\nb\n<!-- @endexclude -->\nc";
|
||||
pp.preprocess(input, {}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with parameters, if truthy -> exclude', function () {
|
||||
input = "a<!-- @exclude NODE_ENV='production' -->b<!-- @endexclude -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('with parameters, if falsy -> include', function () {
|
||||
input = "a<!-- @exclude NODE_ENV='development' -->b<!-- @endexclude -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('with line comments', function () {
|
||||
input = "a\n// @exclude\nb\n// @endexclude\nc";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with block comments', function () {
|
||||
input = "a/* @exclude */b/* @endexclude */c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("ac");
|
||||
});
|
||||
|
||||
it('multiple excludes in one line', function () {
|
||||
input = "a\n/* @exclude */\nb\n/* @endexclude */\nc";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with parameters, if truthy -> exclude', function () {
|
||||
input = "a\n// @exclude NODE_ENV='production' \nb\n// @endexclude\nc";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with parameters, if falsy -> include', function () {
|
||||
input = "a\n// @exclude NODE_ENV='development' \nb\n// @endexclude\nc";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('with default notation', function () {
|
||||
input = "a\n# @exclude\nb\n# @endexclude\nc";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with multiple hashes', function () {
|
||||
input = "a\n## @exclude\nb\n## @endexclude\nc";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with parameters, if truthy -> exclude', function () {
|
||||
input = "a\n# @exclude NODE_ENV='production'\nb\n# @endexclude\nc";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('with parameters, if falsy -> include', function () {
|
||||
input = "a\n# @exclude NODE_ENV='development'\nb\n# @endexclude\nc";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "a<!--@exclude-->b<!--@endexclude-->c";
|
||||
pp.preprocess(input, {}).should.equal("ac");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "a/*@exclude*/b/*@endexclude*/c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("ac");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "a\n//@exclude\nb\n//@endexclude\nc";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nc");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "a\n#@exclude\nb\n#@endexclude\nc";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
164
node_modules/preprocess/test/exec.spec.js
generated
vendored
Normal file
164
node_modules/preprocess/test/exec.spec.js
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
spies = require("chai-spies"),
|
||||
pp = require('../lib/preprocess'),
|
||||
hello = require('./lib/hello');
|
||||
|
||||
chai.should();
|
||||
chai.use(spies);
|
||||
|
||||
describe('@exec directive shall be preprocessed', function () {
|
||||
var input, helloSpy;
|
||||
|
||||
beforeEach(function(){
|
||||
helloSpy = chai.spy(hello);
|
||||
});
|
||||
|
||||
describe('in html', function () {
|
||||
it('and execute function with one parameter', function () {
|
||||
input = "a<!-- @exec hello('Chuck Norris') -->c";
|
||||
pp.preprocess(input, {hello: helloSpy}).should.equal("aHello Chuck Norris!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters', function () {
|
||||
input = "a<!-- @exec hello(\"Chuck Norris\", 'Gandhi') -->c";
|
||||
pp.preprocess(input, {hello: helloSpy}).should.equal("aHello Chuck Norris,Gandhi!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters: one string and one variable', function () {
|
||||
input = "a<!-- @exec hello(\"Chuck Norris\", buddy) -->c";
|
||||
pp.preprocess(input, {
|
||||
hello: helloSpy,
|
||||
buddy: 'Michael Jackson'
|
||||
}).should.equal("aHello Chuck Norris,Michael Jackson!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Michael Jackson');
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and execute function with one parameter (block)', function () {
|
||||
input = "a/* @exec hello('Chuck Norris') */c";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("aHello Chuck Norris!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters (block)', function () {
|
||||
input = "a/* @exec hello(\"Chuck Norris\", 'Gandhi') */c";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("aHello Chuck Norris,Gandhi!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters: one string and one variable (block)', function () {
|
||||
input = "a/* @exec hello(\"Chuck Norris\", buddy) */c";
|
||||
pp.preprocess(input, {
|
||||
hello: helloSpy,
|
||||
buddy: 'Michael Jackson'
|
||||
}, 'js').should.equal("aHello Chuck Norris,Michael Jackson!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Michael Jackson');
|
||||
});
|
||||
|
||||
it('and execute function with one parameter (line)', function () {
|
||||
input = "a\n// @exec hello('Chuck Norris')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("a\nHello Chuck Norris!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters (line)', function () {
|
||||
input = "a\n// @exec hello(\"Chuck Norris\", 'Gandhi')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("a\nHello Chuck Norris,Gandhi!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters: one string and one variable (line)', function () {
|
||||
input = "a\n// @exec hello(\"Chuck Norris\", buddy)\nc";
|
||||
pp.preprocess(input, {
|
||||
hello: helloSpy,
|
||||
buddy: 'Michael Jackson'
|
||||
}, 'js').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Michael Jackson');
|
||||
});
|
||||
});
|
||||
|
||||
describe('in plain text files', function () {
|
||||
it('and execute function with one parameter', function () {
|
||||
input = "a\n@exec hello('Chuck Norris')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'simple').should.equal("a\nHello Chuck Norris!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters', function () {
|
||||
input = "a\n@exec hello(\"Chuck Norris\", 'Gandhi')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'simple').should.equal("a\nHello Chuck Norris,Gandhi!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters: one string and one variable', function () {
|
||||
input = "a\n@exec hello(\"Chuck Norris\", buddy)\nc";
|
||||
pp.preprocess(input, {
|
||||
hello: helloSpy,
|
||||
buddy: 'Michael Jackson'
|
||||
}, 'simple').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Michael Jackson');
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and execute function with one parameter', function () {
|
||||
input = "a\n# @exec hello('Chuck Norris')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'coffee').should.equal("a\nHello Chuck Norris!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters', function () {
|
||||
input = "a\n# @exec hello(\"Chuck Norris\", 'Gandhi')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'coffee').should.equal("a\nHello Chuck Norris,Gandhi!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters (multiple hashes)', function () {
|
||||
input = "a\n## @exec hello(\"Chuck Norris\", 'Gandhi')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'coffee').should.equal("a\nHello Chuck Norris,Gandhi!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Gandhi');
|
||||
});
|
||||
|
||||
it('and execute function with two parameters: one string and one variable', function () {
|
||||
input = "a\n# @exec hello(\"Chuck Norris\", buddy)\nc";
|
||||
pp.preprocess(input, {
|
||||
hello: helloSpy,
|
||||
buddy: 'Michael Jackson'
|
||||
}, 'coffee').should.equal("a\nHello Chuck Norris,Michael Jackson!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris', 'Michael Jackson');
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "a<!-- @exec hello('Chuck Norris') -->c";
|
||||
pp.preprocess(input, {hello: helloSpy}).should.equal("aHello Chuck Norris!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "a/*@exec hello('Chuck Norris')*/c";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("aHello Chuck Norris!c");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "a\n//@exec hello('Chuck Norris')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'js').should.equal("a\nHello Chuck Norris!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "a\n#@exec hello('Chuck Norris')\nc";
|
||||
pp.preprocess(input, {hello: helloSpy}, 'coffee').should.equal("a\nHello Chuck Norris!\nc");
|
||||
helloSpy.should.have.been.called.with('Chuck Norris');
|
||||
});
|
||||
});
|
||||
});
|
||||
95
node_modules/preprocess/test/extend.spec.js
generated
vendored
Normal file
95
node_modules/preprocess/test/extend.spec.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@extend directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('and extend files', function () {
|
||||
input = "<!-- @extend extend.html -->qr<!-- @endextend -->";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}).should.equal("aqrb");
|
||||
});
|
||||
|
||||
it('and support nested @extend', function () {
|
||||
input = "<!-- @extend extend.html -->q<!-- @extend extend.html -->x<!-- @endextend -->r<!-- @endextend -->";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}).should.equal("aqaxbrb");
|
||||
});
|
||||
|
||||
it('and extend files with multiple @extend-s in one line', function () {
|
||||
input = "x<!-- @extend extend.html -->qr<!-- @endextend -->y<!-- @extend extend.html -->hi<!-- @endextend -->z";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}).should.equal("xaqrbyahibz");
|
||||
});
|
||||
|
||||
it('and should strip newlines from inserted content', function () {
|
||||
input = "<!-- @extend extend.html -->\nqa\n<!-- @endextend -->";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}).should.equal("aqab");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and extend files (block)', function () {
|
||||
input = "/* @extend extend.js */qr/* @endextend */";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("aqrb");
|
||||
});
|
||||
|
||||
it('and extend files with multiple @extend-s in one line (block)', function () {
|
||||
input = "x/* @extend extend.js */qr/* @endextend */y/* @extend extend.js */hi/* @endextend */z";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("xaqrbyahibz");
|
||||
});
|
||||
|
||||
it('and should strip newlines from inserted content (block)', function () {
|
||||
input = "/* @extend extend.js */\nqa\n/* @endextend */";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("aqab");
|
||||
});
|
||||
|
||||
it('and should strip newlines from inserted content (line)', function () {
|
||||
input = "// @extend extend.js\nqr\n// @endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("aqrb");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and extend files', function () {
|
||||
input = "# @extend extend.coffee\nqr\n# @endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'coffee').should.equal("a\nqr\nb");
|
||||
});
|
||||
|
||||
it('and should strip newlines from inserted content', function () {
|
||||
input = "# @extend extend.coffee\nqr\n# @endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'coffee').should.equal("a\nqr\nb");
|
||||
});
|
||||
|
||||
it('and should strip newlines from inserted content (multiple hashes)', function () {
|
||||
input = "## @extend extend.coffee\nqr\n## @endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'coffee').should.equal("a\nqr\nb");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "<!--@extend extend.html-->qr<!--@endextend-->";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}).should.equal("aqrb");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "/*@extend extend.js*/qr/*@endextend*/";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("aqrb");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "//@extend extend.js\nqr\n//@endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'js').should.equal("aqrb");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "#@extend extend.coffee\nqr\n#@endextend";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/extend'}, 'coffee').should.equal("a\nqr\nb");
|
||||
});
|
||||
});
|
||||
});
|
||||
3
node_modules/preprocess/test/fixtures/extend/extend.coffee
generated
vendored
Normal file
3
node_modules/preprocess/test/fixtures/extend/extend.coffee
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
a
|
||||
# @extendable
|
||||
b
|
||||
1
node_modules/preprocess/test/fixtures/extend/extend.html
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/extend/extend.html
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a<!-- @extendable -->b
|
||||
1
node_modules/preprocess/test/fixtures/extend/extend.js
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/extend/extend.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a/* @extendable */b
|
||||
1
node_modules/preprocess/test/fixtures/extend/extendadv.html
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/extend/extendadv.html
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a
|
||||
2
node_modules/preprocess/test/fixtures/include/include.block.js
generated
vendored
Normal file
2
node_modules/preprocess/test/fixtures/include/include.block.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
!foobar!/* @exec hello('js') */
|
||||
/* @include static.txt */
|
||||
3
node_modules/preprocess/test/fixtures/include/include.coffee
generated
vendored
Normal file
3
node_modules/preprocess/test/fixtures/include/include.coffee
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
!foobar!
|
||||
# @exec hello('coffee')
|
||||
# @include static.txt
|
||||
1
node_modules/preprocess/test/fixtures/include/include.html
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/include/include.html
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!foobar!<!-- @exec hello('html') --><!-- @include static.txt -->
|
||||
3
node_modules/preprocess/test/fixtures/include/include.js
generated
vendored
Normal file
3
node_modules/preprocess/test/fixtures/include/include.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
!foobar!
|
||||
// @exec hello('js')
|
||||
// @include static.txt
|
||||
3
node_modules/preprocess/test/fixtures/include/include.txt
generated
vendored
Normal file
3
node_modules/preprocess/test/fixtures/include/include.txt
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
!foobar!
|
||||
@exec hello('simple')
|
||||
@include static.txt
|
||||
1
node_modules/preprocess/test/fixtures/include/includenewline.txt
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/include/includenewline.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!foobar!
|
||||
1
node_modules/preprocess/test/fixtures/include/static.txt
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/include/static.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!bazqux!
|
||||
1
node_modules/preprocess/test/fixtures/processFile/processFileTest.html
generated
vendored
Normal file
1
node_modules/preprocess/test/fixtures/processFile/processFileTest.html
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a<!-- @echo TEST -->b
|
||||
3
node_modules/preprocess/test/fixtures/processFile/processFileTestInclude.html
generated
vendored
Normal file
3
node_modules/preprocess/test/fixtures/processFile/processFileTestInclude.html
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
a
|
||||
<!-- @include processFileTest.html -->
|
||||
b
|
||||
221
node_modules/preprocess/test/foreach.spec.js
generated
vendored
Normal file
221
node_modules/preprocess/test/foreach.spec.js
generated
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@foreach directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('with array as input', function () {
|
||||
describe('in html', function () {
|
||||
it('and run basic loop with one item (array toString() form)', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->$ITEM<!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: ['a'].toString()}).should.equal("a");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items (array toString() form)', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->$ITEM<!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}).should.equal("ab");
|
||||
});
|
||||
|
||||
it('and run basic loop (JSON-like array form)', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->$ITEM<!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: "['a','b']"}).should.equal("ab");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and run basic loop with multiple items (array toString() form, block)', function () {
|
||||
input = "/* @foreach $ITEM in LIST */$ITEM/* @endfor */";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("ab");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items (array toString() form, line)', function () {
|
||||
input = "// @foreach $ITEM in LIST\n$ITEM\n// @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("a\nb\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and run basic loop with multiple items (array toString() form)', function () {
|
||||
input = "# @foreach $ITEM in LIST\n$ITEM\n# @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\nb\n");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items (array toString() form, multiple hashes)', function () {
|
||||
input = "## @foreach $ITEM in LIST\n$ITEM\n## @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\nb\n");
|
||||
});
|
||||
});
|
||||
|
||||
it('and support nested @foreach in javascript', function () {
|
||||
input = "/* @foreach $ITEMA in LIST *//* @foreach $ITEMB in LIST */$ITEMA$ITEMB/* @endfor *//* @endfor */";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("aaabbabb");
|
||||
});
|
||||
|
||||
it('and support nested @foreach in coffeescript', function () {
|
||||
input = "## @foreach $ITEMA in LIST \n## @foreach $ITEMB in LIST \n$ITEMA$ITEMB\n## @endfor \n## @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("aa\nab\nba\nbb\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with object as input', function () {
|
||||
describe('in html', function () {
|
||||
it('and run basic loop just repeating content', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->ab<!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}).should.equal("abab");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->$ITEM<!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}).should.equal("ab");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and run basic loop with multiple items (block)', function () {
|
||||
input = "/* @foreach $ITEM in LIST */$ITEM/* @endfor */";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}, 'js').should.equal("ab");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items (line)', function () {
|
||||
input = "// @foreach $ITEM in LIST\n$ITEM\n// @endfor";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}, 'js').should.equal("a\nb\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and run basic loop with multiple items', function () {
|
||||
input = "# @foreach $ITEM in LIST\n$ITEM\n# @endfor";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}, 'coffee').should.equal("a\nb\n");
|
||||
});
|
||||
|
||||
it('and run basic loop with multiple items (multiple hashes)', function () {
|
||||
input = "## @foreach $ITEM in LIST\n$ITEM\n## @endfor";
|
||||
pp.preprocess(input, {LIST: '{"itemOne": "a", "itemTwo": "b"}'}, 'coffee').should.equal("a\nb\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with mixed input', function () {
|
||||
describe('in html', function () {
|
||||
it('duplicate loop with @echo variable included in each', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST --><div class='<!-- @echo LIST_CLASS -->'>$ITEM</div><!-- @endfor -->";
|
||||
pp.preprocess(input, {
|
||||
LIST: ['a', 'b'].toString(),
|
||||
LIST_CLASS: 'list'
|
||||
}).should.equal("<div class='list'>a</div><div class='list'>b</div>");
|
||||
});
|
||||
|
||||
it('loop with @ifdef', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->a<!-- @ifdef NOVAR -->$ITEM<!-- @endif --><!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}).should.equal("aa");
|
||||
});
|
||||
|
||||
it('loop with @ifndef', function () {
|
||||
input = "<!-- @foreach $ITEM in LIST -->a<!-- @ifndef NOVAR -->$ITEM<!-- @endif --><!-- @endfor -->";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}).should.equal("aaab");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('duplicate loop with @echo variable included in each (block)', function () {
|
||||
input = "/* @foreach $ITEM in LIST *//* @echo LIST_CLASS */$ITEM/* @endfor */";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString(), LIST_CLASS: 'list'}, 'js').should.equal("listalistb");
|
||||
});
|
||||
|
||||
it('loop with @ifdef (block)', function () {
|
||||
input = "/* @foreach $ITEM in LIST */a/* @ifdef NOVAR */$ITEM/* @endif *//* @endfor */";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("aa");
|
||||
});
|
||||
|
||||
it('loop with @ifndef (block)', function () {
|
||||
input = "/* @foreach $ITEM in LIST */a/* @ifndef NOVAR */$ITEM/* @endif *//* @endfor */";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("aaab");
|
||||
});
|
||||
|
||||
it('duplicate loop with @echo variable included in each (line)', function () {
|
||||
input = "// @foreach $ITEM in LIST\n// @echo LIST_CLASS\n$ITEM\n// @endfor";
|
||||
pp.preprocess(input, {
|
||||
LIST: ['a', 'b'].toString(),
|
||||
LIST_CLASS: 'list'
|
||||
}, 'js').should.equal("list\na\nlist\nb\n");
|
||||
});
|
||||
|
||||
it('loop with @ifdef (line)', function () {
|
||||
input = "// @foreach $ITEM in LIST\na\n// @ifdef NOVAR\n$ITEM\n// @endif\n// @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("a\na\n");
|
||||
});
|
||||
|
||||
it('loop with @ifndef (line)', function () {
|
||||
input = "// @foreach $ITEM in LIST\na\n// @ifndef NOVAR\n$ITEM\n// @endif\n// @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'js').should.equal("a\na\na\nb\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('duplicate loop with @echo variable included in each', function () {
|
||||
input = "# @foreach $ITEM in LIST\n# @echo LIST_CLASS\n$ITEM\n# @endfor";
|
||||
pp.preprocess(input, {
|
||||
LIST: ['a', 'b'].toString(),
|
||||
LIST_CLASS: 'list'
|
||||
}, 'coffee').should.equal("list\na\nlist\nb\n");
|
||||
});
|
||||
|
||||
it('duplicate loop with @echo variable included in each (multiple hashes)', function () {
|
||||
input = "## @foreach $ITEM in LIST\n## @echo LIST_CLASS\n$ITEM\n## @endfor";
|
||||
pp.preprocess(input, {
|
||||
LIST: ['a', 'b'].toString(),
|
||||
LIST_CLASS: 'list'
|
||||
}, 'coffee').should.equal("list\na\nlist\nb\n");
|
||||
});
|
||||
|
||||
it('loop with @ifdef', function () {
|
||||
input = "# @foreach $ITEM in LIST\na\n# @ifdef NOVAR\n$ITEM\n# @endif\n# @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\na\n");
|
||||
});
|
||||
|
||||
it('loop with @ifdef (multiple hashes)', function () {
|
||||
input = "## @foreach $ITEM in LIST\na\n## @ifdef NOVAR\n$ITEM\n## @endif\n## @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\na\n");
|
||||
});
|
||||
|
||||
it('loop with @ifndef', function () {
|
||||
input = "# @foreach $ITEM in LIST\na\n# @ifndef NOVAR\n$ITEM\n# @endif\n# @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\na\na\nb\n");
|
||||
});
|
||||
|
||||
it('loop with @ifndef (multiple hashes)', function () {
|
||||
input = "## @foreach $ITEM in LIST\na\n## @ifndef NOVAR\n$ITEM\n## @endif\n## @endfor";
|
||||
pp.preprocess(input, {LIST: ['a', 'b'].toString()}, 'coffee').should.equal("a\na\na\nb\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "<!--@foreach $ITEM in LIST-->$ITEM<!--@endfor-->";
|
||||
pp.preprocess(input, {LIST: ['a'].toString()}).should.equal("a");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "/*@foreach $ITEM in LIST*/$ITEM/*@endfor*/";
|
||||
pp.preprocess(input, {LIST: ['a'].toString()}, 'js').should.equal("a");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "//@foreach $ITEM in LIST\n$ITEM\n//@endfor";
|
||||
pp.preprocess(input, {LIST: ['a'].toString()}, 'js').should.equal("a\n");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "#@foreach $ITEM in LIST\n$ITEM\n#@endfor";
|
||||
pp.preprocess(input, {LIST: ['a'].toString()}, 'coffee').should.equal("a\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
123
node_modules/preprocess/test/hidden-by-default.spec.js
generated
vendored
Normal file
123
node_modules/preprocess/test/hidden-by-default.spec.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
spies = require("chai-spies"),
|
||||
pp = require('../lib/preprocess'),
|
||||
hello = require('./lib/hello');
|
||||
|
||||
chai.should();
|
||||
chai.use(spies);
|
||||
|
||||
describe('hidden by default comment blocks shall be preprocessed', function () {
|
||||
var input, helloSpy;
|
||||
|
||||
beforeEach(function(){
|
||||
helloSpy = chai.spy(hello);
|
||||
});
|
||||
|
||||
describe('in html', function () {
|
||||
it('and process @if and exec nested @echo', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @echo 'b' !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'html').should.equal("a bc");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @exec', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @exec hello('b') !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', hello: helloSpy}, 'html').should.equal("a Hello b!c");
|
||||
helloSpy.should.have.been.called.with('b');
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @include', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @include static.txt !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/include'}, 'html').should.equal("a !bazqux!c");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @include-static', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @include-static static.txt !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/include'}, 'html').should.equal("a !bazqux!c");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @exclude', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @exclude !> b <!-- @endexclude !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'html').should.equal("ac");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @extend', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @extend extend.html !>c<!-- @endextend !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'html').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @if', function () {
|
||||
input = "a<!-- @extend extend.html !> <!-- @if NODE_ENV=='dev' !>c<!-- @endif !> <!-- @endextend -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'html').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @ifdef', function () {
|
||||
input = "a<!-- @extend extend.html !> <!-- @ifdef NODE_ENV !>c<!-- @endif !> <!-- @endextend -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'html').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @ifndef', function () {
|
||||
input = "a<!-- @extend extend.html !> <!-- @ifndef NODE_ENV !>c<!-- @endif !> <!-- @endextend -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'html').should.equal("aabc");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @extend', function () {
|
||||
input = "a<!-- @if NODE_ENV=='dev' !> <!-- @foreach $var in ARR !>$var<!-- @endfor !> <!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', ARR: "['b', 'c']"}, 'html').should.equal("abcc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and process @if and exec nested @echo', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @echo 'b' ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("a bc");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @exec', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @exec hello('b') ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', hello: helloSpy}, 'js').should.equal("a Hello b!c");
|
||||
helloSpy.should.have.been.called.with('b');
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @include', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @include static.txt ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/include'}, 'js').should.equal("a !bazqux!c");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @include-static', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @include-static static.txt ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/include'}, 'js').should.equal("a !bazqux!c");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @exclude', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @exclude ** b /* @endexclude ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("ac");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @extend', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @extend extend.js **c/* @endextend ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'js').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @if', function () {
|
||||
input = "a/* @extend extend.js ** /* @if NODE_ENV=='dev' **c/* @endif ** /* @endextend */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'js').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @ifdef', function () {
|
||||
input = "a/* @extend extend.js ** /* @ifdef NODE_ENV **c/* @endif ** /* @endextend */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'js').should.equal("aacbc");
|
||||
});
|
||||
|
||||
it('and process @extend and exec nested @ifndef', function () {
|
||||
input = "a/* @extend extend.js ** /* @ifndef NODE_ENV **c/* @endif ** /* @endextend */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', srcDir: 'test/fixtures/extend'}, 'js').should.equal("aabc");
|
||||
});
|
||||
|
||||
it('and process @if and exec nested @extend', function () {
|
||||
input = "a/* @if NODE_ENV=='dev' ** /* @foreach $var in ARR **$var/* @endfor ** /* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev', ARR: "['b', 'c']"}, 'js').should.equal("abcc");
|
||||
});
|
||||
});
|
||||
});
|
||||
52
node_modules/preprocess/test/if-else.spec.js
generated
vendored
Normal file
52
node_modules/preprocess/test/if-else.spec.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@if/@else directive shall be preprocessed', function () {
|
||||
describe('in html', function () {
|
||||
|
||||
['=', '==', '==='].forEach(function (equalsOp) {
|
||||
describe('and should work with unequality operator `' + equalsOp + '`', function () {
|
||||
|
||||
describe('with common comment syntax', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + equalsOp + "'production' -->\n" +
|
||||
"b\n" +
|
||||
"<!-- @else -->\n" +
|
||||
"c\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"d";
|
||||
|
||||
it('and exclude second block if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nb\nd");
|
||||
});
|
||||
|
||||
it('and exclude first block if condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nc\nd");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should support nesting', function () {
|
||||
var input = "a\n" +
|
||||
"// @ifdef FLAG\n" +
|
||||
"b\n" +
|
||||
"// @ifdef FLAG2\n" +
|
||||
"bad\n" +
|
||||
"// @else\n" +
|
||||
"c\n" +
|
||||
"// @endif\n" +
|
||||
"d\n" +
|
||||
"// @else\n" +
|
||||
"equally bad\n" +
|
||||
"// @endif\n" +
|
||||
"e";
|
||||
pp.preprocess(input, {FLAG: 1}, 'js').should.equal("a\nb\nc\nd\ne");
|
||||
});
|
||||
});
|
||||
});
|
||||
362
node_modules/preprocess/test/if.spec.js
generated
vendored
Normal file
362
node_modules/preprocess/test/if.spec.js
generated
vendored
Normal file
@@ -0,0 +1,362 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@if directive shall be preprocessed', function () {
|
||||
describe('in html', function () {
|
||||
|
||||
['!=', '!=='].forEach(function (unEqualsOp) {
|
||||
describe('and should work with unequality operator `' + unEqualsOp + '`', function () {
|
||||
describe('with common comment syntax', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + unEqualsOp + "'production' -->\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('with comment hidden by default syntax (end tag)', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + unEqualsOp + "'production' !>\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag and start tag)', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + unEqualsOp + "'production' !>\n" +
|
||||
"b\n" +
|
||||
"<! @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
['=', '==', '==='].forEach(function (equalsOp) {
|
||||
describe('and should work with equality operator `' + equalsOp + '`', function () {
|
||||
describe('with common comment syntax', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + equalsOp + "'production' -->\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag)', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + equalsOp + "'production' !>\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag and start tag)', function () {
|
||||
var input = "a\n" +
|
||||
"<!-- @if NODE_ENV" + equalsOp + "'production' !>\n" +
|
||||
"b\n" +
|
||||
"<! @endif -->\n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
describe('and should work with unequality operator', function () {
|
||||
var input = "a\n" +
|
||||
"// @if NODE_ENV!='production' \n" +
|
||||
"b\n" +
|
||||
"// @endif \n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and should work with equality operator', function () {
|
||||
var input = "a\n" +
|
||||
"// @if NODE_ENV=='production'\n" +
|
||||
"b\n" +
|
||||
"// @endif\n" +
|
||||
"c";
|
||||
|
||||
it('and not exclude when condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("a\nc");
|
||||
});
|
||||
});
|
||||
|
||||
it("should exclude if not match (block)", function () {
|
||||
var input = "a/* @if NODE_ENV=='production' */b/* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("ac");
|
||||
});
|
||||
|
||||
it('should not exclude if match (hidden by default syntax)', function () {
|
||||
var input = "a/* @if NODE_ENV=='production' **b/* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("abc");
|
||||
});
|
||||
|
||||
it('should support nesting (block)', function () {
|
||||
var input = "a/* @if true */b/* @if false */bad/* @endif */c/* @if true */d/* @endif */e/* @endif */f";
|
||||
pp.preprocess(input, {}, 'js').should.equal("abcdef");
|
||||
});
|
||||
|
||||
it('should support nesting (line)', function () {
|
||||
var input = "a\n" +
|
||||
"// @if true\n" +
|
||||
"b\n" +
|
||||
"// @if false\n" +
|
||||
"bad\n" +
|
||||
"// @endif\n" +
|
||||
"c\n" +
|
||||
"// @if true\n" +
|
||||
"d\n" +
|
||||
"// @endif\n" +
|
||||
"e\n" +
|
||||
"// @endif\n" +
|
||||
"f";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nb\nc\nd\ne\nf");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
describe('and should work with unequality operator', function () {
|
||||
var input = "a\n" +
|
||||
"# @if NODE_ENV!='production'\n" +
|
||||
"b\n" +
|
||||
"# @endif \n" +
|
||||
"c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('and not exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and should work with equality operator', function () {
|
||||
var input = "a\n" +
|
||||
"# @if NODE_ENV=='production'\n" +
|
||||
"b\n" +
|
||||
"# @endif\n" +
|
||||
"c";
|
||||
|
||||
it('and not exclude when condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
});
|
||||
|
||||
it('and should not overreach upon matching', function () {
|
||||
var input =
|
||||
" ## @if NODE_ENV == 'development'\n" +
|
||||
" host = 'localhost'\n" +
|
||||
" protocol = 'http'\n" +
|
||||
" port = 3001\n" +
|
||||
" ## @endif\n" +
|
||||
"\n" +
|
||||
" console.log \"Socket info\", protocol, host, port";
|
||||
var expected =
|
||||
" host = 'localhost'\n" +
|
||||
" protocol = 'http'\n" +
|
||||
" port = 3001\n" +
|
||||
"\n" +
|
||||
" console.log \"Socket info\", protocol, host, port";
|
||||
pp.preprocess(input, {NODE_ENV: 'development'}, 'coffee').should.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('in same line in html', function () {
|
||||
describe('and should work with unequality operator', function () {
|
||||
describe('with common comment syntax', function () {
|
||||
var input = "a<!-- @if NODE_ENV!='production' -->b<!-- @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV!='production' !>b<!-- @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag and start tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV!='production' !>b<! @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('and should work with equality operator', function () {
|
||||
describe('with common comment syntax', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' -->b<!-- @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' !>b<!-- @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('with comment hidden by default syntax (end tag and start tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' !>b<! @endif -->c";
|
||||
|
||||
it('and exclude when condition evals to false', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('and not exclude if condition evals to true', function () {
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sequentially following each other in html', function () {
|
||||
it('2 in sequence in common comment syntax', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' -->b<!-- @endif -->c" +
|
||||
"d<!-- @if NODE_ENV=='production' -->e<!-- @endif -->f";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abcdef");
|
||||
});
|
||||
|
||||
it('2 in sequence in hidden by default syntax (end tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' !>b<!-- @endif -->c" +
|
||||
"d<!-- @if NODE_ENV=='production' !>e<!-- @endif -->f";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abcdef");
|
||||
});
|
||||
|
||||
it('2 in sequence in hidden by default syntax (end tag and start tag)', function () {
|
||||
var input = "a<!-- @if NODE_ENV=='production' !>b<! @endif -->c" +
|
||||
"d<!-- @if NODE_ENV=='production' !>e<! @endif -->f";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("abcdef");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
var input;
|
||||
|
||||
it('in html before and after the directive', function () {
|
||||
var input = "<!--@if NODE_ENV=='production'-->b<!--@endif-->";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}).should.equal("b");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "/*@if NODE_ENV=='production'*/b/*@endif*/";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("b");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "//@if NODE_ENV=='production'\n" +
|
||||
"b\n" +
|
||||
"//@endif";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'js').should.equal("b\n");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
var input = "#@if NODE_ENV=='production'\n" +
|
||||
"b\n" +
|
||||
"#@endif";
|
||||
pp.preprocess(input, {NODE_ENV: 'production'}, 'coffee').should.equal("b\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
114
node_modules/preprocess/test/ifdef.spec.js
generated
vendored
Normal file
114
node_modules/preprocess/test/ifdef.spec.js
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@ifdef directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('fail case, should not be included', function () {
|
||||
input = "a<!-- @ifdef NONEXISTANT -->b<!-- @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included', function () {
|
||||
input = "a<!-- @ifdef NODE_ENV -->b<!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (hidden by default syntax, end tag)', function () {
|
||||
input = "a<!-- @ifdef NONEXISTANT !>b<!-- @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included (hidden by default syntax, end tag)', function () {
|
||||
input = "a<!-- @ifdef NODE_ENV !>b<!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (hidden by default syntax, end tag and start tag)', function () {
|
||||
input = "a<!-- @ifdef NONEXISTANT !>b<! @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included (hidden by default syntax, end tag and start tag)', function () {
|
||||
input = "a<!-- @ifdef NODE_ENV !>b<! @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('fail case, should not be included (line)', function () {
|
||||
input = "a\n" +
|
||||
"// @ifdef NONEXISTANT\n" +
|
||||
"b\n" +
|
||||
"// @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('success case, should be included (line)', function () {
|
||||
input = "a\n" +
|
||||
"// @ifdef NODE_ENV\n" +
|
||||
"b\n" +
|
||||
"// @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (block)', function () {
|
||||
input = "a/* @ifdef NONEXISTANT */b/* @endif */c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included (block)', function () {
|
||||
input = "a/* @ifdef NODE_ENV */b/* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("abc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('fail case, should not be included', function () {
|
||||
input = "a\n" +
|
||||
"# @ifdef FLAG\n" +
|
||||
"b\n" +
|
||||
"# @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('success case, should be included', function () {
|
||||
input = "a\n" +
|
||||
"# @ifdef FLAG\n" +
|
||||
"b\n" +
|
||||
"# @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {FLAG: 1}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (multiple hashes)', function () {
|
||||
input = "a\n" +
|
||||
"## @ifdef FLAG\n" +
|
||||
"b\n" +
|
||||
"## @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('should support nesting', function () {
|
||||
input = "a\n" +
|
||||
"# @ifdef FLAG\n" +
|
||||
"b\n" +
|
||||
"# @ifdef FLAG2\n" +
|
||||
"bad\n" +
|
||||
"# @endif\n" +
|
||||
"c\n" +
|
||||
"# @endif\n" +
|
||||
"d";
|
||||
pp.preprocess(input, {FLAG: 1}, 'coffee').should.equal("a\nb\nc\nd");
|
||||
});
|
||||
});
|
||||
});
|
||||
106
node_modules/preprocess/test/ifndef.spec.js
generated
vendored
Normal file
106
node_modules/preprocess/test/ifndef.spec.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@ifndef directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('success case, should be included', function () {
|
||||
input = "a<!-- @ifndef NONEXISTANT -->b<!-- @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included', function () {
|
||||
input = "a<!-- @ifndef NODE_ENV -->b<!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included (hidden by default syntax, end tag)', function () {
|
||||
input = "a<!-- @ifndef NONEXISTANT !>b<!-- @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (hidden by default syntax, end tag)', function () {
|
||||
input = "a<!-- @ifndef NODE_ENV !>b<!-- @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('success case, should be included (hidden by default syntax, end tag and start tag)', function () {
|
||||
input = "a<!-- @ifndef NONEXISTANT !>b<! @endif -->c";
|
||||
pp.preprocess(input, {}).should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (hidden by default syntax, end tag and start tag)', function () {
|
||||
input = "a<!-- @ifndef NODE_ENV !>b<! @endif -->c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("ac");
|
||||
});
|
||||
|
||||
it('should support nesting', function () {
|
||||
input = "a<!-- @ifndef NDEF -->b<!-- @ifndef NODE_ENV -->bad<!-- @endif -->c<!-- @endif -->d";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}).should.equal("abcd");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('success case, should be included (line)', function () {
|
||||
input = "a\n" +
|
||||
"// @ifndef NONEXISTANT\n" +
|
||||
"b\n" +
|
||||
"// @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (line)', function () {
|
||||
input = "a\n" +
|
||||
"// @ifndef NODE_ENV\n" +
|
||||
"b\n" +
|
||||
"// @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("a\nc");
|
||||
});
|
||||
|
||||
it('success case, should be included (block)', function () {
|
||||
input = "a/* @ifndef NONEXISTANT */b/* @endif */c";
|
||||
pp.preprocess(input, {}, 'js').should.equal("abc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included (block)', function () {
|
||||
input = "a/* @ifndef NODE_ENV */b/* @endif */c";
|
||||
pp.preprocess(input, {NODE_ENV: 'dev'}, 'js').should.equal("ac");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('success case, should be included', function () {
|
||||
input = "a\n" +
|
||||
"# @ifndef FLAG\n" +
|
||||
"b\n" +
|
||||
"# @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('success case, should be included (multiple hashes)', function () {
|
||||
input = "a\n" +
|
||||
"## @ifndef FLAG\n" +
|
||||
"b\n" +
|
||||
"## @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {}, 'coffee').should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('fail case, should not be included', function () {
|
||||
input = "a\n" +
|
||||
"# @ifndef FLAG\n" +
|
||||
"b\n" +
|
||||
"# @endif\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {FLAG: 1}, 'coffee').should.equal("a\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
107
node_modules/preprocess/test/include-static.spec.js
generated
vendored
Normal file
107
node_modules/preprocess/test/include-static.spec.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('@include-static directive shall be preprocessed', function () {
|
||||
var input;
|
||||
|
||||
describe('in html', function () {
|
||||
it('and include files non-recursively', function () {
|
||||
input = "a<!-- @include-static include.html -->c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'})
|
||||
.should.equal("a!foobar!<!-- @exec hello('html') --><!-- @include static.txt -->c");
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n <!-- @include-static includenewline.txt -->c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}).should.equal("a\n !foobar!\n c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and include files non-recursively (block)', function () {
|
||||
input = "a\n /* @include-static include.block.js */c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js')
|
||||
.should.equal("a\n !foobar!/* @exec hello('js') */\n /* @include static.txt */c");
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline (block)', function () {
|
||||
input = "a\n /* @include-static includenewline.txt */c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js').should.equal("a\n !foobar!\n c");
|
||||
});
|
||||
|
||||
it('and include files non-recursively (line)', function () {
|
||||
input = "a\n// @include-static include.js\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js')
|
||||
.should.equal("a\n!foobar!\n// @exec hello('js')\n// @include static.txt\nc");
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline (line)', function () {
|
||||
input = "a\n // @include-static includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in plain text files', function () {
|
||||
it('and include files non-recursively', function () {
|
||||
input = "a\n@include-static include.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'simple')
|
||||
.should.equal("a\n!foobar!\n@exec hello('simple')\n@include static.txt\nc");
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n @include-static includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'simple').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and include files non-recursively', function () {
|
||||
input = "a\n# @include-static include.coffee\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'coffee')
|
||||
.should.equal("a\n!foobar!\n# @exec hello('coffee')\n# @include static.txt\nc");
|
||||
});
|
||||
|
||||
it('and include files non-recursively (multiple hashes)', function () {
|
||||
input = "a\n## @include-static include.coffee\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'coffee')
|
||||
.should.equal("a\n!foobar!\n# @exec hello('coffee')\n# @include static.txt\nc");
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n # @include-static includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'coffee').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "a<!--@include-static include.html-->c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'})
|
||||
.should.equal("a!foobar!<!-- @exec hello('html') --><!-- @include static.txt -->c");
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "a\n /*@include-static include.block.js*/c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js')
|
||||
.should.equal("a\n !foobar!/* @exec hello('js') */\n /* @include static.txt */c");
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "a\n//@include-static include.js\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js')
|
||||
.should.equal("a\n!foobar!\n// @exec hello('js')\n// @include static.txt\nc");
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "a\n#@include-static include.coffee\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'coffee')
|
||||
.should.equal("a\n!foobar!\n# @exec hello('coffee')\n# @include static.txt\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
144
node_modules/preprocess/test/include.spec.js
generated
vendored
Normal file
144
node_modules/preprocess/test/include.spec.js
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
spies = require("chai-spies"),
|
||||
pp = require('../lib/preprocess'),
|
||||
hello = require('./lib/hello');
|
||||
|
||||
chai.should();
|
||||
chai.use(spies);
|
||||
|
||||
describe('@include directive shall be preprocessed', function () {
|
||||
var input, helloSpy;
|
||||
|
||||
beforeEach(function(){
|
||||
helloSpy = chai.spy(hello);
|
||||
});
|
||||
|
||||
describe('in html', function () {
|
||||
it('and include files', function () {
|
||||
input = "a<!-- @include include.html -->c";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}).should.equal("a!foobar!Hello html!!bazqux!c");
|
||||
helloSpy.should.have.been.called.with('html');
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n <!-- @include includenewline.txt -->c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}).should.equal("a\n !foobar!\n c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('and include files (block)', function () {
|
||||
input = "a\n /* @include include.block.js */c";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'js').should.equal("a\n !foobar!Hello js!\n !bazqux!c");
|
||||
helloSpy.should.have.been.called.with('js');
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline (block)', function () {
|
||||
input = "a\n /* @include includenewline.txt */c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js').should.equal("a\n !foobar!\n c");
|
||||
});
|
||||
|
||||
it('and include files (line)', function () {
|
||||
input = "a\n// @include include.js\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'js').should.equal("a\n!foobar!\nHello js!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('js');
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline (line)', function () {
|
||||
input = "a\n // @include includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in plain text files', function () {
|
||||
it('and include files', function () {
|
||||
input = "a\n@include include.txt\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'simple').should.equal("a\n!foobar!\nHello simple!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('simple');
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n @include includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'simple').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('in coffeescript', function () {
|
||||
it('and include files', function () {
|
||||
input = "a\n# @include include.coffee\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'coffee').should.equal("a\n!foobar!\nHello coffee!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('coffee');
|
||||
});
|
||||
|
||||
it('and include files (multiple hashes)', function () {
|
||||
input = "a\n## @include include.coffee\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'coffee').should.equal("a\n!foobar!\nHello coffee!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('coffee');
|
||||
});
|
||||
|
||||
it('and include files and indent if ending with a newline', function () {
|
||||
input = "a\n # @include includenewline.txt\nc";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'coffee').should.equal("a\n !foobar!\n \nc");
|
||||
});
|
||||
});
|
||||
|
||||
describe('and shall allow omitting of whitespaces', function () {
|
||||
it('in html before and after the directive', function () {
|
||||
input = "a<!--@include include.html-->c";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}).should.equal("a!foobar!Hello html!!bazqux!c");
|
||||
helloSpy.should.have.been.called.with('html');
|
||||
});
|
||||
|
||||
describe('in javascript', function () {
|
||||
it('before and after the directive (block)', function () {
|
||||
input = "a\n /*@include include.block.js*/c";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'js').should.equal("a\n !foobar!Hello js!\n !bazqux!c");
|
||||
helloSpy.should.have.been.called.with('js');
|
||||
});
|
||||
|
||||
it('before the directive (line)', function () {
|
||||
input = "a\n//@include include.js\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'js').should.equal("a\n!foobar!\nHello js!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('js');
|
||||
});
|
||||
});
|
||||
|
||||
it('in coffeescript before the directive', function () {
|
||||
input = "a\n#@include include.coffee\nc";
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/include',
|
||||
hello: helloSpy
|
||||
}, 'coffee').should.equal("a\n!foobar!\nHello coffee!\n!bazqux!\nc");
|
||||
helloSpy.should.have.been.called.with('coffee');
|
||||
});
|
||||
});
|
||||
});
|
||||
11
node_modules/preprocess/test/lib/copyFile.js
generated
vendored
Normal file
11
node_modules/preprocess/test/lib/copyFile.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function copyFile (source, dest, callback) {
|
||||
var writer = fs.createWriteStream(dest);
|
||||
fs.createReadStream(source).pipe(writer);
|
||||
|
||||
writer.on('finish', callback);
|
||||
};
|
||||
|
||||
7
node_modules/preprocess/test/lib/hello.js
generated
vendored
Normal file
7
node_modules/preprocess/test/lib/hello.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function hello() {
|
||||
var names = Array.prototype.slice.call(arguments);
|
||||
|
||||
return 'Hello ' + names.join() + '!';
|
||||
};
|
||||
80
node_modules/preprocess/test/newlines.spec.js
generated
vendored
Normal file
80
node_modules/preprocess/test/newlines.spec.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
spies = require("chai-spies"),
|
||||
pp = require('../lib/preprocess'),
|
||||
hello = require('./lib/hello');
|
||||
|
||||
chai.should();
|
||||
chai.use(spies);
|
||||
|
||||
describe('newlines shall be handled in all common formats', function () {
|
||||
var input;
|
||||
|
||||
it('and handle \\n (Unix) style EOLs', function () {
|
||||
input = "a\n" +
|
||||
"<!-- @ifdef TEST -->\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {TEST: ""}).should.equal("a\nb\nc");
|
||||
});
|
||||
|
||||
it('and handle \\r\\n (Windows) style EOLs', function () {
|
||||
input = "a\r\n" +
|
||||
"<!-- @ifdef TEST -->\r\n" +
|
||||
"b\r\n" +
|
||||
"<!-- @endif -->\r\n" +
|
||||
"c";
|
||||
pp.preprocess(input, {TEST: ""}).should.equal("a\r\nb\r\nc");
|
||||
});
|
||||
|
||||
it('and handle \\r (legacy Mac) style EOLs', function () {
|
||||
input = "a\r" +
|
||||
"<!-- @ifdef TEST -->\r" +
|
||||
"b\r" +
|
||||
"<!-- @endif -->\r" +
|
||||
"c";
|
||||
pp.preprocess(input, {TEST: ""}).should.equal("a\rb\rc");
|
||||
});
|
||||
|
||||
it('and replace EOL in sources with mixed style EOLs with the EOL from current OS', function () {
|
||||
var osEol = require('os').EOL;
|
||||
|
||||
input = "a\r" +
|
||||
"<!-- @ifdef TEST -->\r\n" +
|
||||
"b\n" +
|
||||
"<!-- @endif -->\r" +
|
||||
"c";
|
||||
pp.preprocess(input, {TEST: ""}).should.equal("a" + osEol + "b" + osEol + "c");
|
||||
});
|
||||
|
||||
it('and convert EOLs from included files into EOLs from target file when using @include', function () {
|
||||
// includenewline.txt has \n style EOLs
|
||||
input = "a\r" +
|
||||
"<!-- @include includenewline.txt -->\r" +
|
||||
"b\r";
|
||||
pp.preprocess(input, {srcDir: "test/fixtures/include"}).should.equal("a\r!foobar!\r\rb\r");
|
||||
});
|
||||
|
||||
it('and convert EOLs from included files into EOLs from target file when using @include-static', function () {
|
||||
input = "a\r" +
|
||||
"<!-- @include-static includenewline.txt -->\r" +
|
||||
"b\r";
|
||||
pp.preprocess(input, {srcDir: "test/fixtures/include"}).should.equal("a\r!foobar!\r\rb\r");
|
||||
});
|
||||
|
||||
it('and extend files and adapt all EOLs from file to be included to EOLs in target file when using @extend', function () {
|
||||
var helloSpy = chai.spy(hello);
|
||||
|
||||
// extendadv.html has \r style EOLs
|
||||
input = "a\n<!-- @extend extendadv.html -->\nqa\n<!-- @endextend -->\n\nc";
|
||||
|
||||
pp.preprocess(input, {
|
||||
srcDir: 'test/fixtures/extend',
|
||||
BLUE: "red",
|
||||
hello: helloSpy
|
||||
}).should.equal("a\na\n b\n red\n Hello extend!\n qa\nc\nc");
|
||||
helloSpy.should.have.been.called.with('extend');
|
||||
});
|
||||
});
|
||||
67
node_modules/preprocess/test/options.spec.js
generated
vendored
Normal file
67
node_modules/preprocess/test/options.spec.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('shall support multiple call signatures', function () {
|
||||
var input;
|
||||
|
||||
describe('and support legacy mode', function () {
|
||||
it('with only the source param in which case context shall be extracted from process.env', function () {
|
||||
process.env.TEST = 'a';
|
||||
input = "a<!-- @ifdef TEST -->b<!-- @endif -->c";
|
||||
pp.preprocess(input).should.equal("abc");
|
||||
});
|
||||
|
||||
it('with the source and context params and take srcDir property from context if available', function () {
|
||||
input = "a<!--@include static.txt-->c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}).should.equal("a!bazqux!c");
|
||||
});
|
||||
|
||||
it('with the source, context and type params', function () {
|
||||
input = "a/*@include static.txt*/c";
|
||||
pp.preprocess(input, {srcDir: 'test/fixtures/include'}, 'js').should.equal("a!bazqux!c");
|
||||
});
|
||||
});
|
||||
|
||||
it('shall use process.cwd() if srcDir is not specified', function () {
|
||||
input = "a<!--@include test/fixtures/include/static.txt-->c";
|
||||
pp.preprocess(input).should.equal("a!bazqux!c");
|
||||
});
|
||||
|
||||
describe('and support options object instead of type', function () {
|
||||
it('and use srcDir option', function () {
|
||||
input = "a<!--@include static.txt-->c";
|
||||
pp.preprocess(input, {}, {srcDir: "test/fixtures/include"}).should.equal("a!bazqux!c");
|
||||
});
|
||||
|
||||
describe('and use fileNotFoundSilentFail option', function () {
|
||||
it('that should default to throwing an error when a file could not be found', function () {
|
||||
input = "a<!--@include static.txt-->c";
|
||||
(function () {
|
||||
pp.preprocess(input);
|
||||
}).should.throw(Error, /static.txt not found!/);
|
||||
|
||||
input = "a<!--@extend static.txt-->b<!--@endextend-->c";
|
||||
(function () {
|
||||
pp.preprocess(input);
|
||||
}).should.throw(Error, /static.txt not found!/);
|
||||
});
|
||||
|
||||
it('that should fall back to old behavior if it is set to true', function () {
|
||||
input = "a<!--@include static.txt-->c";
|
||||
pp.preprocess(input, {}, {fileNotFoundSilentFail: true}).should.match(/^a.*static.txt not found!c$/);
|
||||
|
||||
input = "a<!--@extend static.txt-->b<!--@endextend-->c";
|
||||
pp.preprocess(input, {}, {fileNotFoundSilentFail: true}).should.match(/^a.*static.txt not found!c$/);
|
||||
});
|
||||
});
|
||||
|
||||
it('and override automatic EOL detection with srcEol option', function () {
|
||||
input = "a\n<!--@include static.txt-->\nc";
|
||||
pp.preprocess(input, {}, {srcEol: '\r\n', srcDir: 'test/fixtures/include'}).should.equal("a\r\n!bazqux!\r\nc");
|
||||
});
|
||||
});
|
||||
});
|
||||
76
node_modules/preprocess/test/processFile.spec.js
generated
vendored
Normal file
76
node_modules/preprocess/test/processFile.spec.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess'),
|
||||
fs = require('fs'),
|
||||
copyFile = require('./lib/copyFile');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('processFile', function () {
|
||||
beforeEach(function () {
|
||||
if (!fs.existsSync('test/tmp')) {
|
||||
fs.mkdirSync('test/tmp');
|
||||
}
|
||||
});
|
||||
|
||||
it('shall preprocess files asynchronously', function (done) {
|
||||
var expected = "a0xDEADBEEFb";
|
||||
|
||||
pp.preprocessFile(
|
||||
'test/fixtures/processFile/processFileTest.html',
|
||||
'test/tmp/processFileTest.dest.html',
|
||||
{TEST: '0xDEADBEEF'},
|
||||
function () {
|
||||
fs.readFileSync('test/tmp/processFileTest.dest.html').toString().should.equal(expected);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('shall allow setting file extension explicitly', function (done) {
|
||||
copyFile(
|
||||
'test/fixtures/processFile/processFileTest.html',
|
||||
'test/tmp/processFileTest.js',
|
||||
function () {
|
||||
var expected = "a0xDEADBEEFb";
|
||||
|
||||
pp.preprocessFile(
|
||||
'test/tmp/processFileTest.js',
|
||||
'test/tmp/processFileTest.dest.js',
|
||||
{TEST: '0xDEADBEEF'},
|
||||
function () {
|
||||
fs.readFileSync('test/tmp/processFileTest.dest.js').toString().should.equal(expected);
|
||||
|
||||
done();
|
||||
},
|
||||
{type: 'html'}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('shall allow setting srcDir explicitly', function (done) {
|
||||
copyFile(
|
||||
'test/fixtures/processFile/processFileTestInclude.html',
|
||||
'test/tmp/processFileTestInclude.html',
|
||||
function () {
|
||||
var expected = "a\r\na0xDEADBEEFb\r\nb";
|
||||
|
||||
pp.preprocessFile(
|
||||
'test/tmp/processFileTestInclude.html',
|
||||
'test/tmp/processFileTestInclude.dest.html',
|
||||
{TEST: '0xDEADBEEF'},
|
||||
function () {
|
||||
fs.readFileSync('test/tmp/processFileTestInclude.dest.html').toString().should.equal(expected);
|
||||
|
||||
done();
|
||||
},
|
||||
{
|
||||
srcDir: 'test/fixtures/processFile',
|
||||
srcEol: '\r\n'
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
70
node_modules/preprocess/test/processFileSync.spec.js
generated
vendored
Normal file
70
node_modules/preprocess/test/processFileSync.spec.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai'),
|
||||
pp = require('../lib/preprocess'),
|
||||
fs = require('fs'),
|
||||
copyFile = require('./lib/copyFile');
|
||||
|
||||
chai.should();
|
||||
|
||||
describe('processFileSync', function () {
|
||||
beforeEach(function () {
|
||||
if (!fs.existsSync('test/tmp')) {
|
||||
fs.mkdirSync('test/tmp');
|
||||
}
|
||||
});
|
||||
|
||||
it('shall preprocess files synchronously', function () {
|
||||
var expected = "a0xDEADBEEFb";
|
||||
|
||||
pp.preprocessFileSync(
|
||||
'test/fixtures/processFile/processFileTest.html',
|
||||
'test/tmp/processFileTest.dest.html',
|
||||
{TEST: '0xDEADBEEF'}
|
||||
);
|
||||
fs.readFileSync('test/tmp/processFileTest.dest.html').toString().should.equal(expected);
|
||||
});
|
||||
|
||||
it('shall allow setting file extension explicitly', function (done) {
|
||||
copyFile(
|
||||
'test/fixtures/processFile/processFileTest.html',
|
||||
'test/tmp/processFileTest.js',
|
||||
function () {
|
||||
var expected = "a0xDEADBEEFb";
|
||||
|
||||
pp.preprocessFileSync(
|
||||
'test/tmp/processFileTest.js',
|
||||
'test/tmp/processFileTest.dest.js',
|
||||
{TEST: '0xDEADBEEF'},
|
||||
{type: 'html'}
|
||||
);
|
||||
|
||||
fs.readFileSync('test/tmp/processFileTest.dest.js').toString().should.equal(expected);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('shall allow setting srcDir explicitly', function (done) {
|
||||
copyFile(
|
||||
'test/fixtures/processFile/processFileTestInclude.html',
|
||||
'test/tmp/processFileTestInclude.html',
|
||||
function () {
|
||||
var expected = "a\r\na0xDEADBEEFb\r\nb";
|
||||
|
||||
pp.preprocessFileSync(
|
||||
'test/tmp/processFileTestInclude.html',
|
||||
'test/tmp/processFileTestInclude.dest.html',
|
||||
{TEST: '0xDEADBEEF'},
|
||||
{
|
||||
srcDir: 'test/fixtures/processFile',
|
||||
srcEol: '\r\n'
|
||||
}
|
||||
);
|
||||
|
||||
fs.readFileSync('test/tmp/processFileTestInclude.dest.html').toString().should.equal(expected);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user