'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*global describe, it */
'use strict';
 
var fs         = require( 'fs' );
var assert     = require( 'assert' );
var postcss    = require( 'postcss' );
var urlrewrite = require( '../index.js' );
 
var fixture = function ( name ) {
    return fs.readFileSync( 'test/fixtures/' + name + '.css', 'utf8' ).trim();
};
 
var compareFixtures = function ( name, options ) {
    var actual = postcss( urlrewrite( options ) ).process( fixture( name ) ).css.trim();
    var expected = fixture( name + '.out' );
    return assert.equal( actual, expected );
};
 
describe( 'postcss-urlrewrite', function() {
    describe( 'paths in absolute rules', function() {
        it( 'should be replaced', function() {
            var config = {
                rules: [
                    { from: 'http://www.google.com/', 'to': 'http://yandex.ru/' },
                    { from: /^\//, to: 'http://mysite.com/' }
                ]
            };
 
            compareFixtures( 'absolute', config );
        });
    });
 
    describe( 'different file types', function() {
        it( 'should return must not affect replacement', function() {
            var config = {
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'backgrounds', config );
        });
    });
 
    describe( 'data-uris', function() {
        it( 'should be replaceable', function() {
            var config = {
                rules: function( uri ) { uri.href( 'image.png' ); }
            };
 
            compareFixtures( 'datauri', config );
        });
    });
 
    describe( 'only "content" and "cursor" properties', function() {
        it( 'should be updated', function() {
            var config = {
                properties: [ 'content', 'cursor' ],
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'filter', config );
        });
    });
 
    describe( 'fonts src with ie hacks', function() {
        it( 'should be replaced without errors', function() {
            var config = {
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'fonts', config );
        });
    });
 
    describe( 'only "content" and "cursor" properties', function() {
        it( 'should be updated', function() {
            var config = {
                imports: true,
                properties: false,
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'imports', config );
        });
    });
 
    describe( 'multiple url() in property value', function() {
        it( 'should be replaced without errors', function() {
            var config = {
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'multiple', config );
        });
    });
 
    describe( 'all properties from css 2.1 spec', function() {
        it( 'should be replaceable', function() {
            var config = {
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'properties', config );
        });
    });
 
    describe( 'if multiple rules match value', function() {
        it( 'only first should trigger replace', function() {
            var config = {
                rules: [
                    { from: /local\/test/, 'to': '$&1' },
                    { from: /global\/test/, 'to': '$&2' },
                    { from: /test/, 'to': '$&3' }
                ]
            };
 
            compareFixtures( 'rules', config );
        });
    });
 
    describe( 'if properties value is "true"', function() {
        it( 'it should not return error', function() {
            var config = {
                properties: true,
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'properties-default', config );
        });
    });
 
    describe( 'if blank url()', function() {
        it( 'it should not return error', function() {
            var config = {
                rules: [
                    { from: 'local', 'to': 'global' }
                ]
            };
 
            compareFixtures( 'blank-url', config );
        });
    });
} );