forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
34 lines (30 loc) · 1.38 KB
/
index.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
import fs from 'fs'
import path from 'path'
import { corePlugins } from '../../src/corePlugins'
test('all core plugins have a dedicated test file', async () => {
let currentFile = path.basename(__filename)
let corePluginList = Object.keys(corePlugins).sort((a, z) => a.localeCompare(z))
let testedPluginList = (
await fs.promises.readdir(path.resolve(__dirname, './'), {
withFileTypes: true,
})
)
.filter(
(dirent) => dirent.isFile() && dirent.name.endsWith('.test.js') && dirent.name !== currentFile
)
.map((dirent) => dirent.name.slice(0, dirent.name.indexOf('.')))
.sort((a, z) => a.localeCompare(z))
let missingTests = corePluginList.filter((plugin) => !testedPluginList.includes(plugin))
let additionalTests = testedPluginList.filter((plugin) => !corePluginList.includes(plugin))
if (missingTests.length > 0 || additionalTests.length > 0) {
throw new Error(
`The following \`corePlugins\` are not covered by tests in the \`./tests/plugins/\` folder:\n${
missingTests.map((x) => `\t- ${x}`).join('\n') || '\t- None'
}\n\nAdditional tests found that don't correspond to any of the \`corePlugins\`:\n${
additionalTests.map((x) => `\t- ${x}`).join('\n') || '\t- None'
}\n\nCovered: ${testedPluginList.length - additionalTests.length}/${
corePluginList.length
}, missing: ${missingTests.length}`
)
}
})