-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathdetect-dot-only-hook.js
41 lines (37 loc) · 1.47 KB
/
detect-dot-only-hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/
const es = require('event-stream');
const child_process = require('child_process');
const detectDotOnlyHook = (reporter) => {
// If SKIP_DOT_ONLY_CHECK is set, skip the check
if (process.env.SKIP_DOT_ONLY_CHECK) {
reporter('Skipping .only check for staged test files because SKIP_DOT_ONLY_CHECK is set\n', false);
return es.through(function () {
/* noop, important for the stream to end */
});
}
try {
const result = child_process.execSync('node build/detect-dot-only.js', { encoding: 'utf8' });
} catch (error) {
let message = '';
// See ExitCodes in build/detect-dot-only.js
switch (error.status) {
case 1:
message = 'If you want to skip the .only check, set SKIP_DOT_ONLY_CHECK in your environment.\n\te.g., `SKIP_DOT_ONLY_CHECK=1 git commit`';
break;
case 2:
message = 'detect-dot-only.js encountered an error...';
break;
default:
message = 'Encountered an error while running the hook to detect .only in staged test files.';
break;
}
reporter(message + '\n', true);
}
return es.through(function () {
/* noop, important for the stream to end */
});
};
module.exports = detectDotOnlyHook;