From a33d507872ee496dc20e0929e83e1c32d696d792 Mon Sep 17 00:00:00 2001 From: exuanbo Date: Sun, 30 Aug 2020 15:39:41 +0800 Subject: [PATCH] test: refactor --- test/index.test.js | 49 ++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index c06831d..d645acb 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -3,11 +3,13 @@ const fs = require('fs') const path = require('path') -const should = require('should') +const expect = require('chai').expect const Vinyl = require('vinyl') const inlineSource = require('..') const getFile = (filePath, contents) => { + filePath = filePath.replace(/\\/g, '/') + if (!path.extname(filePath)) filePath += '.html' return new Vinyl({ base: path.dirname(filePath), path: filePath, @@ -23,66 +25,49 @@ const getExpected = filePath => { return getFile(path.join(__dirname, 'expected', filePath)) } -const compare = (stream, fixtureName, expectedName, done) => { - stream.on('error', err => { - should.exist(err) - done(err) - }) - +const compare = (done, fixtureName, expectedName, options = {}) => { + const stream = inlineSource(options) + stream.on('error', err => done(err)) stream.on('data', file => { - should.exist(file) - should.exist(file.contents) - - should.equal( - String(file.contents), + expect(String(file.contents)).to.equal( String(getExpected(expectedName).contents) ) done() }) - stream.write(getFixture(fixtureName)) stream.end() } describe('gulp-inline-source', () => { it('Should inline