Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/ps.test.ts
4778 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { deepStrictEqual } from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
8
import { JS_FILENAME_PATTERN } from '../../node/ps.js';
9
10
suite('Process Utils', () => {
11
12
ensureNoDisposablesAreLeakedInTestSuite();
13
14
suite('JS file regex', () => {
15
16
function findJsFiles(cmd: string): string[] {
17
const matches: string[] = [];
18
let match;
19
while ((match = JS_FILENAME_PATTERN.exec(cmd)) !== null) {
20
matches.push(match[0]);
21
}
22
return matches;
23
}
24
25
test('should match simple .js files', () => {
26
deepStrictEqual(findJsFiles('node bootstrap.js'), ['bootstrap.js']);
27
});
28
29
test('should match multiple .js files', () => {
30
deepStrictEqual(findJsFiles('node server.js --require helper.js'), ['server.js', 'helper.js']);
31
});
32
33
test('should match .js files with hyphens', () => {
34
deepStrictEqual(findJsFiles('node my-script.js'), ['my-script.js']);
35
});
36
37
test('should not match .json files', () => {
38
deepStrictEqual(findJsFiles('cat package.json'), []);
39
});
40
41
test('should not match .js prefix in .json extension (regression test for \\b fix)', () => {
42
// Without the \b word boundary, the regex would incorrectly match "package.js" from "package.json"
43
deepStrictEqual(findJsFiles('node --config tsconfig.json'), []);
44
deepStrictEqual(findJsFiles('eslint.json'), []);
45
});
46
47
test('should not match .jsx files', () => {
48
deepStrictEqual(findJsFiles('node component.jsx'), []);
49
});
50
51
test('should match .js but not .json in same command', () => {
52
deepStrictEqual(findJsFiles('node app.js --config settings.json'), ['app.js']);
53
});
54
55
test('should not match partial matches inside other extensions', () => {
56
deepStrictEqual(findJsFiles('file.jsmith'), []);
57
});
58
59
test('should match .js at end of command', () => {
60
deepStrictEqual(findJsFiles('/path/to/script.js'), ['script.js']);
61
});
62
});
63
});
64
65
66