Skip to content

Commit

Permalink
test(*): devided tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Feb 14, 2017
1 parent 7223c38 commit 667cd8d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 67 deletions.
35 changes: 35 additions & 0 deletions test/test-postcss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'path';
import {readFile, existsSync} from 'fs';
import postcss from 'postcss';
import execa from 'execa';
import tempfile from 'tempfile';
import test from 'ava';
import postLoadPlugins from '../src/index.js';

process.chdir(path.resolve(process.cwd() + '/test'));

const read = path => new Promise((resolve, reject) => {
readFile(path, 'utf8', (err, data) => {
if (err) {
reject(err);
}
return resolve(data);
});
});

test('post-load-pliguns default config for postcss from package.json', async t => {
t.is(
'.test{display:-ms-flexbox;display:flex;color:red}',
(await postcss(postLoadPlugins()).process('.test { display: flex; color: #ff0000;} @charset "utf-8";')).css
);
});

test('post-load-pliguns default config for postcss-cli from package.json', async t => {
t.plan(2);
const filename = tempfile('.css');
await execa('postcss', ['-u', path.resolve('../lib/index.js'), '-o', filename, 'fixtures/input-for-cli.css']);
const fix = await read('expected/output-for-cli.css');
const exp = await read(filename);
t.true(existsSync(filename));
t.is(fix, exp);
});
23 changes: 23 additions & 0 deletions test/test-posthtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'path';
import {readFile} from 'fs';
import posthtml from 'posthtml';
import test from 'ava';
import postLoadPlugins from '../src/index.js';

process.chdir(path.resolve(process.cwd() + '/test'));

const read = path => new Promise((resolve, reject) => {
readFile(path, 'utf8', (err, data) => {
if (err) {
reject(err);
}
return resolve(data);
});
});

test('post-load-pliguns default config for posthtml from package.json', async t => {
t.is(
(await read('expected/output-default-config-from-pkg.html')),
(await posthtml(postLoadPlugins()).process(await read('fixtures/input.html'))).html
);
});
34 changes: 34 additions & 0 deletions test/test-reshape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import path from 'path';
import reshape from 'reshape';
import test from 'ava';
import postLoadPlugins from '../src/index.js';

process.chdir(path.resolve(process.cwd() + '/test'));

test('reshape with post-load-pliguns should return equal html', async t => {
const html = '<div class="test">test</div>';
t.is(html, (await reshape({plugins: [postLoadPlugins()]}).process(html)).output());
});

test('reshape with post-load-pliguns should report not install pkg', async t => {
const html = '<my-custom class="test">test</my-custom>';
const ext = {
reshape: {
plugins: {
'custom-elements': {
defaultTag: 'span'
}
}
}
};
t.is(html, (await reshape({plugins: [postLoadPlugins(ext)]}).process(html)).output());
});

test('reshape with post-load-pliguns with reshape-beautify plugin', async t => {
const html = `<body><p>hi there</p><div class='wow'>this is minified</div></body>`;
const fixtures = `<body>
<p>hi there</p>
<div class="wow">this is minified</div>
</body>`;
t.is(fixtures, (await reshape({plugins: [postLoadPlugins()]}).process(html)).output());
});
67 changes: 0 additions & 67 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,9 @@
import path from 'path';
import {readFile, existsSync} from 'fs';
import posthtml from 'posthtml';
import postcss from 'postcss';
import reshape from 'reshape';
import execa from 'execa';
import tempfile from 'tempfile';
import test from 'ava';
import postLoadPlugins from '../src/index.js';

process.chdir(path.resolve(process.cwd() + '/test'));

const read = path => new Promise((resolve, reject) => {
readFile(path, 'utf8', (err, data) => {
if (err) {
reject(err);
}
return resolve(data);
});
});

test('post-load-pliguns return function', t => {
t.true(typeof postLoadPlugins() === 'function');
});

test('post-load-pliguns default config for posthtml from package.json', async t => {
t.is(
(await read('expected/output-default-config-from-pkg.html')),
(await posthtml(postLoadPlugins()).process(await read('fixtures/input.html'))).html
);
});

test('post-load-pliguns default config for postcss from package.json', async t => {
t.is(
'.test{display:-ms-flexbox;display:flex;color:red}',
(await postcss(postLoadPlugins()).process('.test { display: flex; color: #ff0000;} @charset "utf-8";')).css
);
});

test('post-load-pliguns default config for postcss-cli from package.json', async t => {
t.plan(2);
const filename = tempfile('.css');
await execa('postcss', ['-u', path.resolve('../lib/index.js'), '-o', filename, 'fixtures/input-for-cli.css']);
const fix = await read('expected/output-for-cli.css');
const exp = await read(filename);
t.true(existsSync(filename));
t.is(fix, exp);
});

test('reshape with post-load-pliguns should return equal html', async t => {
const html = '<div class="test">test</div>';
t.is(html, (await reshape({plugins: [postLoadPlugins()]}).process(html)).output());
});

test('reshape with post-load-pliguns should report not install pkg', async t => {
const html = '<my-custom class="test">test</my-custom>';
const ext = {
reshape: {
plugins: {
'custom-elements': {
defaultTag: 'span'
}
}
}
};
t.is(html, (await reshape({plugins: [postLoadPlugins(ext)]}).process(html)).output());
});

test('reshape with post-load-pliguns with reshape-beautify plugin', async t => {
const html = `<body><p>hi there</p><div class='wow'>this is minified</div></body>`;
const fixtures = `<body>
<p>hi there</p>
<div class="wow">this is minified</div>
</body>`;
t.is(fixtures, (await reshape({plugins: [postLoadPlugins()]}).process(html)).output());
});

0 comments on commit 667cd8d

Please sign in to comment.