MCPcopy Index your code
hub / github.com/ampproject/amphtml / checkSentinels

Function checkSentinels

build-system/tasks/check-asserts.js:20–44  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

18 * @throws if a sentinel isn't/is present when it should/shouldn't be
19 */
20async 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.

Callers 1

checkAssertsFunction · 0.85

Calls 5

redFunction · 0.85
cyanFunction · 0.85
greenFunction · 0.85
logFunction · 0.50
entriesMethod · 0.45

Tested by

no test coverage detected