Skip to content

Commit 72ee0a0

Browse files
mightyalekseyAlexey Litvinov
authored andcommitted
more tests for the public api
1 parent 18e9c9b commit 72ee0a0

File tree

9 files changed

+134
-9
lines changed

9 files changed

+134
-9
lines changed

test/api/append.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').lodash;
4+
const Through = require('../sugar').Through;
5+
6+
suite('api/append', () => {
7+
suite('should add plugins to the pipeline', () => {
8+
const processor = spy(identity);
9+
10+
test('plugin should be called', () => assert(processor.called));
11+
12+
setup(() => {
13+
hook({append: [new Through(processor)]});
14+
require('./fixture/oceanic.css');
15+
});
16+
17+
teardown(() => {
18+
dropCache('./api/fixture/oceanic.css');
19+
detachHook('.css');
20+
});
21+
});
22+
});

test/api/extensions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
const detachHook = require('../sugar').detachHook;
12
const dropCache = require('../sugar').dropCache;
2-
const dropHook = require('../sugar').dropHook;
33
const identity = require('lodash').identity;
4-
const spy = require('sinon').spy;
54

65
suite('api/extensions', () => {
76
suite('uses .css by default', () => {
@@ -14,7 +13,7 @@ suite('api/extensions', () => {
1413

1514
teardown(() => {
1615
dropCache('./api/fixture/oceanic.css');
17-
dropHook('.css');
16+
detachHook('.css');
1817
});
1918
});
2019
});

test/api/prepend.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').lodash;
4+
const Through = require('../sugar').Through;
5+
6+
suite('api/prepend', () => {
7+
suite('should add plugins to the pipeline', () => {
8+
const processor = spy(identity);
9+
10+
test('plugin should be called', () => assert(processor.called));
11+
12+
setup(() => {
13+
hook({prepend: [new Through(processor)]});
14+
require('./fixture/oceanic.css');
15+
});
16+
17+
teardown(() => {
18+
dropCache('./api/fixture/oceanic.css');
19+
detachHook('.css');
20+
});
21+
});
22+
});

test/api/preprocessCss.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').identity;
4+
5+
suite('api/preprocessCss', () => {
6+
const preprocessCss = spy(identity);
7+
8+
test('should be called', () => assert(preprocessCss.called));
9+
10+
setup(() => {
11+
hook({preprocessCss});
12+
require('./fixture/oceanic.css');
13+
});
14+
15+
teardown(() => {
16+
dropCache('./api/fixture/oceanic.css');
17+
detachHook('.css');
18+
});
19+
});

test/api/processCss.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
const detachHook = require('../sugar').detachHook;
12
const dropCache = require('../sugar').dropCache;
23
const identity = require('lodash').identity;
3-
const spy = require('sinon').spy;
44

55
suite('api/processCss()', () => {
66
const processCss = spy(identity);
77

88
test('should be called', () => assert(processCss.called));
99

1010
setup(() => {
11-
hook({processCss: processCss});
11+
hook({processCss});
1212
require('./fixture/oceanic.css');
1313
});
1414

15-
teardown(() => dropCache('./api/fixture/oceanic.css'));
15+
teardown(() => {
16+
dropCache('./api/fixture/oceanic.css');
17+
detachHook('.css');
18+
});
1619
});

test/api/rootDir.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const path = require('path');
4+
5+
suite('api/rootDir', () => {
6+
suite('should change the way in which tokens are generated', () => {
7+
let tokens1;
8+
let tokens2;
9+
10+
test('should return different tokens', () => assert.notDeepEqual(tokens1, tokens2));
11+
12+
setup(() => {
13+
hook({rootDir: path.join(__dirname, '../../')});
14+
tokens1 = require('./fixture/oceanic.css');
15+
dropCache('./api/fixture/oceanic.css');
16+
17+
hook({rootDir: __dirname});
18+
tokens2 = require('./fixture/oceanic.css');
19+
});
20+
21+
teardown(() => {
22+
dropCache('./api/fixture/oceanic.css');
23+
detachHook('.css');
24+
});
25+
});
26+
});

test/api/use.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').lodash;
4+
const Through = require('../sugar').Through;
5+
6+
suite('api/use', () => {
7+
suite('should replace plugins in the pipeline', () => {
8+
const processor = spy(identity);
9+
let tokens;
10+
11+
test('plugin should be called', () => {
12+
assert(processor.called);
13+
assert.deepEqual(tokens, {});
14+
});
15+
16+
setup(() => {
17+
hook({use: [new Through(processor)]});
18+
tokens = require('./fixture/oceanic.css');
19+
});
20+
21+
teardown(() => {
22+
dropCache('./api/fixture/oceanic.css');
23+
detachHook('.css');
24+
});
25+
});
26+
});

test/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
global.assert = require('assert');
22
global.hook = require('../');
3+
global.spy = require('sinon').spy;

test/sugar.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const plugin = require('postcss').plugin;
2+
13
/**
24
* Drops require cache for the certain module
35
*
@@ -8,11 +10,16 @@ function dropCache(modulePath) {
810
};
911

1012
/**
11-
* @param {string} extension
13+
* @param {string} extension
1214
*/
13-
function dropHook(extension) {
15+
function detachHook(extension) {
1416
delete require.extensions[extension];
1517
}
1618

19+
const Through = plugin('through', function postcssThrough(processor) {
20+
return css => processor(css);
21+
});
22+
1723
exports.dropCache = dropCache;
18-
exports.dropHook = dropHook;
24+
exports.detachHook = detachHook;
25+
exports.Through = Through;

0 commit comments

Comments
 (0)