forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orphan-tests.js
29 lines (25 loc) · 874 Bytes
/
orphan-tests.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
const fs = require('fs').promises
const path = require('path')
const { filter: asyncFilter } = require('async')
describe('check for orphan tests', () => {
test('all tests are in sub-directories', async () => {
// A known list of exceptions that can live outside of directories
const EXCEPTIONS = ['README.md']
const pathToTests = path.join(process.cwd(), 'tests')
// Get a list of files/directories in `/tests`
const testDirectory = await fs.readdir(pathToTests)
let filteredList = testDirectory
// Filter out our exceptions
.filter(item => !EXCEPTIONS.includes(item))
// Don't include directories
filteredList = await asyncFilter(
filteredList,
async item => !(
await fs.stat(
path.join(pathToTests, item)
)
).isDirectory()
)
expect(filteredList).toHaveLength(0)
})
})