mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
I noticed uncommitted changes of #15275 on my local setup so here's the updated changelog and the added unit test.
138 lines
4.8 KiB
TypeScript
138 lines
4.8 KiB
TypeScript
import { expect, test } from 'vitest'
|
|
import { rewriteUrls } from './urls'
|
|
|
|
const css = String.raw
|
|
|
|
test('URLs can be rewritten', async () => {
|
|
let root = '/root'
|
|
|
|
let result = await rewriteUrls({
|
|
root,
|
|
base: '/root/foo/bar',
|
|
// prettier-ignore
|
|
css: css`
|
|
.foo {
|
|
/* Relative URLs: replaced */
|
|
background: url(./image.jpg);
|
|
background: url(../image.jpg);
|
|
background: url('./image.jpg');
|
|
background: url("./image.jpg");
|
|
|
|
/* Absolute URLs: ignored */
|
|
background: url(/image.jpg);
|
|
background: url(/foo/image.jpg);
|
|
background: url('/image.jpg');
|
|
background: url("/image.jpg");
|
|
|
|
/* External URL: ignored */
|
|
background: url(http://example.com/image.jpg);
|
|
background: url('http://example.com/image.jpg');
|
|
background: url("http://example.com/image.jpg");
|
|
|
|
/* Data URI: ignored */
|
|
/* background: url(data:image/png;base64,abc==); */
|
|
background: url('data:image/png;base64,abc==');
|
|
background: url("data:image/png;base64,abc==");
|
|
|
|
/* Function calls: ignored */
|
|
background: url(var(--foo));
|
|
background: url(var(--foo, './image.jpg'));
|
|
background: url(var(--foo, "./image.jpg"));
|
|
|
|
/* Fragments: ignored */
|
|
background: url(#dont-touch-this);
|
|
|
|
/* Image Sets - Raw URL: replaced */
|
|
background: image-set(
|
|
image1.jpg 1x,
|
|
image2.jpg 2x
|
|
);
|
|
background: image-set(
|
|
'image1.jpg' 1x,
|
|
'image2.jpg' 2x
|
|
);
|
|
background: image-set(
|
|
"image1.jpg" 1x,
|
|
"image2.jpg" 2x
|
|
);
|
|
|
|
/* Image Sets - Relative URLs: replaced */
|
|
background: image-set(
|
|
url('image1.jpg') 1x,
|
|
url('image2.jpg') 2x
|
|
);
|
|
background: image-set(
|
|
url("image1.jpg") 1x,
|
|
url("image2.jpg") 2x
|
|
);
|
|
background: image-set(
|
|
url('image1.avif') type('image/avif'),
|
|
url('image2.jpg') type('image/jpeg')
|
|
);
|
|
background: image-set(
|
|
url("image1.avif") type('image/avif'),
|
|
url("image2.jpg") type('image/jpeg')
|
|
);
|
|
|
|
/* Image Sets - Function calls: ignored */
|
|
background: image-set(
|
|
linear-gradient(blue, white) 1x,
|
|
linear-gradient(blue, green) 2x
|
|
);
|
|
|
|
/* Image Sets - Mixed: replaced */
|
|
background: image-set(
|
|
linear-gradient(blue, white) 1x,
|
|
url("image2.jpg") 2x
|
|
);
|
|
}
|
|
|
|
/* Fonts - Multiple URLs: replaced */
|
|
@font-face {
|
|
font-family: "Newman";
|
|
src:
|
|
local("Newman"),
|
|
url("newman-COLRv1.otf") format("opentype") tech(color-COLRv1),
|
|
url("newman-outline.otf") format("opentype"),
|
|
url("newman-outline.woff") format("woff");
|
|
}
|
|
`,
|
|
})
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
".foo {
|
|
background: url(./foo/bar/image.jpg);
|
|
background: url(./foo/image.jpg);
|
|
background: url('./foo/bar/image.jpg');
|
|
background: url("./foo/bar/image.jpg");
|
|
background: url(/image.jpg);
|
|
background: url(/foo/image.jpg);
|
|
background: url('/image.jpg');
|
|
background: url("/image.jpg");
|
|
background: url(http://example.com/image.jpg);
|
|
background: url('http://example.com/image.jpg');
|
|
background: url("http://example.com/image.jpg");
|
|
background: url('data:image/png;base64,abc==');
|
|
background: url("data:image/png;base64,abc==");
|
|
background: url(var(--foo));
|
|
background: url(var(--foo, './image.jpg'));
|
|
background: url(var(--foo, "./image.jpg"));
|
|
background: url(#dont-touch-this);
|
|
background: image-set(url(./foo/bar/image1.jpg) 1x, url(./foo/bar/image2.jpg) 2x);
|
|
background: image-set(url('./foo/bar/image1.jpg') 1x, url('./foo/bar/image2.jpg') 2x);
|
|
background: image-set(url("./foo/bar/image1.jpg") 1x, url("./foo/bar/image2.jpg") 2x);
|
|
background: image-set(url('./foo/bar/image1.jpg') 1x, url('./foo/bar/image2.jpg') 2x);
|
|
background: image-set(url("./foo/bar/image1.jpg") 1x, url("./foo/bar/image2.jpg") 2x);
|
|
background: image-set(url('./foo/bar/image1.avif') type('image/avif'), url('./foo/bar/image2.jpg') type('image/jpeg'));
|
|
background: image-set(url("./foo/bar/image1.avif") type('image/avif'), url("./foo/bar/image2.jpg") type('image/jpeg'));
|
|
background: image-set(linear-gradient(blue, white) 1x, linear-gradient(blue, green) 2x);
|
|
background: image-set(linear-gradient(blue, white) 1x, url("./foo/bar/image2.jpg") 2x);
|
|
}
|
|
@font-face {
|
|
font-family: "Newman";
|
|
src: local("Newman"), url("./foo/bar/newman-COLRv1.otf") format("opentype") tech(color-COLRv1), url("./foo/bar/newman-outline.otf") format("opentype"), url("./foo/bar/newman-outline.woff") format("woff");
|
|
}
|
|
"
|
|
`)
|
|
})
|