File tree Expand file tree Collapse file tree 9 files changed +134
-9
lines changed Expand file tree Collapse file tree 9 files changed +134
-9
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const detachHook = require ( '../sugar' ) . detachHook ;
1
2
const dropCache = require ( '../sugar' ) . dropCache ;
2
- const dropHook = require ( '../sugar' ) . dropHook ;
3
3
const identity = require ( 'lodash' ) . identity ;
4
- const spy = require ( 'sinon' ) . spy ;
5
4
6
5
suite ( 'api/extensions' , ( ) => {
7
6
suite ( 'uses .css by default' , ( ) => {
@@ -14,7 +13,7 @@ suite('api/extensions', () => {
14
13
15
14
teardown ( ( ) => {
16
15
dropCache ( './api/fixture/oceanic.css' ) ;
17
- dropHook ( '.css' ) ;
16
+ detachHook ( '.css' ) ;
18
17
} ) ;
19
18
} ) ;
20
19
} ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const detachHook = require ( '../sugar' ) . detachHook ;
1
2
const dropCache = require ( '../sugar' ) . dropCache ;
2
3
const identity = require ( 'lodash' ) . identity ;
3
- const spy = require ( 'sinon' ) . spy ;
4
4
5
5
suite ( 'api/processCss()' , ( ) => {
6
6
const processCss = spy ( identity ) ;
7
7
8
8
test ( 'should be called' , ( ) => assert ( processCss . called ) ) ;
9
9
10
10
setup ( ( ) => {
11
- hook ( { processCss : processCss } ) ;
11
+ hook ( { processCss} ) ;
12
12
require ( './fixture/oceanic.css' ) ;
13
13
} ) ;
14
14
15
- teardown ( ( ) => dropCache ( './api/fixture/oceanic.css' ) ) ;
15
+ teardown ( ( ) => {
16
+ dropCache ( './api/fixture/oceanic.css' ) ;
17
+ detachHook ( '.css' ) ;
18
+ } ) ;
16
19
} ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change 1
1
global . assert = require ( 'assert' ) ;
2
2
global . hook = require ( '../' ) ;
3
+ global . spy = require ( 'sinon' ) . spy ;
Original file line number Diff line number Diff line change
1
+ const plugin = require ( 'postcss' ) . plugin ;
2
+
1
3
/**
2
4
* Drops require cache for the certain module
3
5
*
@@ -8,11 +10,16 @@ function dropCache(modulePath) {
8
10
} ;
9
11
10
12
/**
11
- * @param {string } extension
13
+ * @param {string } extension
12
14
*/
13
- function dropHook ( extension ) {
15
+ function detachHook ( extension ) {
14
16
delete require . extensions [ extension ] ;
15
17
}
16
18
19
+ const Through = plugin ( 'through' , function postcssThrough ( processor ) {
20
+ return css => processor ( css ) ;
21
+ } ) ;
22
+
17
23
exports . dropCache = dropCache ;
18
- exports . dropHook = dropHook ;
24
+ exports . detachHook = detachHook ;
25
+ exports . Through = Through ;
You can’t perform that action at this time.
0 commit comments