Skip to content

Commit

Permalink
fix: space in font filename (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored Dec 6, 2023
1 parent 2251edb commit 8a7ec71
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function parseFontsFromCss (content: string, fontsPath: string): FontInputOutput
const newFilename = formatFontFileName('{family}-{weight}-{i}.{ext}', {
comment: comment || '',
family: family.replace(/\s+/g, '_'),
weight: weight || '',
weight: weight.replace(/\s+/g, '_') || '',
ext,
i: String(i++)
}).replace(/\.$/, '')
Expand Down
30 changes: 30 additions & 0 deletions test/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ describe('download', () => {
rmSync(outputDir, { recursive: true, force: true })
}, 60000)

test('with a variable fonts', async () => {
const outputDir = temporaryDirectory()
const stylePath = 'font.css'
const fontsDir = 'fonts'

await download('https://fonts.googleapis.com/css2?family=Manrope:[email protected]', {
outputDir,
stylePath,
fontsDir
}).execute()

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-1.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-2.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-3.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-4.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-5.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Manrope-200_800-6.woff2'))).toBe(true)

rmSync(outputDir, { recursive: true, force: true })
}, 60000)

test('with a text', async () => {
const outputDir = temporaryDirectory()
const stylePath = 'font.css'
Expand All @@ -35,6 +58,9 @@ describe('download', () => {

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-400-1.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-600-2.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-700-3.woff2'))).toBe(true)

rmSync(outputDir, { recursive: true, force: true })
}, 60000)
Expand All @@ -52,6 +78,9 @@ describe('download', () => {

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-400-1.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-600-2.woff2'))).toBe(true)
expect(existsSync(join(outputDir, fontsDir, 'Poppins-700-3.woff2'))).toBe(true)

rmSync(outputDir, { recursive: true, force: true })
}, 60000)
Expand Down Expand Up @@ -126,6 +155,7 @@ describe('download', () => {

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(false)
expect(existsSync(join(outputDir, fontsDir, 'Roboto-400-1.woff2'))).toBe(false)

rmSync(outputDir, { recursive: true, force: true })
}, 60000)
Expand Down

0 comments on commit 8a7ec71

Please sign in to comment.