-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a spot check for directories that don't contain tests (#1791)
Closes #1433
- Loading branch information
Showing
5 changed files
with
44 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,4 +159,8 @@ export default abstract class SpecDirectory { | |
} | ||
} | ||
} | ||
|
||
toString(): string { | ||
return this.path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as p from 'path'; | ||
import * as specDirectory from '../lib-js/spec-directory'; | ||
|
||
// Spot checks for common spec errors. | ||
|
||
it('every directory contains or is contained by a test', async () => { | ||
// Verifies that `dir` either is a test, or that all its children are tests. | ||
async function verifyDirectory( | ||
dir: specDirectory.SpecDirectory | ||
): Promise<void> { | ||
if (dir.isTestDir()) return; | ||
|
||
const subdirs = await dir.subdirs(); | ||
if (subdirs.length === 0) { | ||
// Empty directories aren't recorded by Git, so we allow them. | ||
if ((await dir.listFiles()).length === 0) return; | ||
|
||
const path = p.relative(process.cwd(), dir.path); | ||
throw new Error( | ||
`Directory ${path} is neither a test, the child of a test, nor the ` + | ||
'parent of a test.' | ||
); | ||
} else { | ||
await Promise.all(subdirs.map(verifyDirectory)); | ||
} | ||
} | ||
|
||
await verifyDirectory(await specDirectory.fromPath('spec')); | ||
}); |