fix style content url normalizer and add some tests

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent bbf23157c5
commit 349d78e02b
3 changed files with 53 additions and 2 deletions

31
test/snapshot.test.ts Normal file
View File

@@ -0,0 +1,31 @@
import 'mocha';
import { expect } from 'chai';
import { absoluteToStylesheet } from '../src/snapshot';
describe('absolute url to stylesheet', () => {
const href = 'http://localhost/css/style.css';
it('can handle same level path', () => {
expect(absoluteToStylesheet('url("./a.jpg")', href)).to.equal(
`url('http://localhost/css/a.jpg')`,
);
});
it('can handle parent level path', () => {
expect(absoluteToStylesheet('url("../a.jpg")', href)).to.equal(
`url('http://localhost/a.jpg')`,
);
});
it('can handle absolute path', () => {
expect(absoluteToStylesheet('url("/a.jpg")', href)).to.equal(
`url('http://localhost/a.jpg')`,
);
});
it('can handle external path', () => {
expect(
absoluteToStylesheet('url("http://localhost/a.jpg")', href),
).to.equal(`url('http://localhost/a.jpg')`);
});
});