1 | 'use strict';
|
2 |
|
3 | var concatFilenames = require('../index.js'),
|
4 | chai = require('chai'),
|
5 | sinonChai = require('sinon-chai'),
|
6 | expect = chai.expect,
|
7 | assert = require('stream-assert'),
|
8 | File = require('gulp-util').File,
|
9 | gulp = require('gulp'),
|
10 | path = require('path');
|
11 |
|
12 | chai.use(sinonChai);
|
13 |
|
14 | function fixtures(glob) {
|
15 | return path.join(__dirname, 'fixtures', glob);
|
16 | }
|
17 |
|
18 | describe('Given gulp-concat-filenames', function () {
|
19 | describe('When I do not provide a filename', function () {
|
20 | it('Then it should error', function () {
|
21 |
|
22 | function nofilenameProvided() {
|
23 | concatFilenames();
|
24 | }
|
25 |
|
26 | expect(nofilenameProvided)
|
27 | .to
|
28 | .throw(Error, 'Missing fileName option for gulp-concat-filenames');
|
29 | });
|
30 | });
|
31 |
|
32 | describe('When I do provide a filename', function () {
|
33 | it('Then it should ignore null files', function (done) {
|
34 | var stream = concatFilenames('example.js');
|
35 | stream
|
36 | .pipe(assert.length(0))
|
37 | .pipe(assert.end(done));
|
38 | stream.write(new File());
|
39 | stream.end();
|
40 | });
|
41 |
|
42 | it('Then it emit an error in streamed files', function (done) {
|
43 | gulp
|
44 | .src(fixtures('*'), {
|
45 | buffer: false
|
46 | })
|
47 | .pipe(concatFilenames('example.js'))
|
48 | .on('error', function (err) {
|
49 | expect(err.message).to.equal('Streaming not supported');
|
50 | done();
|
51 | });
|
52 | });
|
53 |
|
54 | describe('When I do not provide the "root" optional argument', function () {
|
55 | it('then it will concatinate all filenames into a single file with absolute paths', function (done) {
|
56 | var expectedFilenames = ([
|
57 | path.join(__dirname, 'fixtures/fork.txt'),
|
58 | path.join(__dirname, 'fixtures/knife.js'),
|
59 | path.join(__dirname, 'fixtures/spoon.html'),
|
60 | ]
|
61 | .join('\n') + '\n')
|
62 | .replace(/\\/g, '\/')
|
63 | .toString();
|
64 |
|
65 | gulp
|
66 | .src(fixtures('*'))
|
67 | .pipe(concatFilenames('mainfest.txt'))
|
68 | .pipe(assert.first(function (d) {
|
69 |
|
70 | var contents = d.contents.toString();
|
71 | expect(contents)
|
72 | .to
|
73 | .equal(expectedFilenames);
|
74 | }))
|
75 | .pipe(assert.end(done));
|
76 | });
|
77 | });
|
78 |
|
79 | describe('When I do provide the "root" optional argument', function () {
|
80 | it('then it will concatinate all filenames into a single file with relative paths', function (done) {
|
81 | var expectedFilenames = ([
|
82 | '../test/fixtures/fork.txt',
|
83 | '../test/fixtures/knife.js',
|
84 | '../test/fixtures/spoon.html',
|
85 | ].join('\n') + '\n').toString();
|
86 |
|
87 | gulp
|
88 | .src(fixtures('*'))
|
89 | .pipe(concatFilenames('mainfest.txt', {
|
90 | root: 'fixtures'
|
91 | }))
|
92 | .pipe(assert.first(function (d) {
|
93 |
|
94 | var contents = d.contents.toString();
|
95 | expect(contents)
|
96 | .to
|
97 | .equal(expectedFilenames);
|
98 | }))
|
99 | .pipe(assert.end(done));
|
100 | });
|
101 |
|
102 | describe('When I provide prepend and append arguments', function () {
|
103 | it('then it will concatinate all filenames into a single file with prefix and suffix strings', function (done) {
|
104 | var expectedFilenames = ([
|
105 | 'XXX../test/fixtures/fork.txtYYY',
|
106 | 'XXX../test/fixtures/knife.jsYYY',
|
107 | 'XXX../test/fixtures/spoon.htmlYYY',
|
108 | ].join('\n') + '\n').toString();
|
109 |
|
110 | gulp
|
111 | .src(fixtures('*'))
|
112 | .pipe(concatFilenames('mainfest.txt', {
|
113 | root: 'fixtures',
|
114 | prepend: 'XXX',
|
115 | append: 'YYY'
|
116 | }))
|
117 | .pipe(assert.first(function (d) {
|
118 |
|
119 | var contents = d.contents.toString();
|
120 | expect(contents)
|
121 | .to
|
122 | .equal(expectedFilenames);
|
123 | }))
|
124 | .pipe(assert.end(done));
|
125 | });
|
126 | });
|
127 |
|
128 | describe('When I provide a differnt newLine argument', function () {
|
129 |
|
130 | it('then it will concatinate all filenames into a single file with an alternate newLine', function (done) {
|
131 | var expectedFilenames = ([
|
132 | '../test/fixtures/fork.txt',
|
133 | '../test/fixtures/knife.js',
|
134 | '../test/fixtures/spoon.html',
|
135 | ].join('XXX') + 'XXX').toString();
|
136 |
|
137 | gulp
|
138 | .src(fixtures('*'))
|
139 | .pipe(concatFilenames('mainfest.txt', {
|
140 | root: 'fixtures',
|
141 | newLine: 'XXX'
|
142 | }))
|
143 | .pipe(assert.first(function (d) {
|
144 |
|
145 | var contents = d.contents.toString();
|
146 | expect(contents)
|
147 | .to
|
148 | .equal(expectedFilenames);
|
149 | }))
|
150 | .pipe(assert.end(done));
|
151 | });
|
152 | });
|
153 | });
|
154 | });
|
155 | }); |
\ | No newline at end of file |