Skip to content

Commit a33d507

Browse files
committed
test: refactor
1 parent 898c7bf commit a33d507

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

test/index.test.js

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
const fs = require('fs')
55
const path = require('path')
6-
const should = require('should')
6+
const expect = require('chai').expect
77
const Vinyl = require('vinyl')
88
const inlineSource = require('..')
99

1010
const getFile = (filePath, contents) => {
11+
filePath = filePath.replace(/\\/g, '/')
12+
if (!path.extname(filePath)) filePath += '.html'
1113
return new Vinyl({
1214
base: path.dirname(filePath),
1315
path: filePath,
@@ -23,66 +25,49 @@ const getExpected = filePath => {
2325
return getFile(path.join(__dirname, 'expected', filePath))
2426
}
2527

26-
const compare = (stream, fixtureName, expectedName, done) => {
27-
stream.on('error', err => {
28-
should.exist(err)
29-
done(err)
30-
})
31-
28+
const compare = (done, fixtureName, expectedName, options = {}) => {
29+
const stream = inlineSource(options)
30+
stream.on('error', err => done(err))
3231
stream.on('data', file => {
33-
should.exist(file)
34-
should.exist(file.contents)
35-
36-
should.equal(
37-
String(file.contents),
32+
expect(String(file.contents)).to.equal(
3833
String(getExpected(expectedName).contents)
3934
)
4035
done()
4136
})
42-
4337
stream.write(getFixture(fixtureName))
4438
stream.end()
4539
}
4640

4741
describe('gulp-inline-source', () => {
4842
it('Should inline <script> tag', done => {
49-
compare(inlineSource(), 'script.html', 'inlined-script.html', done)
43+
compare(done, 'script', 'inlined-script')
5044
})
5145

5246
it('Should inline <script> tag with ES6 source', done => {
53-
compare(inlineSource(), 'script-es6.html', 'inlined-script.html', done)
47+
compare(done, 'script-es6', 'inlined-script')
5448
})
5549

5650
it('Should inline <link> tag', done => {
57-
compare(inlineSource(), 'link.html', 'inlined-link.html', done)
51+
compare(done, 'link', 'inlined-link')
5852
})
5953

6054
it('Should inline <img> tag with SVG source', done => {
61-
compare(inlineSource(), 'image-svg.html', 'inlined-image-svg.html', done)
55+
compare(done, 'image-svg', 'inlined-image-svg')
6256
})
6357

6458
it('Should inline <img> tag with PNG source', done => {
65-
compare(inlineSource(), 'image-png.html', 'inlined-image-png.html', done)
59+
compare(done, 'image-png', 'inlined-image-png')
6660
})
6761

68-
it('works with type and media attributes', done => {
69-
compare(
70-
inlineSource(),
71-
'with-attributes.html',
72-
'inlined-with-attributes.html',
73-
done
74-
)
62+
it('Should work with type and media attributes', done => {
63+
compare(done, 'with-attributes', 'inlined-with-attributes')
7564
})
7665

77-
it('works with relative paths', done => {
78-
compare(inlineSource(), 'script-relative.html', 'inlined-script.html', done)
66+
it('Should work with relative paths', done => {
67+
compare(done, 'script-relative', 'inlined-script')
7968
})
8069

8170
it('Should inline assets without minification', done => {
82-
const stream = inlineSource({
83-
compress: false
84-
})
85-
86-
compare(stream, 'nominify.html', 'inlined-nominify.html', done)
71+
compare(done, 'nominify', 'inlined-nominify', { compress: false })
8772
})
8873
})

0 commit comments

Comments
 (0)