diff --git a/test/test.js b/test/test.js index 77a6994..dbde160 100644 --- a/test/test.js +++ b/test/test.js @@ -12,86 +12,86 @@ const serveStatic = require('serve-static'); const plugin = require('../'); function read(filename) { - return fs.readFileSync(path.join(__dirname, 'fixtures', 'styles', filename), 'utf8'); + return fs.readFileSync(path.join(__dirname, 'fixtures', 'styles', filename), 'utf8'); } const test = function (input, output, opts, done) { - input = read(input); - output = read(output); - - opts = defaults(opts || {}, { - assetPaths: ['//localhost:3000/styles/'] - }); - - postcss([plugin(opts)]).process(input).then(result => { - assert.equal(result.css, output); - assert.isEmpty(result.warnings()); - }).then(done).catch(err => { - done(err); - }); + input = read(input); + output = read(output); + + opts = defaults(opts || {}, { + assetPaths: ['//localhost:3000/styles/'] + }); + + postcss([plugin(opts)]).process(input).then(result => { + assert.equal(result.css, output); + assert.isEmpty(result.warnings()); + }).then(done).catch(err => { + done(err); + }); }; function startServer(docroot) { - const serve = serveStatic(docroot); - const server = http.createServer((req, res) => { - const done = finalhandler(req, res); - serve(req, res, done); - }); - server.listen(3000); - - return server; + const serve = serveStatic(docroot); + const server = http.createServer((req, res) => { + const done = finalhandler(req, res); + serve(req, res, done); + }); + server.listen(3000); + + return server; } /* eslint max-len:0 */ describe('postcss-image-inliner', () => { - let server; - - beforeEach(() => { - server = startServer(path.join(__dirname, 'fixtures')); - }); - afterEach(done => { - server.close(done); - }); - - it('should skip too big images', done => { - test('big.css', 'big.css', {maxFileSize: 1}, done); - }); - - it('should handle multiple background images', done => { - test('multi.in.css', 'multi.out.css', {}, done); - }); - - it('should handle background shorthand', done => { - test('shorthand.in.css', 'shorthand.out.css', {}, done); - }); - - it('should handle media queries', done => { - test('media.in.css', 'media.out.css', {}, done); - }); - - it('should consider base64Svg option', done => { - test('b64svg.in.css', 'b64svg.out.css', {b64Svg: true, maxFileSize: 0}, done); - }); - - it('should do nothing on missing files in non strict mode', done => { - test('missing.in.css', 'missing.out.css', {}, done); - }); - - it('should handle urls used for content property', done => { - test('pseudo.in.css', 'pseudo.out.css', {}, done); - }); - - it('should fail on missing files in strict mode', done => { - test('missing.in.css', 'missing.out.css', {strict: true}, error => { - if (error) { - done(); - } else { - done(new Error('Should fail')); - } - }); - }); - - it('should allow globbing', done => { - test('glob.in.css', 'glob.out.css', {assetPaths: 'test/*/images/'}, done); - }); + let server; + + beforeEach(() => { + server = startServer(path.join(__dirname, 'fixtures')); + }); + afterEach(done => { + server.close(done); + }); + + it('should skip too big images', done => { + test('big.css', 'big.css', {maxFileSize: 1}, done); + }); + + it('should handle multiple background images', done => { + test('multi.in.css', 'multi.out.css', {}, done); + }); + + it('should handle background shorthand', done => { + test('shorthand.in.css', 'shorthand.out.css', {}, done); + }); + + it('should handle media queries', done => { + test('media.in.css', 'media.out.css', {}, done); + }); + + it('should consider base64Svg option', done => { + test('b64svg.in.css', 'b64svg.out.css', {b64Svg: true, maxFileSize: 0}, done); + }); + + it('should do nothing on missing files in non strict mode', done => { + test('missing.in.css', 'missing.out.css', {}, done); + }); + + it('should handle urls used for content property', done => { + test('pseudo.in.css', 'pseudo.out.css', {}, done); + }); + + it('should fail on missing files in strict mode', done => { + test('missing.in.css', 'missing.out.css', {strict: true}, error => { + if (error) { + done(); + } else { + done(new Error('Should fail')); + } + }); + }); + + it('should allow globbing', done => { + test('glob.in.css', 'glob.out.css', {assetPaths: 'test/*/images/'}, done); + }); });