Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: resolve config paths fully and warn on config errors (#522)
- Loading branch information
Showing
6 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, test, expect, vi } from 'vitest' | ||
import { mockedWarn } from 'consola' | ||
import { useTestContext } from '@nuxt/test-utils' | ||
import { setupNuxtTailwind } from './util' | ||
|
||
describe('tailwindcss module configs', async () => { | ||
vi.mock('consola', async () => { | ||
const { default: mod } = (await vi.importActual<typeof import('consola')>('consola')) | ||
mod.withScope = () => mod | ||
mod.info = vi.fn() | ||
mod.warn = vi.fn() | ||
return { default: mod, info: mod.info, mockedWarn: mod.warn } | ||
}) | ||
|
||
await setupNuxtTailwind({ | ||
exposeConfig: true, | ||
configPath: [ | ||
'alt-tailwind.config.js', | ||
'malformed-tailwind.config', | ||
'ts-tailwind.config' | ||
], | ||
cssPath: 'tailwind.css' | ||
}) | ||
|
||
test('throws error about malformed config', () => { | ||
expect(mockedWarn.mock.calls[0][0]).toMatchInlineSnapshot('"Failed to load Tailwind config at: `./malformed-tailwind.config.js`"') | ||
expect(mockedWarn.mock.calls[0][0]).contains('Failed to load Tailwind config at: `./malformed-tailwind.config.js`') | ||
|
||
expect(mockedWarn.mock.calls[0].length).toBe(2) | ||
}) | ||
|
||
test('ts config file is loaded and merged', () => { | ||
const nuxt = useTestContext().nuxt | ||
const vfsKey = Object.keys(nuxt.vfs).find(k => k.includes('tailwind.config.')) | ||
// set from ts-tailwind.config.ts | ||
expect(nuxt.vfs[vfsKey]).contains('"typescriptBlue": "#007acc"') | ||
}) | ||
|
||
test('js config file is loaded and merged', () => { | ||
const nuxt = useTestContext().nuxt | ||
const vfsKey = Object.keys(nuxt.vfs).find(k => k.includes('tailwind.config.')) | ||
// set from ts-tailwind.config.ts | ||
expect(nuxt.vfs[vfsKey]).contains('"javascriptYellow": "#f1e05a"') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
theme: { | ||
extend: { | ||
colors: { | ||
javascriptYellow: '#f1e05a' | ||
} | ||
} | ||
}, | ||
content: [ | ||
'content/**/*.md' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
module.exports = { | ||
content: [ | ||
'content/**/*.md' | ||
] | ||
], | ||
theme: { | ||
extend: { | ||
colors: { | ||
primary: '#f1e05a' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Config } from 'tailwindcss' | ||
|
||
export default <Config> { | ||
content: [ | ||
'content/**/*.md' | ||
], | ||
theme: { | ||
extend: { | ||
colors: { | ||
typescriptBlue: '#007acc' | ||
} | ||
} | ||
} | ||
} |