Skip to content

Commit

Permalink
Merge pull request #301 from mrmlnc/FG-277_smoke_tests_for_root_case
Browse files Browse the repository at this point in the history
ISSUE-277: smoke tests for patterns that starts with the leading slash
  • Loading branch information
mrmlnc committed Dec 28, 2020
2 parents 9fb903d + 62e9395 commit 19cdcb7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/tests/index.ts
@@ -1,11 +1,13 @@
import * as entry from './utils/entry';
import * as errno from './utils/errno';
import * as pattern from './utils/pattern';
import * as platform from './utils/platform';
import * as task from './utils/task';

export {
entry,
errno,
pattern,
platform,
task
};
5 changes: 2 additions & 3 deletions src/tests/smoke/case-sensitive-match.smoke.ts
@@ -1,6 +1,5 @@
import * as os from 'os';

import * as smoke from './smoke';
import * as utils from '..';

smoke.suite('Smoke → CaseSensitiveMatch', [
{
Expand All @@ -17,6 +16,6 @@ smoke.suite('Smoke → CaseSensitiveMatch', [
pattern: '/tmp/*',
globOptions: { nocase: true, nodir: false },
fgOptions: { caseSensitiveMatch: false, onlyFiles: false },
condition: () => os.platform() !== 'win32'
condition: () => !utils.platform.isWindows()
}
]);
7 changes: 0 additions & 7 deletions src/tests/smoke/regular.smoke.ts
@@ -1,5 +1,3 @@
import * as os from 'os';

import * as smoke from './smoke';

smoke.suite('Smoke → Regular', [
Expand Down Expand Up @@ -485,8 +483,3 @@ smoke.suite('Smoke → Regular (relative)', [
{ pattern: '../{first,second}', cwd: 'fixtures/first' },
{ pattern: './../*', cwd: 'fixtures/first' }
]);

smoke.suite('Smoke → Regular (root)', [
// ISSUE-266
{ pattern: '/tmp/*', condition: () => os.platform() !== 'win32' }
]);
45 changes: 45 additions & 0 deletions src/tests/smoke/root.smoke.ts
@@ -0,0 +1,45 @@
import * as path from 'path';

import * as smoke from './smoke';
import * as utils from '..';

const CWD = process.cwd().replace(/\\/g, '/');
const ROOT = path.parse(CWD).root;

smoke.suite('Smoke → Root', [
{
pattern: '/*',
condition: () => !utils.platform.isWindows()
},
{
pattern: '/tmp/*',
condition: () => !utils.platform.isWindows()
},
{
pattern: '/*',
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows(),
correct: true,
reason: 'The `node-glob` packages returns items with resolve path for the current disk letter'
},
// UNC pattern without dynamic sections in the base section
{
pattern: `//?/${ROOT}*`,
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows(),
correct: true,
reason: 'The `node-glob` package does not allow to use UNC in patterns'
}
]);

smoke.suite('Smoke → Root (cwd)', [
{
pattern: '*',
cwd: ROOT,
condition: () => !utils.platform.isWindows() || utils.platform.isSupportReaddirWithFileTypes()
},
// UNC on Windows
{
pattern: '*',
cwd: `//?/${ROOT}`,
condition: () => utils.platform.isSupportReaddirWithFileTypes() && utils.platform.isWindows()
}
]);
25 changes: 25 additions & 0 deletions src/tests/utils/platform.ts
@@ -0,0 +1,25 @@
import * as os from 'os';

const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');

const MAJOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
const MINOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);

const SUPPORTED_MAJOR_VERSION = 10;
const SUPPORTED_MINOR_VERSION = 10;

const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;

/**
* IS `true` for Node.js 10.10 and greater.
*/
export const IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;

export function isWindows(): boolean {
return os.platform() === 'win32';
}

export function isSupportReaddirWithFileTypes(): boolean {
return IS_SUPPORT_READDIR_WITH_FILE_TYPES;
}

0 comments on commit 19cdcb7

Please sign in to comment.