From 62e939507a8269d38a073996c61bac406d7b909c Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Sun, 27 Dec 2020 17:50:52 +0300 Subject: [PATCH] test(smoke): add tests for root --- src/tests/index.ts | 2 + src/tests/smoke/case-sensitive-match.smoke.ts | 5 +-- src/tests/smoke/regular.smoke.ts | 7 --- src/tests/smoke/root.smoke.ts | 45 +++++++++++++++++++ src/tests/utils/platform.ts | 25 +++++++++++ 5 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 src/tests/smoke/root.smoke.ts create mode 100644 src/tests/utils/platform.ts diff --git a/src/tests/index.ts b/src/tests/index.ts index cacc6366..b8f2dcbe 100644 --- a/src/tests/index.ts +++ b/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 }; diff --git a/src/tests/smoke/case-sensitive-match.smoke.ts b/src/tests/smoke/case-sensitive-match.smoke.ts index 60ca20db..8e418268 100644 --- a/src/tests/smoke/case-sensitive-match.smoke.ts +++ b/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', [ { @@ -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() } ]); diff --git a/src/tests/smoke/regular.smoke.ts b/src/tests/smoke/regular.smoke.ts index d6b3c228..1c4ba94a 100644 --- a/src/tests/smoke/regular.smoke.ts +++ b/src/tests/smoke/regular.smoke.ts @@ -1,5 +1,3 @@ -import * as os from 'os'; - import * as smoke from './smoke'; smoke.suite('Smoke → Regular', [ @@ -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' } -]); diff --git a/src/tests/smoke/root.smoke.ts b/src/tests/smoke/root.smoke.ts new file mode 100644 index 00000000..220783e4 --- /dev/null +++ b/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() + } +]); diff --git a/src/tests/utils/platform.ts b/src/tests/utils/platform.ts new file mode 100644 index 00000000..868753e6 --- /dev/null +++ b/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; +}