Skip to content

Commit 62eaac4

Browse files
RobinMalfaitadamwathan
authored andcommitted
suppress console.warn logs in tests
This makes the test output a bit nicer to look at
1 parent ad7fec4 commit 62eaac4

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

__tests__/purgeUnusedStyles.test.js

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import postcss from 'postcss'
44
import tailwind from '../src/index'
55
import defaultConfig from '../stubs/defaultConfig.stub.js'
66

7+
function suppressConsoleLogs(cb, type = 'warn') {
8+
return () => {
9+
const spy = jest.spyOn(global.console, type).mockImplementation(jest.fn())
10+
11+
return new Promise((resolve, reject) => {
12+
Promise.resolve(cb()).then(resolve, reject)
13+
}).finally(() => spy.mockRestore())
14+
}
15+
}
16+
717
const config = {
818
...defaultConfig,
919
theme: {
@@ -146,29 +156,32 @@ test('does not purge except in production', () => {
146156
})
147157
})
148158

149-
test('does not purge if the array is empty', () => {
150-
const OLD_NODE_ENV = process.env.NODE_ENV
151-
process.env.NODE_ENV = 'production'
152-
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
153-
const input = fs.readFileSync(inputPath, 'utf8')
154-
155-
return postcss([
156-
tailwind({
157-
...defaultConfig,
158-
purge: [],
159-
}),
160-
])
161-
.process(input, { from: inputPath })
162-
.then(result => {
163-
process.env.NODE_ENV = OLD_NODE_ENV
164-
const expected = fs.readFileSync(
165-
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
166-
'utf8'
167-
)
168-
169-
expect(result.css).toBe(expected)
170-
})
171-
})
159+
test(
160+
'does not purge if the array is empty',
161+
suppressConsoleLogs(() => {
162+
const OLD_NODE_ENV = process.env.NODE_ENV
163+
process.env.NODE_ENV = 'production'
164+
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
165+
const input = fs.readFileSync(inputPath, 'utf8')
166+
167+
return postcss([
168+
tailwind({
169+
...defaultConfig,
170+
purge: [],
171+
}),
172+
])
173+
.process(input, { from: inputPath })
174+
.then(result => {
175+
process.env.NODE_ENV = OLD_NODE_ENV
176+
const expected = fs.readFileSync(
177+
path.resolve(`${__dirname}/fixtures/tailwind-output.css`),
178+
'utf8'
179+
)
180+
181+
expect(result.css).toBe(expected)
182+
})
183+
})
184+
)
172185

173186
test('does not purge if explicitly disabled', () => {
174187
const OLD_NODE_ENV = process.env.NODE_ENV

0 commit comments

Comments
 (0)