From f59f2c1edb02a1955f5d16ee5a4ee042569f94ed Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sun, 28 Jul 2024 13:08:50 -0700 Subject: [PATCH] test: use assertions instead of snapshot --- .../create-optimized-css.test.ts.snap | 85 --------- .../optimize-imports.test.ts.snap | 18 -- tests/create-optimized-css.test.ts | 168 ++++++++++++------ tests/optimize-imports.test.ts | 35 ++-- 4 files changed, 137 insertions(+), 169 deletions(-) delete mode 100644 tests/__snapshots__/create-optimized-css.test.ts.snap delete mode 100644 tests/__snapshots__/optimize-imports.test.ts.snap diff --git a/tests/__snapshots__/create-optimized-css.test.ts.snap b/tests/__snapshots__/create-optimized-css.test.ts.snap deleted file mode 100644 index a7d055f..0000000 --- a/tests/__snapshots__/create-optimized-css.test.ts.snap +++ /dev/null @@ -1,85 +0,0 @@ -// Bun Snapshot v1, https://goo.gl/fbAQLP - -exports[`create-optimized-css removes unused selectors 1`] = ` -" - * { box-sizing: border-box } - a { color: blue } - .bx--accordion { background-color: yellow } - .bx--accordion--end, .bx--accordion__content {color: black } - " -`; - -exports[`create-optimized-css removes unused IBM @font rules 1`] = ` -" - @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; - }" -`; - -exports[`create-optimized-css preserves all IBM fonts 1`] = ` -" - @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; - }" -`; diff --git a/tests/__snapshots__/optimize-imports.test.ts.snap b/tests/__snapshots__/optimize-imports.test.ts.snap deleted file mode 100644 index e01aca0..0000000 --- a/tests/__snapshots__/optimize-imports.test.ts.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Bun Snapshot v1, https://goo.gl/fbAQLP - -exports[`optimizeImports barrel imports 1`] = ` -" - 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"; - " -`; diff --git a/tests/create-optimized-css.test.ts b/tests/create-optimized-css.test.ts index c1e53e1..7adce94 100644 --- a/tests/create-optimized-css.test.ts +++ b/tests/create-optimized-css.test.ts @@ -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", () => { @@ -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; +}`) }); }); diff --git a/tests/optimize-imports.test.ts b/tests/optimize-imports.test.ts index 12f0230..d0a9eef 100644 --- a/tests/optimize-imports.test.ts +++ b/tests/optimize-imports.test.ts @@ -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";`) }); });