|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import { buildApplication } from '../../index';
|
| 10 | +import { OutputHashing } from '../../schema'; |
10 | 11 | import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
|
11 | 12 |
|
12 | 13 | describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
|
@@ -164,46 +165,131 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
|
164 | 165 | );
|
165 | 166 | });
|
166 | 167 |
|
167 |
| - it('should not rebase a URL with a namespaced Sass variable reference', async () => { |
168 |
| - await harness.writeFile( |
169 |
| - 'src/styles.scss', |
170 |
| - ` |
171 |
| - @import "a"; |
172 |
| - `, |
173 |
| - ); |
174 |
| - await harness.writeFile( |
175 |
| - 'src/a.scss', |
176 |
| - ` |
177 |
| - @use './b' as named; |
178 |
| - .a { |
179 |
| - background-image: url(named.$my-var) |
180 |
| - } |
181 |
| - `, |
182 |
| - ); |
183 |
| - await harness.writeFile( |
184 |
| - 'src/b.scss', |
185 |
| - ` |
186 |
| - @forward './c.scss' show $my-var; |
187 |
| - `, |
188 |
| - ); |
189 |
| - await harness.writeFile( |
190 |
| - 'src/c.scss', |
191 |
| - ` |
192 |
| - $my-var: "https://example.com/example.png"; |
193 |
| - `, |
194 |
| - ); |
| 168 | + it('should not rebase a URL with a namespaced Sass variable reference that points to an absolute asset', async () => { |
| 169 | + await harness.writeFiles({ |
| 170 | + 'src/styles.scss': `@use 'theme/a';`, |
| 171 | + 'src/theme/a.scss': ` |
| 172 | + @use './b' as named; |
| 173 | + .a { |
| 174 | + background-image: url(named.$my-var) |
| 175 | + } |
| 176 | + `, |
| 177 | + 'src/theme/b.scss': `@forward './c.scss' show $my-var;`, |
| 178 | + 'src/theme/c.scss': `$my-var: "https://example.com/example.png";`, |
| 179 | + }); |
195 | 180 |
|
196 | 181 | harness.useTarget('build', {
|
197 | 182 | ...BASE_OPTIONS,
|
198 | 183 | styles: ['src/styles.scss'],
|
199 | 184 | });
|
200 | 185 |
|
201 | 186 | const { result } = await harness.executeOnce();
|
202 |
| - expect(result?.success).toBe(true); |
| 187 | + expect(result?.success).toBeTrue(); |
203 | 188 |
|
204 | 189 | harness
|
205 | 190 | .expectFile('dist/browser/styles.css')
|
206 | 191 | .content.toContain('url(https://example.com/example.png)');
|
207 | 192 | });
|
| 193 | + |
| 194 | + it('should not rebase a URL with a Sass variable reference that points to an absolute asset', async () => { |
| 195 | + await harness.writeFiles({ |
| 196 | + 'src/styles.scss': `@use 'theme/a';`, |
| 197 | + 'src/theme/a.scss': ` |
| 198 | + @import './b'; |
| 199 | + .a { |
| 200 | + background-image: url($my-var) |
| 201 | + } |
| 202 | + `, |
| 203 | + 'src/theme/b.scss': `$my-var: "https://example.com/example.png";`, |
| 204 | + }); |
| 205 | + |
| 206 | + harness.useTarget('build', { |
| 207 | + ...BASE_OPTIONS, |
| 208 | + styles: ['src/styles.scss'], |
| 209 | + }); |
| 210 | + |
| 211 | + const { result } = await harness.executeOnce(); |
| 212 | + expect(result?.success).toBeTrue(); |
| 213 | + |
| 214 | + harness |
| 215 | + .expectFile('dist/browser/styles.css') |
| 216 | + .content.toContain('url(https://example.com/example.png)'); |
| 217 | + }); |
| 218 | + |
| 219 | + it('should rebase a URL with a namespaced Sass variable referencing a local resource', async () => { |
| 220 | + await harness.writeFiles({ |
| 221 | + 'src/styles.scss': `@use 'theme/a';`, |
| 222 | + 'src/theme/a.scss': ` |
| 223 | + @use './b' as named; |
| 224 | + .a { |
| 225 | + background-image: url(named.$my-var) |
| 226 | + } |
| 227 | + `, |
| 228 | + 'src/theme/b.scss': `@forward './c.scss' show $my-var;`, |
| 229 | + 'src/theme/c.scss': `$my-var: "./images/logo.svg";`, |
| 230 | + 'src/theme/images/logo.svg': `<svg></svg>`, |
| 231 | + }); |
| 232 | + |
| 233 | + harness.useTarget('build', { |
| 234 | + ...BASE_OPTIONS, |
| 235 | + outputHashing: OutputHashing.None, |
| 236 | + styles: ['src/styles.scss'], |
| 237 | + }); |
| 238 | + |
| 239 | + const { result } = await harness.executeOnce(); |
| 240 | + expect(result?.success).toBeTrue(); |
| 241 | + |
| 242 | + harness.expectFile('dist/browser/styles.css').content.toContain(`url("./media/logo.svg")`); |
| 243 | + harness.expectFile('dist/browser/media/logo.svg').toExist(); |
| 244 | + }); |
| 245 | + |
| 246 | + it('should rebase a URL with a Sass variable referencing a local resource', async () => { |
| 247 | + await harness.writeFiles({ |
| 248 | + 'src/styles.scss': `@use 'theme/a';`, |
| 249 | + 'src/theme/a.scss': ` |
| 250 | + @import './b'; |
| 251 | + .a { |
| 252 | + background-image: url($my-var) |
| 253 | + } |
| 254 | + `, |
| 255 | + 'src/theme/b.scss': `$my-var: "./images/logo.svg";`, |
| 256 | + 'src/theme/images/logo.svg': `<svg></svg>`, |
| 257 | + }); |
| 258 | + |
| 259 | + harness.useTarget('build', { |
| 260 | + ...BASE_OPTIONS, |
| 261 | + outputHashing: OutputHashing.None, |
| 262 | + styles: ['src/styles.scss'], |
| 263 | + }); |
| 264 | + |
| 265 | + const { result } = await harness.executeOnce(); |
| 266 | + expect(result?.success).toBeTrue(); |
| 267 | + |
| 268 | + harness.expectFile('dist/browser/styles.css').content.toContain(`url("./media/logo.svg")`); |
| 269 | + harness.expectFile('dist/browser/media/logo.svg').toExist(); |
| 270 | + }); |
| 271 | + |
| 272 | + it('should not process a URL that has been marked as external', async () => { |
| 273 | + await harness.writeFiles({ |
| 274 | + 'src/styles.scss': `@use 'theme/a';`, |
| 275 | + 'src/theme/a.scss': ` |
| 276 | + .a { |
| 277 | + background-image: url("assets/logo.svg") |
| 278 | + } |
| 279 | + `, |
| 280 | + }); |
| 281 | + |
| 282 | + harness.useTarget('build', { |
| 283 | + ...BASE_OPTIONS, |
| 284 | + outputHashing: OutputHashing.None, |
| 285 | + externalDependencies: ['assets/*'], |
| 286 | + styles: ['src/styles.scss'], |
| 287 | + }); |
| 288 | + |
| 289 | + const { result } = await harness.executeOnce(); |
| 290 | + expect(result?.success).toBeTrue(); |
| 291 | + |
| 292 | + harness.expectFile('dist/browser/styles.css').content.toContain(`url(assets/logo.svg)`); |
| 293 | + }); |
208 | 294 | });
|
209 | 295 | });
|
0 commit comments