refactor log.warn checks in tests

This commit is contained in:
Robin Malfait 2023-03-17 14:48:21 +01:00
parent ab66c5afe3
commit 8132de6660
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE
5 changed files with 18 additions and 85 deletions

View file

@ -1,15 +1,6 @@
import log from '../src/util/log'
import { crosscheck, run, html, css } from './util/run'
crosscheck(({ stable, oxide }) => {
let warn
beforeEach(() => {
warn = jest.spyOn(log, 'warn')
})
afterEach(() => warn.mockClear())
it('can block classes matched literally', () => {
let config = {
content: [
@ -102,8 +93,7 @@ crosscheck(({ stable, oxide }) => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['blocklist-invalid'])
expect().toHaveBeenWarnedWith(['blocklist-invalid'])
})
it('can block classes generated by the safelist', () => {

View file

@ -2,7 +2,6 @@ import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import plugin from '../src/lib/evaluateTailwindFunctions'
import log from '../src/util/log'
import { crosscheck, run as runFull, html, css } from './util/run'
function run(input, opts = {}) {
@ -1348,14 +1347,6 @@ crosscheck(({ stable, oxide }) => {
)
afterEach(() => fs.promises.unlink(configPath))
let warn
beforeEach(() => {
warn = jest.spyOn(log, 'warn')
})
afterEach(() => warn.mockClear())
oxide.test.todo('should not generate when theme fn doesnt resolve')
stable.test('should not generate when theme fn doesnt resolve', async () => {
await fs.promises.writeFile(
@ -1378,11 +1369,7 @@ crosscheck(({ stable, oxide }) => {
`)
// 2. But we get a warning in the console
expect(warn).toHaveBeenCalledTimes(2)
expect(warn.mock.calls.map((x) => x[0])).toEqual([
'invalid-theme-key-in-class',
'invalid-theme-key-in-class',
])
expect().toHaveBeenWarnedWith(['invalid-theme-key-in-class'])
// 3. The second run should work fine because it's been removed from the class cache
result = await runFull('@tailwind utilities', configPath)
@ -1394,11 +1381,7 @@ crosscheck(({ stable, oxide }) => {
`)
// 4. But we've not received any further logs about it
expect(warn).toHaveBeenCalledTimes(2)
expect(warn.mock.calls.map((x) => x[0])).toEqual([
'invalid-theme-key-in-class',
'invalid-theme-key-in-class',
])
expect().toHaveBeenWarnedWith(['invalid-theme-key-in-class'])
})
})
})

View file

@ -1,17 +1,6 @@
import log from '../src/util/log'
import { crosscheck, run, html, css } from './util/run'
crosscheck(() => {
let warn
beforeEach(() => {
warn = jest.spyOn(log, 'warn')
})
afterEach(() => {
warn.mockClear()
})
let defaultScreens = {
sm: '640px',
md: '768px',
@ -119,7 +108,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(0)
expect().not.toHaveBeenWarned()
})
it('works when using max variants screens config is empty and variants all use the same unit', () => {
@ -318,8 +307,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['complex-screen-config'])
expect().toHaveBeenWarnedWith(['complex-screen-config'])
})
it('warns when using min variants with simple configs containing mixed units', async () => {
@ -365,8 +353,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['mixed-screen-units'])
expect().toHaveBeenWarnedWith(['mixed-screen-units'])
})
it('warns when using min variants with mixed units (with screens config)', async () => {
@ -412,8 +399,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
})
it('warns when using min variants with mixed units (with no screens config)', async () => {
@ -450,8 +436,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
})
it('warns when using max variants with complex screen configs', async () => {
@ -500,8 +485,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['complex-screen-config'])
expect().toHaveBeenWarnedWith(['complex-screen-config'])
})
it('warns when using max variants with simple configs containing mixed units', async () => {
@ -547,8 +531,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['mixed-screen-units'])
expect().toHaveBeenWarnedWith(['mixed-screen-units'])
})
it('warns when using max variants with mixed units (with screens config)', async () => {
@ -594,8 +577,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
})
it('warns when using max variants with mixed units (with no screens config)', async () => {
@ -632,8 +614,7 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
})
it('warns when using min and max variants with mixed units (with no screens config)', async () => {
@ -670,7 +651,6 @@ crosscheck(() => {
}
`)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
})
})

View file

@ -1,6 +1,5 @@
import { normalizeConfig } from '../src/util/normalizeConfig'
import resolveConfig from '../src/public/resolve-config'
import log from '../src/util/log'
import { crosscheck, run, css } from './util/run'
crosscheck(({ stable, oxide }) => {
@ -128,8 +127,6 @@ crosscheck(({ stable, oxide }) => {
})
it('should warn when we detect invalid globs with incorrect brace expansion', () => {
let spy = jest.spyOn(log, 'warn')
let config = {
content: [
'./{example-folder}/**/*.{html,js}',
@ -162,9 +159,6 @@ crosscheck(({ stable, oxide }) => {
transform: {},
})
// But a warning should happen
expect(spy).toHaveBeenCalledTimes(2)
expect(spy.mock.calls.map((x) => x[0])).toEqual(['invalid-glob-braces', 'invalid-glob-braces'])
spy.mockRestore()
expect().toHaveBeenWarnedWith(['invalid-glob-braces'])
})
})

View file

@ -1,17 +1,6 @@
import log from '../src/util/log'
import { crosscheck, run, html, css } from './util/run'
crosscheck(() => {
let warn
beforeEach(() => {
warn = jest.spyOn(log, 'warn')
})
afterEach(() => {
warn.mockClear()
})
test('it warns when there is no content key', async () => {
let config = {
corePlugins: { preflight: false },
@ -23,8 +12,7 @@ crosscheck(() => {
await run(input, config)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
expect().toHaveBeenWarnedWith(['content-problems'])
})
test('it warns when there is an empty content key', async () => {
@ -39,8 +27,7 @@ crosscheck(() => {
await run(input, config)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
expect().toHaveBeenWarnedWith(['content-problems'])
})
test('it warns when there are no utilities generated', async () => {
@ -55,8 +42,7 @@ crosscheck(() => {
await run(input, config)
expect(warn).toHaveBeenCalledTimes(1)
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
expect().toHaveBeenWarnedWith(['content-problems'])
})
it('warnings are not thrown when only variant utilities are generated', async () => {
@ -71,6 +57,6 @@ crosscheck(() => {
await run(input, config)
expect(warn).toHaveBeenCalledTimes(0)
expect().not.toHaveBeenWarned()
})
})