Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/postcss-capsize. PostCSS plugin to inject Capsize font metrics
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import type { FontMetrics } from '@capsizecss/core'import type Processor from 'postcss/lib/processor'import postcss from 'postcss'
import { beforeEach, describe, expect, it } from 'vitest'
import pluginCreator from '../src'
describe(`plugin`, () => { let processor: Processor
beforeEach(() => { processor = postcss([ pluginCreator({ metrics: { 'Test Mono': { capHeight: 100, ascent: 800, descent: -200, lineGap: 0, unitsPerEm: 1000, } as FontMetrics, }, }), ]) }) it('renders correct CSS', async () => { const result = await processor.process( ` .test { font-metrics: 24px Test Mono 10px; }`, { from: undefined }, ) expect(result.css).toMatchSnapshot() }) it('renders correct CSS with line-gap syntax', async () => { const result = await processor.process( ` .test { font-family: 'Gaudy Mono', 'Test Mono', sans-serif; font-size: 24px; line-gap: 10px; }`, { from: undefined }, ) expect(result.css).toMatchSnapshot() }) it('throws an error with invalid declaration', async () => { const invalidOptions = [ `.test { font-metrics: Test Mono 10px; }`, `.test { line-gap: 10rem; }`, `.test { line-gap: 10px; }`, `.test { line-gap: 10px; font-size: 10vw; }`, `.test { line-gap: 10px; font-size: 10px; }`, ] await Promise.all( invalidOptions.map(async (css) => { let errored = false try { await processor.process(css, { from: undefined }) } catch { errored = true } expect(errored).toBeTruthy() }), ) })})