Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Refactor tests (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan authored and shvaikalesh committed Jan 4, 2017
1 parent c1728c8 commit a012b48
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,66 @@
global.expect = require('chai').expect;
global.Plugin = require('./');
describe('Plugin', function() {
var plugin;
/* eslint no-undef: 0 */
'use strict';

beforeEach(function() {
const expect = require('chai').expect;
const Plugin = require('./');

describe('Plugin', () => {
let plugin;

beforeEach(() => {
plugin = new Plugin({});
});

it('should be an object', function() {
expect(plugin).to.be.ok;
});
it('should be an object', () => expect(plugin).to.be.ok);

it('should has #optimize method', function() {
it('should has #optimize method', () => {
expect(plugin.optimize).to.be.an.instanceof(Function);
});

it('should compile and produce valid result', function(done) {
var content = '#first { font-size: 14px; color: #b0b; }';
var expected = '#first{font-size:14px;color:#b0b}';
it('should compile and produce valid result', done => {
const content = '#first { font-size: 14px; color: #b0b; }';
const expected = '#first{font-size:14px;color:#b0b}';

plugin.optimize({data: content, path: ''}).then(data => {
expect(data).to.equal(expected);
done();
}, error => expect(error).not.to.be.ok);
plugin.optimize({data: content, path: ''})
.then(data => {
expect(data).to.equal(expected);
done();
})
.catch(error => expect(error).not.to.be.ok);
});

it('should compile and produce a result clean-css options are reflected in', function(done) {
it('should compile and produce a result clean-css options are reflected in', done => {
plugin.options = {
keepSpecialComments: 0,
keepBreaks: true
keepBreaks: true,
};

var eol = require('os').EOL;
const eol = require('os').EOL;

var content = '/*! comment */\n#first { color: red; }\r\n#second { color: blue; }';
var expected = '#first{color:red}' + eol + '#second{color:#00f}';
const content = '/*! comment */\n#first { color: red; }\r\n#second { color: blue; }';
const expected = `#first{color:red}${eol}#second{color:#00f}`;

plugin.optimize({data: content, path: ''}).then(data => {
expect(data).to.equal(expected);
done();
}, error => expect(error).not.to.be.ok);
plugin.optimize({data: content, path: ''})
.then(data => {
expect(data).to.equal(expected);
done();
})
.catch(error => expect(error).not.to.be.ok);
});

it('should return a non minified css if path is in "ignore" list', function(done) {
it('should return a non minified css if path is in "ignore" list', done => {
plugin.options = {
ignored: /ignore-me\.css/
ignored: /ignore-me\.css/,
};

var content = '#first { font-size: 14px; color: #b0b; }';
var expected = content;
const content = '#first { font-size: 14px; color: #b0b; }';
const expected = content;

plugin.optimize({data: content, path: "dist/ignore-me.css"}).then(data => {
expect(data).to.equal(expected);
done();
}, error => expect(error).not.to.be.ok);
plugin.optimize({data: content, path: 'dist/ignore-me.css'})
.then(data => {
expect(data).to.equal(expected);
done();
})
.catch(error => expect(error).not.to.be.ok);
});


});

0 comments on commit a012b48

Please sign in to comment.