Skip to content

Commit 19cdcb7

Browse files
authored
Merge pull request #301 from mrmlnc/FG-277_smoke_tests_for_root_case
ISSUE-277: smoke tests for patterns that starts with the leading slash
2 parents 9fb903d + 62e9395 commit 19cdcb7

5 files changed

Lines changed: 74 additions & 10 deletions

File tree

src/tests/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as entry from './utils/entry';
22
import * as errno from './utils/errno';
33
import * as pattern from './utils/pattern';
4+
import * as platform from './utils/platform';
45
import * as task from './utils/task';
56

67
export {
78
entry,
89
errno,
910
pattern,
11+
platform,
1012
task
1113
};

src/tests/smoke/case-sensitive-match.smoke.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as os from 'os';
2-
31
import * as smoke from './smoke';
2+
import * as utils from '..';
43

54
smoke.suite('Smoke → CaseSensitiveMatch', [
65
{
@@ -17,6 +16,6 @@ smoke.suite('Smoke → CaseSensitiveMatch', [
1716
pattern: '/tmp/*',
1817
globOptions: { nocase: true, nodir: false },
1918
fgOptions: { caseSensitiveMatch: false, onlyFiles: false },
20-
condition: () => os.platform() !== 'win32'
19+
condition: () => !utils.platform.isWindows()
2120
}
2221
]);

src/tests/smoke/regular.smoke.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as os from 'os';
2-
31
import * as smoke from './smoke';
42

53
smoke.suite('Smoke → Regular', [
@@ -485,8 +483,3 @@ smoke.suite('Smoke → Regular (relative)', [
485483
{ pattern: '../{first,second}', cwd: 'fixtures/first' },
486484
{ pattern: './../*', cwd: 'fixtures/first' }
487485
]);
488-
489-
smoke.suite('Smoke → Regular (root)', [
490-
// ISSUE-266
491-
{ pattern: '/tmp/*', condition: () => os.platform() !== 'win32' }
492-
]);

src/tests/smoke/root.smoke.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as path from 'path';
2+
3+
import * as smoke from './smoke';
4+
import * as utils from '..';
5+
6+
const CWD = process.cwd().replace(/\\/g, '/');
7+
const ROOT = path.parse(CWD).root;
8+
9+
smoke.suite('Smoke → Root', [
10+
{
11+
pattern: '/*',
12+
condition: () => !utils.platform.isWindows()
13+
},
14+
{
15+
pattern: '/tmp/*',
16+
condition: () => !utils.platform.isWindows()
17+
},
18+
{
19+
pattern: '/*',
20+
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows(),
21+
correct: true,
22+
reason: 'The `node-glob` packages returns items with resolve path for the current disk letter'
23+
},
24+
// UNC pattern without dynamic sections in the base section
25+
{
26+
pattern: `//?/${ROOT}*`,
27+
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows(),
28+
correct: true,
29+
reason: 'The `node-glob` package does not allow to use UNC in patterns'
30+
}
31+
]);
32+
33+
smoke.suite('Smoke → Root (cwd)', [
34+
{
35+
pattern: '*',
36+
cwd: ROOT,
37+
condition: () => !utils.platform.isWindows() || utils.platform.isSupportReaddirWithFileTypes()
38+
},
39+
// UNC on Windows
40+
{
41+
pattern: '*',
42+
cwd: `//?/${ROOT}`,
43+
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows()
44+
}
45+
]);

src/tests/utils/platform.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as os from 'os';
2+
3+
const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
4+
5+
const MAJOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
6+
const MINOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
7+
8+
const SUPPORTED_MAJOR_VERSION = 10;
9+
const SUPPORTED_MINOR_VERSION = 10;
10+
11+
const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
12+
const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
13+
14+
/**
15+
* IS `true` for Node.js 10.10 and greater.
16+
*/
17+
export const IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
18+
19+
export function isWindows(): boolean {
20+
return os.platform() === 'win32';
21+
}
22+
23+
export function isSupportReaddirWithFileTypes(): boolean {
24+
return IS_SUPPORT_READDIR_WITH_FILE_TYPES;
25+
}

0 commit comments

Comments
 (0)