Skip to content

Commit

Permalink
test: use assertions instead of snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jul 29, 2024
1 parent a5a53f1 commit f59f2c1
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 169 deletions.
85 changes: 0 additions & 85 deletions tests/__snapshots__/create-optimized-css.test.ts.snap

This file was deleted.

18 changes: 0 additions & 18 deletions tests/__snapshots__/optimize-imports.test.ts.snap

This file was deleted.

168 changes: 115 additions & 53 deletions tests/create-optimized-css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,91 @@ import { createOptimizedCss } from "../src/plugins/create-optimized-css";
describe("create-optimized-css", () => {
test("removes unused selectors", () => {
const result = createOptimizedCss({
source: `
* { box-sizing: border-box }
a { color: blue }
button.bx--btn { background-color: red }
.bx--btn, .bx--btn--primary { color: white }
.bx--accordion { background-color: yellow }
.bx--accordion--end, .bx--accordion__content {color: black }
`,
source: `* { box-sizing: border-box }
a { color: blue }
button.bx--btn { background-color: red }
.bx--btn, .bx--btn--primary { color: white }
.bx--accordion { background-color: yellow }
.bx--accordion--end, .bx--accordion__content {color: black }`,
ids: ["/Accordion.svelte"],
});
expect(result).toMatchSnapshot();
expect(result).toEqual(`* { box-sizing: border-box }
a { color: blue }
.bx--accordion { background-color: yellow }
.bx--accordion--end, .bx--accordion__content {color: black }`)
});

const font_rules = `
@font-face {
font-family: 'CustomFont';
src: url('path/to/custom-font.ttf');
}
@font-face {
font-display: auto;
font-family: IBM Plex Mono;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 600;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 300;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 700;
}
@font-face {
font-family: IBM Plex Sans;
font-style: italic;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 100;
}`;
const font_rules = `@font-face {
font-family: 'CustomFont';
src: url('path/to/custom-font.ttf');
}
@font-face {
font-display: auto;
font-family: IBM Plex Mono;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 600;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 300;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 700;
}
@font-face {
font-family: IBM Plex Sans;
font-style: italic;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 100;
}`;

test("removes unused @font rules", () => {
const result = createOptimizedCss({
source: font_rules,
ids: ["/Accordion.svelte"],
});
expect(result).toMatchSnapshot();
expect(result).toEqual(`@font-face {
font-family: 'CustomFont';
src: url('path/to/custom-font.ttf');
}
@font-face {
font-display: auto;
font-family: IBM Plex Mono;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 600;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 300;
}`)
});

test("preserves all IBM fonts", () => {
Expand All @@ -73,6 +96,45 @@ describe("create-optimized-css", () => {
ids: ["/Accordion.svelte"],
preserveAllIBMFonts: true,
});
expect(result).toMatchSnapshot();
expect(result).toEqual(`@font-face {
font-family: 'CustomFont';
src: url('path/to/custom-font.ttf');
}
@font-face {
font-display: auto;
font-family: IBM Plex Mono;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 600;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 300;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 700;
}
@font-face {
font-family: IBM Plex Sans;
font-style: italic;
font-weight: 400;
}
@font-face {
font-family: IBM Plex Sans;
font-style: normal;
font-weight: 100;
}`)
});
});
35 changes: 22 additions & 13 deletions tests/optimize-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@ describe("optimizeImports", () => {
test("barrel imports", () => {
expect(
preprocess({
content: `
import { Accordion, AccordionItem } from "carbon-components-svelte";
import { Accordion as Accordion2 } from "carbon-components-svelte";
import { breakpoints } from "carbon-components-svelte";
import { invalid } from "carbon-components-svelte";
content: `import { Accordion, AccordionItem } from "carbon-components-svelte";
import { Accordion as Accordion2 } from "carbon-components-svelte";
import { breakpoints } from "carbon-components-svelte";
import { invalid } from "carbon-components-svelte";
import { Add } from "carbon-icons-svelte";
import { Add as Add2 } from "carbon-icons-svelte";
import Add3 from "carbon-icons-svelte/lib/Add.svelte";
import { Add } from "carbon-icons-svelte";
import { Add as Add2 } from "carbon-icons-svelte";
import Add3 from "carbon-icons-svelte/lib/Add.svelte";
import { Airplane } from "carbon-pictograms-svelte";
import { Airplane as Airplane2 } from "carbon-pictograms-svelte";
import Airplane3 from "carbon-pictograms-svelte/lib/Airplane.svelte";
`,
import { Airplane } from "carbon-pictograms-svelte";
import { Airplane as Airplane2 } from "carbon-pictograms-svelte";
import Airplane3 from "carbon-pictograms-svelte/lib/Airplane.svelte";`,
}),
).toMatchSnapshot();
).toEqual(`import Accordion from "carbon-components-svelte/src/Accordion/Accordion.svelte";import AccordionItem from "carbon-components-svelte/src/Accordion/AccordionItem.svelte";
import Accordion2 from "carbon-components-svelte/src/Accordion/Accordion.svelte";
import breakpoints from "carbon-components-svelte/src/Breakpoint/breakpoints.js";
import { invalid } from "carbon-components-svelte";
import Add from "carbon-icons-svelte/lib/Add.svelte";
import Add2 from "carbon-icons-svelte/lib/Add.svelte";
import Add3 from "carbon-icons-svelte/lib/Add.svelte";
import Airplane from "carbon-pictograms-svelte/lib/Airplane.svelte";
import Airplane2 from "carbon-pictograms-svelte/lib/Airplane.svelte";
import Airplane3 from "carbon-pictograms-svelte/lib/Airplane.svelte";`)
});
});

0 comments on commit f59f2c1

Please sign in to comment.