Skip to content

Commit

Permalink
chore: remove console output testing
Browse files Browse the repository at this point in the history
ineshbose committed Oct 13, 2024
1 parent 5ede5ff commit 98296a8
Showing 2 changed files with 3 additions and 35 deletions.
28 changes: 1 addition & 27 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
import { useTestContext } from '@nuxt/test-utils'
import { describe, test, expect, vi, afterAll } from 'vitest'
import { describe, test, expect } from 'vitest'
import { getVfsFile, r, setupNuxtTailwind } from './utils'

describe('tailwindcss module', async () => {
// Consola will by default set the log level to warn in test, we trick it into thinking we're in debug mode
process.env.DEBUG = 'nuxt:*'
// // Running dev environment for setup in test-utils to test dev options
// process.env.NUXT_TEST_DEV = true

const spyStderr = vi.spyOn(process.stderr, 'write').mockImplementation(() => undefined!)
const spyStdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => undefined!)

afterAll(() => {
spyStderr.mockRestore()
spyStdout.mockRestore()
})

await setupNuxtTailwind({
exposeConfig: { level: 2, alias: '#twcss' },
quiet: false,
// viewer: { endpoint: '_tw' },
cssPath: r('tailwind.css'),
})

test('include custom tailwind.css file in project css', () => {
const nuxt = useTestContext().nuxt!

expect(nuxt.options.css).toHaveLength(1)
expect(nuxt.options.css[0]).toEqual(
// @ts-expect-error tailwindcss is not typed
(nuxt.options.tailwindcss.cssPath as string).replace(/\\/g /* windows protocol */, '/'),
)

expect(spyStdout.mock.calls.some(c => (c[0] as string).includes('Using Tailwind CSS from ~/tailwind.css'))).toBeTruthy()
})

test('default js config is merged in', () => {
const vfsFile = getVfsFile('test-tailwind.config.mjs')
// set from default config tailwind.config.js
10 changes: 2 additions & 8 deletions test/configs.test.ts
Original file line number Diff line number Diff line change
@@ -54,14 +54,8 @@ describe('tailwindcss module configs', async () => {
},
})

test('throws error about malformed config', () => {
const output = spyStderr.mock.calls.map(m => m[0].toString().split('\n')[0].replace(/\(node:\d+\) /, ''))

// TODO: investigate warning on Node v22 (possibly generated by loading tailwind.config?)
// Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
// expect(output).toContain('Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.')

expect(output).toContain('[warn] [nuxt:tailwindcss] Failed to load config `./malformed-tailwind.config.js` due to the error below. Skipping..')
test('malformed config is not read', () => {
expect(getVfsFile('tailwind.config.cjs')).not.contains('malformed-tailwind.config')
})

test('ts config file is loaded and merged', () => {

0 comments on commit 98296a8

Please sign in to comment.