Skip to content

Commit

Permalink
Tidy up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-eb committed Oct 23, 2016
1 parent 17006cd commit 34ca2f3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
7 changes: 7 additions & 0 deletions src/__tests__/_processCss.js
@@ -0,0 +1,7 @@
import cssnano from '..';

export default function processCss (t, fixture, expected, options = {}) {
return cssnano.process(fixture, options).then(({css}) => {
t.deepEqual(css, expected);
});
}
10 changes: 3 additions & 7 deletions src/__tests__/fixtures.js
@@ -1,7 +1,7 @@
import {readdirSync as directory, readFileSync as file} from 'fs';
import {join} from 'path';
import ava from 'ava';
import nano from '..';
import processCss from './_processCss';
import specName from './util/specName';

const base = join(__dirname, 'fixtures');
Expand All @@ -16,10 +16,6 @@ const specs = directory(base).reduce((tests, cssFile) => {
}, {});

Object.keys(specs).forEach(name => {
const spec = specs[name];
ava(name, t => {
return nano.process(spec.fixture).then(result => {
t.deepEqual(result.css, spec.expected, specName(name));
});
});
const {fixture, expected} = specs[name];
ava(specName(name), processCss, fixture, expected);
});
17 changes: 0 additions & 17 deletions src/__tests__/issue26.css

This file was deleted.

1 change: 0 additions & 1 deletion src/__tests__/issue26.expected.css

This file was deleted.

27 changes: 22 additions & 5 deletions src/__tests__/issue26.js
@@ -1,13 +1,30 @@
import {join} from 'path';
import {readFileSync as file} from 'fs';
import postcss from 'postcss';
import nano from '..';
import ava from 'ava';

ava('it should compress whitespace after node.clone()', t => {
const fixture = file(join(__dirname, 'issue26.css'), 'utf-8');
const expected = file(join(__dirname, 'issue26.expected.css'), 'utf-8');
const fixture = `
@media print {
.test {
-webkit-border-radius: 0;
border-radius: 0;
}
}
@media print {
.test {
-webkit-box-shadow: none;
box-shadow: none;
}
}
.test {
width: 500px;
}
`;

const expected = `@media print{.test{box-shadow:none;border-radius:0}}.test{width:500px}`;

ava('it should compress whitespace after node.clone()', t => {
const processor = postcss([
postcss.plugin('cloner', () => {
return css => {
Expand Down
11 changes: 3 additions & 8 deletions src/__tests__/modules.js
@@ -1,18 +1,13 @@
import {join} from 'path';
import {readdirSync as directory} from 'fs';
import ava from 'ava';
import nano from '..';
import processCss from './_processCss';

const base = join(__dirname, '/modules');

directory(base).forEach(file => {
const submodule = require(join(base, file));
submodule.tests.forEach(test => {
ava(test.message, t => {
const options = test.options || {};
return nano.process(test.fixture, options).then(result => {
t.deepEqual(result.css, test.expected);
});
});
submodule.tests.forEach(({message, fixture, expected, options}) => {
ava(message, processCss, fixture, expected, options);
});
});

0 comments on commit 34ca2f3

Please sign in to comment.