1+ const buffer = require ( 'vinyl-buffer' ) ;
2+ const chai = require ( 'chai' ) ;
3+ const cleanCSS = require ( '..' ) ;
4+ const concat = require ( 'gulp-concat' ) ;
5+ const del = require ( 'del' ) ;
6+ const expect = chai . expect ;
7+ const File = require ( 'vinyl' ) ;
8+ const gulp = require ( 'gulp' ) ;
9+ const gulpSass = require ( 'gulp-sass' ) ;
10+ const rename = require ( 'gulp-rename' ) ;
11+ const sourcemaps = require ( 'gulp-sourcemaps' ) ;
12+ const vfsFake = require ( 'vinyl-fs-fake' ) ;
13+
14+ chai . should ( ) ;
15+
16+ describe ( 'gulp-clean-css: rebase' , function ( ) {
17+
18+ it ( 'should not rebase files by default' , function ( done ) {
19+
20+ // CLI: cleancss test/fixtures/rebasing/subdir/insub.css
21+ gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
22+ . pipe ( cleanCSS ( ) )
23+ . on ( 'data' , function ( file ) {
24+ expect ( file . contents . toString ( ) ) . to . equal (
25+ 'p.insub_same{background:url(insub.png)}' +
26+ 'p.insub_parent{background:url(../parent.png)}' +
27+ 'p.insub_other{background:url(../othersub/inother.png)}' +
28+ 'p.insub_absolute{background:url(/inroot.png)}'
29+ ) ;
30+ } )
31+ . once ( 'end' , function ( ) {
32+ done ( ) ;
33+ } ) ;
34+ } ) ;
35+
36+ // CLI: cleancss test/fixtures/rebasing/subdir/insub.css -o test/fixtures/rebasing/min.generated.css
37+ it ( 'should by rebase files with target specified' , function ( done ) {
38+ gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
39+ . pipe ( cleanCSS ( { target : 'test/fixtures/rebasing/min.generated.css' } ) )
40+ . on ( 'data' , function ( file ) {
41+ expect ( file . contents . toString ( ) ) . to . equal (
42+ 'p.insub_same{background:url(subdir/insub.png)}' +
43+ 'p.insub_parent{background:url(parent.png)}' +
44+ 'p.insub_other{background:url(othersub/inother.png)}' +
45+ 'p.insub_absolute{background:url(/inroot.png)}'
46+ ) ;
47+ } )
48+ . once ( 'end' , function ( ) {
49+ done ( ) ;
50+ } ) ;
51+ } ) ;
52+
53+ // CLI: cleancss test/fixtures/rebasing/subdir/insub.css -o test/fixtures/rebasing/subdir/min.generated.css
54+ it ( 'should by rebase files with target in subdir specified' , function ( done ) {
55+ gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
56+ . pipe ( cleanCSS ( { target : 'test/fixtures/rebasing/subdir/min.generated.css' } ) )
57+ . on ( 'data' , function ( file ) {
58+ expect ( file . contents . toString ( ) ) . to . equal (
59+ 'p.insub_same{background:url(insub.png)}' +
60+ 'p.insub_parent{background:url(../parent.png)}' +
61+ 'p.insub_other{background:url(../othersub/inother.png)}' +
62+ 'p.insub_absolute{background:url(/inroot.png)}'
63+ ) ;
64+ } )
65+ . once ( 'end' , function ( ) {
66+ done ( ) ;
67+ } ) ;
68+ } ) ;
69+
70+ // CLI: cleancss test/fixtures/rebasing/subdir/insub.css --root test/fixtures/rebasing/
71+ it ( 'should rebase files with root specified' , function ( done ) {
72+ gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
73+ . pipe ( cleanCSS ( { root : 'test/fixtures/rebasing/' } ) )
74+ . on ( 'data' , function ( file ) {
75+ expect ( file . contents . toString ( ) ) . to . equal (
76+ 'p.insub_same{background:url(/subdir/insub.png)}' +
77+ 'p.insub_parent{background:url(/parent.png)}' +
78+ 'p.insub_other{background:url(/othersub/inother.png)}' +
79+ 'p.insub_absolute{background:url(/inroot.png)}'
80+ ) ;
81+ } )
82+ . once ( 'end' , function ( ) {
83+ done ( ) ;
84+ } )
85+ } ) ;
86+
87+ // CLI: cleancss test/fixtures/rebasing/subdir/insub.css --root test/fixtures/rebasing/ -o test/fixtures/rebasing/subdir/min.generated.css
88+ it ( 'should rebase files with root and target specified' , function ( done ) {
89+ gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
90+ . pipe ( cleanCSS ( {
91+ root : 'test/fixtures/rebasing/' ,
92+ target : 'test/fixtures/rebasing/subdir/min.generated.css'
93+ } ) )
94+ . on ( 'data' , function ( file ) {
95+ expect ( file . contents . toString ( ) ) . to . equal (
96+ 'p.insub_same{background:url(/subdir/insub.png)}' +
97+ 'p.insub_parent{background:url(/parent.png)}' +
98+ 'p.insub_other{background:url(/othersub/inother.png)}' +
99+ 'p.insub_absolute{background:url(/inroot.png)}'
100+ ) ;
101+ } )
102+ . once ( 'end' , function ( ) {
103+ done ( ) ;
104+ } )
105+ } ) ;
106+
107+ // CLI: cleancss test/fixtures/rebasing/subdir/import.css
108+ it ( 'should resolve imports correctly' , function ( done ) {
109+ gulp . src ( [ 'test/fixtures/rebasing/subdir/import.css' ] )
110+ . pipe ( cleanCSS ( ) )
111+ . on ( 'data' , function ( file ) {
112+ expect ( file . contents . toString ( ) ) . to . equal (
113+ 'p.imported_nested{background:url(../otherdir/nestedsub/nested.png)}' +
114+ 'p.imported_same{background:url(../otherdir/imported.png)}' +
115+ 'p.imported_parent{background:url(../parent.png)}' +
116+ 'p.imported_other{background:url(../othersub/inother.png)}' +
117+ 'p.imported_absolute{background:url(/inroot.png)}' +
118+ 'p.insub_same{background:url(insub.png)}' +
119+ 'p.insub_parent{background:url(../parent.png)}' +
120+ 'p.insub_other{background:url(../othersub/inother.png)}' +
121+ 'p.insub_absolute{background:url(/inroot.png)}' +
122+ 'p.import{background:url(import.png)}'
123+ ) ;
124+ } )
125+ . once ( 'end' , function ( ) {
126+ done ( ) ;
127+ } )
128+ } ) ;
129+
130+ // CLI: cleancss test/fixtures/rebasing/subdir/import.css -o test/fixtures/root.generated.css
131+ it ( 'should resolve imports with target set correctly' , function ( done ) {
132+ gulp . src ( [ 'test/fixtures/rebasing/subdir/import.css' ] )
133+ . pipe ( cleanCSS ( { target : 'test/fixtures/root.generated.css' } ) )
134+ . on ( 'data' , function ( file ) {
135+ expect ( file . contents . toString ( ) ) . to . equal (
136+ 'p.imported_nested{background:url(rebasing/otherdir/nestedsub/nested.png)}' +
137+ 'p.imported_same{background:url(rebasing/otherdir/imported.png)}' +
138+ 'p.imported_parent{background:url(rebasing/parent.png)}' +
139+ 'p.imported_other{background:url(rebasing/othersub/inother.png)}' +
140+ 'p.imported_absolute{background:url(/inroot.png)}' +
141+ 'p.insub_same{background:url(rebasing/subdir/insub.png)}' +
142+ 'p.insub_parent{background:url(rebasing/parent.png)}' +
143+ 'p.insub_other{background:url(rebasing/othersub/inother.png)}' +
144+ 'p.insub_absolute{background:url(/inroot.png)}' +
145+ 'p.import{background:url(rebasing/subdir/import.png)}'
146+ ) ;
147+ } )
148+ . once ( 'end' , function ( ) {
149+ done ( ) ;
150+ } )
151+ } ) ;
152+
153+ // CLI: cleancss test/fixtures/rebasing/subdir/import_absolute.css --root test/fixtures/
154+ it ( 'should resolve absolute imports with root set correctly' , function ( done ) {
155+ gulp . src ( [ 'test/fixtures/rebasing/subdir/import_absolute.css' ] )
156+ . pipe ( cleanCSS ( { root : 'test/fixtures/' } ) )
157+ . on ( 'data' , function ( file ) {
158+ expect ( file . contents . toString ( ) ) . to . equal (
159+ 'p.imported_nested{background:url(/rebasing/otherdir/nestedsub/nested.png)}' +
160+ 'p.imported_same{background:url(/rebasing/otherdir/imported.png)}' +
161+ 'p.imported_parent{background:url(/rebasing/parent.png)}' +
162+ 'p.imported_other{background:url(/rebasing/othersub/inother.png)}' +
163+ 'p.imported_absolute{background:url(/inroot.png)}' +
164+ 'p.insub_same{background:url(/rebasing/subdir/insub.png)}' +
165+ 'p.insub_parent{background:url(/rebasing/parent.png)}' +
166+ 'p.insub_other{background:url(/rebasing/othersub/inother.png)}' +
167+ 'p.insub_absolute{background:url(/inroot.png)}' +
168+ 'p.fromroot{background:url(/rebasing/sbudir/insubdir.png)}' +
169+ 'p.root{background:url(/rebasing/inroot.png)}' +
170+ 'p.import{background:url(/rebasing/subdir/import.png)}'
171+ ) ;
172+ } )
173+ . once ( 'end' , function ( ) {
174+ done ( ) ;
175+ } )
176+ } ) ;
177+
178+ // CLI: cleancss test/fixtures/rebasing/subdir/import_absolute.css --root test/fixtures/ -o test/fixtures/rebasing/subdir/min.generated.css
179+ it ( 'should resolve imports with root and target set correctly' , function ( done ) {
180+ gulp . src ( [ 'test/fixtures/rebasing/subdir/import_absolute.css' ] )
181+ . pipe ( cleanCSS ( { root : 'test/fixtures/' , target : 'test/fixtures/rebasing/subdir/min.generated.css' } ) )
182+ . on ( 'data' , function ( file ) {
183+ expect ( file . contents . toString ( ) ) . to . equal (
184+ 'p.imported_nested{background:url(/rebasing/otherdir/nestedsub/nested.png)}' +
185+ 'p.imported_same{background:url(/rebasing/otherdir/imported.png)}' +
186+ 'p.imported_parent{background:url(/rebasing/parent.png)}' +
187+ 'p.imported_other{background:url(/rebasing/othersub/inother.png)}' +
188+ 'p.imported_absolute{background:url(/inroot.png)}' +
189+ 'p.insub_same{background:url(/rebasing/subdir/insub.png)}' +
190+ 'p.insub_parent{background:url(/rebasing/parent.png)}' +
191+ 'p.insub_other{background:url(/rebasing/othersub/inother.png)}' +
192+ 'p.insub_absolute{background:url(/inroot.png)}' +
193+ 'p.fromroot{background:url(/rebasing/sbudir/insubdir.png)}' +
194+ 'p.root{background:url(/rebasing/inroot.png)}' +
195+ 'p.import{background:url(/rebasing/subdir/import.png)}'
196+ ) ;
197+ } )
198+ . once ( 'end' , function ( ) {
199+ done ( ) ;
200+ } )
201+ } ) ;
202+ } ) ;
0 commit comments