Skip to content

Commit

Permalink
fix: overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Nov 23, 2023
1 parent 1a46fc5 commit c82bb6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export class Downloader extends Hookable<DownloaderHooks> {
const currentCssContent = readFileSync(cssPath, 'utf-8')
const currentUrl = (currentCssContent.split(/\r?\n/, 1).shift() || '').replace('/*', '').replace('*/', '').trim()

overwriting = currentUrl !== this.url
if (currentUrl === this.url) {
return
}

overwriting = true
}

if (overwriting) {
Expand Down
29 changes: 28 additions & 1 deletion test/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('download', () => {
rmSync(outputDir, { recursive: true, force: true })
}, 60000)

test('overwriting', async () => {
test('force overwriting when a different url', async () => {
const outputDir = temporaryDirectory()
const stylePath = 'font.css'
const fontsDir = 'fonts'
Expand Down Expand Up @@ -51,6 +51,33 @@ describe('download', () => {
rmSync(outputDir, { recursive: true, force: true })
}, 60000)

test('download only once', async () => {
const outputDir = temporaryDirectory()
const stylePath = 'font.css'
const fontsDir = 'fonts'
const config = {
families: {
Roboto: true
}
}

const url = constructURL(config) || ''

await download(url, { outputDir, stylePath, fontsDir }).execute()

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(true)
expect(readFileSync(join(outputDir, stylePath), 'utf-8')).toContain(url)
rmSync(join(outputDir, fontsDir), { recursive: true, force: true })

await download(url, { outputDir, stylePath, fontsDir }).execute()

expect(existsSync(join(outputDir, stylePath))).toBe(true)
expect(existsSync(join(outputDir, fontsDir))).toBe(false)

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

test('base64', async () => {
const outputDir = temporaryDirectory()
const stylePath = 'font.css'
Expand Down

0 comments on commit c82bb6d

Please sign in to comment.