Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-277: smoke tests for patterns that starts with the leading slash #301

Merged
merged 1 commit into from Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}