-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathtest.js
84 lines (69 loc) · 2.36 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { execSync } = require('child_process')
const os = require('os')
const fs = require('fs-extra')
const platformMap = {
darwin: 'macos',
win32: 'windows',
linux: 'linux',
}
function exec(args) {
return execSync(
`./dist/tailwindcss-${platformMap[process.platform]}-${process.arch} ${args}`
).toString()
}
it('works', () => {
let result = exec('--content tests/fixtures/basic.html')
expect(result).toContain('.uppercase')
expect(result).toContain('.\\[will-change\\:opacity\\]')
expect(result).toContain('will-change: opacity')
// Verify that no plugins are installed that modify the `[will-change:opacity]` class
expect(result).not.toContain('backface-visibility: hidden')
})
it('supports first-party plugins', () => {
let result = exec('--content tests/fixtures/plugins.html --config tests/fixtures/test.config.js')
expect(result).toContain('.aspect-w-1')
expect(result).toContain('.form-input')
expect(result).toContain('.line-clamp-2')
expect(result).toContain('.prose')
})
it('supports postcss config files', async () => {
// We have to run this test outside of any place with node_modules for it to properly test this situation
let result = await inIsolatedContext(() => {
// Emulate the user adding their own postcss plugins
execSync(`npm install postcss-will-change`)
return exec('--content tests/fixtures/basic.html --postcss tests/fixtures/postcss.config.js')
})
expect(result).toContain('.uppercase')
// Ensure the custom added postcss plugin is working
expect(result).toContain('will-change: opacity')
expect(result).toContain('backface-visibility: hidden')
})
/**
* @template T
* @param {() => T} fn
* @returns {Promise<T>}
*/
async function inIsolatedContext(fn) {
// Create a new directory entirely outside of the package for the test
let dest = `${os.tmpdir()}/tailwindcss-cli`
// Recursively copy the dist and tests folders
let dirs = ['dist', 'tests']
await Promise.all(
dirs.map((dir) =>
fs.copy(`${__dirname}/../${dir}`, `${dest}/${dir}`, {
overwrite: true,
recursive: true,
})
)
)
// Change the working directory to the new directory
process.chdir(dest)
try {
return await fn()
} finally {
// Change back to the original working directory
process.chdir(__dirname)
// Delete the new directory
await fs.rm(dest, { recursive: true })
}
}