File tree 3 files changed +33
-4
lines changed
3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
import { Transform } from "stream" ;
3
- let prefixBuffer = function ( buffer , prefix ) {
3
+ export function prefixBuffer ( buffer , prefix ) {
4
4
return Buffer . concat ( [ Buffer ( prefix ) , buffer ] ) ;
5
- } ;
5
+ }
6
6
7
- let prefixStream = function ( prefix ) {
7
+ export function prefixStream ( prefix ) {
8
8
return new Transform ( {
9
9
transform : function ( chunk , encoding , next ) {
10
10
let buffer = prefixBuffer ( chunk , prefix ) ;
11
11
this . push ( buffer ) ;
12
12
next ( ) ;
13
13
}
14
14
} ) ;
15
- } ;
15
+ }
16
16
17
17
let gulpTransform = function ( prefix ) {
18
18
// enable `objectMode` of the stream for vinyl File objects.
Original file line number Diff line number Diff line change
1
+ text
Original file line number Diff line number Diff line change
1
+ // LICENSE : MIT
2
+ "use strict" ;
3
+ import assert from "power-assert" ;
4
+ import { createReadStream } from "fs" ;
5
+ import { prefixBuffer , prefixStream } from "../../src/gulp/gulp-prefixer" ;
6
+ describe ( "gulp-prefixer-test" , function ( ) {
7
+ describe ( "#prefixBuffer" , function ( ) {
8
+ it ( "should add prefix text to buffer" , function ( ) {
9
+ let result = prefixBuffer ( Buffer ( "text" ) , "prefix" ) ;
10
+ assert . equal ( result . toString ( ) , "prefixtext" ) ;
11
+ } ) ;
12
+ } ) ;
13
+ describe ( "#prefixStream" , function ( ) {
14
+ it ( "should add prefix text to stream" , function ( done ) {
15
+ let buffer = "" ;
16
+ let stream = createReadStream ( __dirname + "/fixtures/text.txt" ) ;
17
+ stream . pipe ( prefixStream ( "prefix" ) )
18
+ . on ( "data" , function ( chunk ) {
19
+ buffer += chunk ;
20
+ } )
21
+ . on ( "end" , function ( ) {
22
+ assert . equal ( buffer . toString ( ) , "prefixtext" ) ;
23
+ done ( ) ;
24
+ } ) ;
25
+ } ) ;
26
+ } ) ;
27
+
28
+ } ) ;
You can’t perform that action at this time.
0 commit comments