* Update tests to use fs.promises when not top-level * Move two to asyncFilter * Update site-data-references.js * Update site-data-references.js * Clear out await fs.exists * Lint * A few more fixes * Can't use async when defining tests
30 lines
874 B
JavaScript
30 lines
874 B
JavaScript
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)
|
|
})
|
|
})
|