forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorphan-tests.js
More file actions
26 lines (21 loc) · 853 Bytes
/
Copy pathorphan-tests.js
File metadata and controls
26 lines (21 loc) · 853 Bytes
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
import xFs from 'fs'
import path from 'path'
import { filter as asyncFilter } from 'async'
const fs = xFs.promises
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', 'package.json']
const pathToTests = path.join(process.cwd(), 'tests')
// Get a list of files/directories in `/tests`
const testDirectory = await fs.readdir(pathToTests)
// Filter out our exceptions
let filteredList = testDirectory.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)
})
})