* Checks that a provided sentinel is/is not contained in a file. * @param {string} filePath JS binary to check * @param {Record } sentinels map from sentinels to whether or not * they should be present * @return {Promise } * @throws if a sentin
(filePath, sentinels)
| 18 | * @throws if a sentinel isn't/is present when it should/shouldn't be |
| 19 | */ |
| 20 | async function checkSentinels(filePath, sentinels) { |
| 21 | const fileContents = await fs.readFile(filePath, 'utf8'); |
| 22 | |
| 23 | for (const [sentinel, shouldBePresent] of Object.entries(sentinels)) { |
| 24 | const isPresent = fileContents.includes(sentinel); |
| 25 | |
| 26 | if (isPresent != shouldBePresent) { |
| 27 | log( |
| 28 | red('ERROR:'), |
| 29 | cyan(filePath), |
| 30 | shouldBePresent ? 'does not contain' : 'contains', |
| 31 | `${cyan(sentinel)}.`, |
| 32 | 'Something may be wrong with assertions or compilation.' |
| 33 | ); |
| 34 | throw new Error('Assertion sentinel check failed'); |
| 35 | } |
| 36 | |
| 37 | log( |
| 38 | green('SUCCESS:'), |
| 39 | cyan(sentinel), |
| 40 | shouldBePresent ? 'found in' : 'not found in', |
| 41 | cyan(filePath) |
| 42 | ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Checks that the file at the provided path does not include devAssert. |