-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from botandrose/fail-only
Add `--fail-only` option to fail the test suite in CI when an `it.only` is left in
- Loading branch information
Showing
5 changed files
with
29 additions
and
3 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
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
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,24 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
||
export default { | ||
name: 'fail-only', | ||
async transform(context) { | ||
const filePath = context.path; | ||
const failOnlyEnabled = process.argv.includes('--fail-only'); | ||
if (failOnlyEnabled && filePath.match(/^\/test\/[^/]+\.js$/)) { | ||
const fileContent = await fs.readFile(`.${filePath}`, 'utf-8'); | ||
if (/\bit\.only\b/.test(fileContent)) { | ||
abort(`--fail-only:\nFound 'it.only' in ${filePath}. Remove it to proceed.`); | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
function abort(message) { | ||
const RED = '\x1b[31m'; // Red color code | ||
const RESET = '\x1b[0m'; // Reset color code | ||
process.stderr.write(`${RED}${message}\n${RESET}`, () => { | ||
process.exit(1); | ||
}); | ||
} |
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