Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 7ff6acd

Browse files
committed
Reorganize tests
1 parent 77cf600 commit 7ff6acd

File tree

6 files changed

+64
-62
lines changed

6 files changed

+64
-62
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"postcss-cli": "^8.3.1",
3333
"prettier": "^2.2.1"
3434
},
35+
"jest": {
36+
"setupFilesAfterEnv": [
37+
"<rootDir>/tests/customMatchers.js"
38+
]
39+
},
3540
"browserslist": [
3641
"> 1%",
3742
"not edge <= 18",

src/index.test.adding-a-custom-variant.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/index.test.css renamed to tests/01-sanity.test.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ div {
284284
--tw-ring-inset: var(--tw-empty, /*!*/ /*!*/);
285285
--tw-ring-offset-width: 0px;
286286
--tw-ring-offset-color: #fff;
287-
--tw-ring-color: rgba(147, 197, 253, 0.5);
287+
--tw-ring-color: rgba(59, 130, 246, 0.5);
288288
--tw-ring-offset-shadow: 0 0 #0000;
289289
--tw-ring-shadow: 0 0 #0000;
290290
}
File renamed without changes.

src/index.test.js renamed to tests/01-sanity.test.js

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const prettier = require('prettier')
2-
const diff = require('jest-diff').default
31
const postcss = require('postcss')
4-
const tailwind = require('./index.js')
2+
const tailwind = require('../src/index.js')
53
const fs = require('fs')
64
const path = require('path')
75

@@ -12,7 +10,7 @@ function run(input, config = {}) {
1210
test('it works', () => {
1311
let config = {
1412
darkMode: 'class',
15-
purge: [path.resolve(__dirname, './index.test.html')],
13+
purge: [path.resolve(__dirname, './01-sanity.test.html')],
1614
corePlugins: { preflight: false },
1715
theme: {
1816
extend: {
@@ -151,62 +149,9 @@ test('it works', () => {
151149
`
152150

153151
return run(css, config).then((result) => {
154-
let expectedPath = path.resolve(__dirname, './index.test.css')
152+
let expectedPath = path.resolve(__dirname, './01-sanity.test.css')
155153
let expected = fs.readFileSync(expectedPath, 'utf8')
156154

157155
expect(result.css).toMatchCss(expected)
158156
})
159157
})
160-
161-
function format(input) {
162-
return prettier.format(input, {
163-
parser: 'css',
164-
printWidth: 100,
165-
})
166-
}
167-
168-
expect.extend({
169-
// Compare two CSS strings with all whitespace removed
170-
// This is probably naive but it's fast and works well enough.
171-
toMatchCss(received, argument) {
172-
const options = {
173-
comment: 'stripped(received) === stripped(argument)',
174-
isNot: this.isNot,
175-
promise: this.promise,
176-
}
177-
178-
let formattedReceived = format(received)
179-
let formattedArgument = format(argument)
180-
181-
const pass = formattedReceived === formattedArgument
182-
183-
const message = pass
184-
? () => {
185-
return (
186-
this.utils.matcherHint('toMatchCss', undefined, undefined, options) +
187-
'\n\n' +
188-
`Expected: not ${this.utils.printExpected(formattedReceived)}\n` +
189-
`Received: ${this.utils.printReceived(formattedArgument)}`
190-
)
191-
}
192-
: () => {
193-
const actual = formattedReceived
194-
const expected = formattedArgument
195-
196-
const diffString = diff(expected, actual, {
197-
expand: this.expand,
198-
})
199-
200-
return (
201-
this.utils.matcherHint('toMatchCss', undefined, undefined, options) +
202-
'\n\n' +
203-
(diffString && diffString.includes('- Expect')
204-
? `Difference:\n\n${diffString}`
205-
: `Expected: ${this.utils.printExpected(expected)}\n` +
206-
`Received: ${this.utils.printReceived(actual)}`)
207-
)
208-
}
209-
210-
return { actual: received, message, pass }
211-
},
212-
})

tests/customMatchers.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const prettier = require('prettier')
2+
const diff = require('jest-diff').default
3+
4+
function format(input) {
5+
return prettier.format(input, {
6+
parser: 'css',
7+
printWidth: 100,
8+
})
9+
}
10+
11+
expect.extend({
12+
// Compare two CSS strings with all whitespace removed
13+
// This is probably naive but it's fast and works well enough.
14+
toMatchCss(received, argument) {
15+
const options = {
16+
comment: 'stripped(received) === stripped(argument)',
17+
isNot: this.isNot,
18+
promise: this.promise,
19+
}
20+
21+
let formattedReceived = format(received)
22+
let formattedArgument = format(argument)
23+
24+
const pass = formattedReceived === formattedArgument
25+
26+
const message = pass
27+
? () => {
28+
return (
29+
this.utils.matcherHint('toMatchCss', undefined, undefined, options) +
30+
'\n\n' +
31+
`Expected: not ${this.utils.printExpected(formattedReceived)}\n` +
32+
`Received: ${this.utils.printReceived(formattedArgument)}`
33+
)
34+
}
35+
: () => {
36+
const actual = formattedReceived
37+
const expected = formattedArgument
38+
39+
const diffString = diff(expected, actual, {
40+
expand: this.expand,
41+
})
42+
43+
return (
44+
this.utils.matcherHint('toMatchCss', undefined, undefined, options) +
45+
'\n\n' +
46+
(diffString && diffString.includes('- Expect')
47+
? `Difference:\n\n${diffString}`
48+
: `Expected: ${this.utils.printExpected(expected)}\n` +
49+
`Received: ${this.utils.printReceived(actual)}`)
50+
)
51+
}
52+
53+
return { actual: received, message, pass }
54+
},
55+
})

0 commit comments

Comments
 (0)