1 |
|
2 |
|
3 |
|
4 |
|
5 | var assert = require('assert')
|
6 | var gulp = require('gulp')
|
7 | var fs = require('fs')
|
8 | var path = require('path')
|
9 | var inline = require('..')
|
10 | var transform = require('readable-stream/transform')
|
11 | var base = 'test/fixtures'
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | describe('gulp-inline', function () {
|
18 | it('should inline a stylesheet', function (done) {
|
19 | inputOutput('css', done)
|
20 | })
|
21 |
|
22 | it('should inline a script', function (done) {
|
23 | inputOutput('js', done)
|
24 | })
|
25 |
|
26 | it('should preserve attributes', function (done) {
|
27 | inputOutput('attrs', done)
|
28 | })
|
29 |
|
30 | it('should inline SVG', function (done) {
|
31 | inputOutput('svg', done)
|
32 | })
|
33 |
|
34 | it('should inline an image', function (done) {
|
35 | inputOutput('img', done)
|
36 | })
|
37 |
|
38 | it('should inline a basic template', function (done) {
|
39 | inputOutput('basic', done)
|
40 | })
|
41 |
|
42 | it('should work with inline event listeners', function (done) {
|
43 | inputOutput('inline-events', done)
|
44 | })
|
45 |
|
46 | it('should not automatically create unnecessary html entities', function (done) {
|
47 | inputOutput('apostrophe', done)
|
48 | })
|
49 |
|
50 | it('should not duplicate css', function (done) {
|
51 | inputOutput('duplicate-css', done)
|
52 | })
|
53 |
|
54 | it('should inline using relative paths when src not absolute', function (done) {
|
55 | gulp.src(path.join(base, 'relative.html'))
|
56 | .pipe(inline())
|
57 | .on('data', function (file) {
|
58 | assert.equal(String(file.contents), fs.readFileSync(path.join(base, 'basic-output.html'), 'utf8'))
|
59 | done()
|
60 | })
|
61 | })
|
62 |
|
63 | it('should ignore files if option is set', function (done) {
|
64 | gulp.src(path.join(base, 'ignore.html'))
|
65 | .pipe(inline({
|
66 | ignore: ['/ignore.js', '/ignore.css', '/ignore.svg'],
|
67 | base: base
|
68 | }))
|
69 | .on('data', function (file) {
|
70 | assert.equal(String(file.contents), fs.readFileSync(path.join(base, 'ignore-output.html'), 'utf8'))
|
71 | done()
|
72 | })
|
73 | })
|
74 |
|
75 | it('should ignore tag types if option is set', function (done) {
|
76 | gulp.src(path.join(base, 'disable.html'))
|
77 | .pipe(inline({
|
78 | disabledTypes: ['svg', 'img', 'js', 'css'],
|
79 | base: base
|
80 | }))
|
81 | .on('data', function (file) {
|
82 | assert.equal(String(file.contents), fs.readFileSync(path.join(base, 'disable-output.html'), 'utf8'))
|
83 | done()
|
84 | })
|
85 | })
|
86 |
|
87 | it('should run Transform stream on files', function(done) {
|
88 | gulp.src(path.join(base, 'basic-transform.html'))
|
89 | .pipe(inline({
|
90 | css: dummyTransform,
|
91 | base: base
|
92 | }))
|
93 | .on('data', function (file) {
|
94 | assert.equal(String(file.contents), fs.readFileSync(path.join(base, 'basic-transform-output.html'), 'utf8'))
|
95 | done()
|
96 | })
|
97 | })
|
98 |
|
99 | function dummyTransform() {
|
100 | return new transform({
|
101 | objectMode: true,
|
102 | transform: function(file, enc, cb) {
|
103 | file.contents = new Buffer("Transformed file")
|
104 | this.push(file)
|
105 | cb()
|
106 | }
|
107 | })
|
108 | }
|
109 |
|
110 | it('should inline SVG referenced in <use> tag', function (done) {
|
111 | inputOutput('svg-use', done)
|
112 | })
|
113 |
|
114 | function inputOutput (name, done) {
|
115 | gulp.src(path.join(base, name + '.html'))
|
116 | .pipe(inline({base: base}))
|
117 | .on('data', function (file) {
|
118 | assert.equal(String(file.contents), fs.readFileSync(path.join(base, name + '-output.html'), 'utf8'))
|
119 | done()
|
120 | })
|
121 | }
|
122 | })
|