Skip to content

Commit 8132de6

Browse files
committed
refactor log.warn checks in tests
1 parent ab66c5a commit 8132de6

File tree

5 files changed

+18
-85
lines changed

5 files changed

+18
-85
lines changed

tests/blocklist.test.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
import log from '../src/util/log'
21
import { crosscheck, run, html, css } from './util/run'
32

43
crosscheck(({ stable, oxide }) => {
5-
let warn
6-
7-
beforeEach(() => {
8-
warn = jest.spyOn(log, 'warn')
9-
})
10-
11-
afterEach(() => warn.mockClear())
12-
134
it('can block classes matched literally', () => {
145
let config = {
156
content: [
@@ -102,8 +93,7 @@ crosscheck(({ stable, oxide }) => {
10293
}
10394
`)
10495

105-
expect(warn).toHaveBeenCalledTimes(1)
106-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['blocklist-invalid'])
96+
expect().toHaveBeenWarnedWith(['blocklist-invalid'])
10797
})
10898

10999
it('can block classes generated by the safelist', () => {

tests/evaluateTailwindFunctions.test.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'fs'
22
import path from 'path'
33
import postcss from 'postcss'
44
import plugin from '../src/lib/evaluateTailwindFunctions'
5-
import log from '../src/util/log'
65
import { crosscheck, run as runFull, html, css } from './util/run'
76

87
function run(input, opts = {}) {
@@ -1348,14 +1347,6 @@ crosscheck(({ stable, oxide }) => {
13481347
)
13491348
afterEach(() => fs.promises.unlink(configPath))
13501349

1351-
let warn
1352-
1353-
beforeEach(() => {
1354-
warn = jest.spyOn(log, 'warn')
1355-
})
1356-
1357-
afterEach(() => warn.mockClear())
1358-
13591350
oxide.test.todo('should not generate when theme fn doesnt resolve')
13601351
stable.test('should not generate when theme fn doesnt resolve', async () => {
13611352
await fs.promises.writeFile(
@@ -1378,11 +1369,7 @@ crosscheck(({ stable, oxide }) => {
13781369
`)
13791370

13801371
// 2. But we get a warning in the console
1381-
expect(warn).toHaveBeenCalledTimes(2)
1382-
expect(warn.mock.calls.map((x) => x[0])).toEqual([
1383-
'invalid-theme-key-in-class',
1384-
'invalid-theme-key-in-class',
1385-
])
1372+
expect().toHaveBeenWarnedWith(['invalid-theme-key-in-class'])
13861373

13871374
// 3. The second run should work fine because it's been removed from the class cache
13881375
result = await runFull('@tailwind utilities', configPath)
@@ -1394,11 +1381,7 @@ crosscheck(({ stable, oxide }) => {
13941381
`)
13951382

13961383
// 4. But we've not received any further logs about it
1397-
expect(warn).toHaveBeenCalledTimes(2)
1398-
expect(warn.mock.calls.map((x) => x[0])).toEqual([
1399-
'invalid-theme-key-in-class',
1400-
'invalid-theme-key-in-class',
1401-
])
1384+
expect().toHaveBeenWarnedWith(['invalid-theme-key-in-class'])
14021385
})
14031386
})
14041387
})

tests/min-max-screen-variants.test.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import log from '../src/util/log'
21
import { crosscheck, run, html, css } from './util/run'
32

43
crosscheck(() => {
5-
let warn
6-
7-
beforeEach(() => {
8-
warn = jest.spyOn(log, 'warn')
9-
})
10-
11-
afterEach(() => {
12-
warn.mockClear()
13-
})
14-
154
let defaultScreens = {
165
sm: '640px',
176
md: '768px',
@@ -119,7 +108,7 @@ crosscheck(() => {
119108
}
120109
`)
121110

122-
expect(warn).toHaveBeenCalledTimes(0)
111+
expect().not.toHaveBeenWarned()
123112
})
124113

125114
it('works when using max variants screens config is empty and variants all use the same unit', () => {
@@ -318,8 +307,7 @@ crosscheck(() => {
318307
}
319308
`)
320309

321-
expect(warn).toHaveBeenCalledTimes(1)
322-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['complex-screen-config'])
310+
expect().toHaveBeenWarnedWith(['complex-screen-config'])
323311
})
324312

325313
it('warns when using min variants with simple configs containing mixed units', async () => {
@@ -365,8 +353,7 @@ crosscheck(() => {
365353
}
366354
`)
367355

368-
expect(warn).toHaveBeenCalledTimes(1)
369-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['mixed-screen-units'])
356+
expect().toHaveBeenWarnedWith(['mixed-screen-units'])
370357
})
371358

372359
it('warns when using min variants with mixed units (with screens config)', async () => {
@@ -412,8 +399,7 @@ crosscheck(() => {
412399
}
413400
`)
414401

415-
expect(warn).toHaveBeenCalledTimes(1)
416-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
402+
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
417403
})
418404

419405
it('warns when using min variants with mixed units (with no screens config)', async () => {
@@ -450,8 +436,7 @@ crosscheck(() => {
450436
}
451437
`)
452438

453-
expect(warn).toHaveBeenCalledTimes(1)
454-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
439+
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
455440
})
456441

457442
it('warns when using max variants with complex screen configs', async () => {
@@ -500,8 +485,7 @@ crosscheck(() => {
500485
}
501486
`)
502487

503-
expect(warn).toHaveBeenCalledTimes(1)
504-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['complex-screen-config'])
488+
expect().toHaveBeenWarnedWith(['complex-screen-config'])
505489
})
506490

507491
it('warns when using max variants with simple configs containing mixed units', async () => {
@@ -547,8 +531,7 @@ crosscheck(() => {
547531
}
548532
`)
549533

550-
expect(warn).toHaveBeenCalledTimes(1)
551-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['mixed-screen-units'])
534+
expect().toHaveBeenWarnedWith(['mixed-screen-units'])
552535
})
553536

554537
it('warns when using max variants with mixed units (with screens config)', async () => {
@@ -594,8 +577,7 @@ crosscheck(() => {
594577
}
595578
`)
596579

597-
expect(warn).toHaveBeenCalledTimes(1)
598-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
580+
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
599581
})
600582

601583
it('warns when using max variants with mixed units (with no screens config)', async () => {
@@ -632,8 +614,7 @@ crosscheck(() => {
632614
}
633615
`)
634616

635-
expect(warn).toHaveBeenCalledTimes(1)
636-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
617+
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
637618
})
638619

639620
it('warns when using min and max variants with mixed units (with no screens config)', async () => {
@@ -670,7 +651,6 @@ crosscheck(() => {
670651
}
671652
`)
672653

673-
expect(warn).toHaveBeenCalledTimes(1)
674-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['minmax-have-mixed-units'])
654+
expect().toHaveBeenWarnedWith(['minmax-have-mixed-units'])
675655
})
676656
})

tests/normalize-config.test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { normalizeConfig } from '../src/util/normalizeConfig'
22
import resolveConfig from '../src/public/resolve-config'
3-
import log from '../src/util/log'
43
import { crosscheck, run, css } from './util/run'
54

65
crosscheck(({ stable, oxide }) => {
@@ -128,8 +127,6 @@ crosscheck(({ stable, oxide }) => {
128127
})
129128

130129
it('should warn when we detect invalid globs with incorrect brace expansion', () => {
131-
let spy = jest.spyOn(log, 'warn')
132-
133130
let config = {
134131
content: [
135132
'./{example-folder}/**/*.{html,js}',
@@ -162,9 +159,6 @@ crosscheck(({ stable, oxide }) => {
162159
transform: {},
163160
})
164161

165-
// But a warning should happen
166-
expect(spy).toHaveBeenCalledTimes(2)
167-
expect(spy.mock.calls.map((x) => x[0])).toEqual(['invalid-glob-braces', 'invalid-glob-braces'])
168-
spy.mockRestore()
162+
expect().toHaveBeenWarnedWith(['invalid-glob-braces'])
169163
})
170164
})

tests/warnings.test.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import log from '../src/util/log'
21
import { crosscheck, run, html, css } from './util/run'
32

43
crosscheck(() => {
5-
let warn
6-
7-
beforeEach(() => {
8-
warn = jest.spyOn(log, 'warn')
9-
})
10-
11-
afterEach(() => {
12-
warn.mockClear()
13-
})
14-
154
test('it warns when there is no content key', async () => {
165
let config = {
176
corePlugins: { preflight: false },
@@ -23,8 +12,7 @@ crosscheck(() => {
2312

2413
await run(input, config)
2514

26-
expect(warn).toHaveBeenCalledTimes(1)
27-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
15+
expect().toHaveBeenWarnedWith(['content-problems'])
2816
})
2917

3018
test('it warns when there is an empty content key', async () => {
@@ -39,8 +27,7 @@ crosscheck(() => {
3927

4028
await run(input, config)
4129

42-
expect(warn).toHaveBeenCalledTimes(1)
43-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
30+
expect().toHaveBeenWarnedWith(['content-problems'])
4431
})
4532

4633
test('it warns when there are no utilities generated', async () => {
@@ -55,8 +42,7 @@ crosscheck(() => {
5542

5643
await run(input, config)
5744

58-
expect(warn).toHaveBeenCalledTimes(1)
59-
expect(warn.mock.calls.map((x) => x[0])).toEqual(['content-problems'])
45+
expect().toHaveBeenWarnedWith(['content-problems'])
6046
})
6147

6248
it('warnings are not thrown when only variant utilities are generated', async () => {
@@ -71,6 +57,6 @@ crosscheck(() => {
7157

7258
await run(input, config)
7359

74-
expect(warn).toHaveBeenCalledTimes(0)
60+
expect().not.toHaveBeenWarned()
7561
})
7662
})

0 commit comments

Comments
 (0)