From 04bc56c6880651551524f048024f2ef866e79670 Mon Sep 17 00:00:00 2001 From: zkochan Date: Mon, 6 Feb 2017 02:11:22 +0200 Subject: [PATCH] refactor(tests): move supporting functions to utils folder --- test/breakingChanges.ts | 3 +-- test/cache.ts | 4 +--- test/cli.ts | 9 ++++++--- test/install.ts | 15 +++++++++------ test/link.ts | 10 ++++++---- test/prune.ts | 3 +-- test/uninstall.ts | 3 +-- test/{support => utils}/distTags.ts | 0 test/{support => utils}/execPnpm.ts | 0 test/utils/index.ts | 16 ++++++++++++++++ test/{support => utils}/isExecutable.ts | 0 test/{support => utils}/localPkg.ts | 0 test/{support => utils}/prepare.ts | 0 test/{support => utils}/simple-package.json | 0 test/{support => utils}/testDefaults.ts | 0 test/verify.ts | 4 +--- 16 files changed, 42 insertions(+), 25 deletions(-) rename test/{support => utils}/distTags.ts (100%) rename test/{support => utils}/execPnpm.ts (100%) create mode 100644 test/utils/index.ts rename test/{support => utils}/isExecutable.ts (100%) rename test/{support => utils}/localPkg.ts (100%) rename test/{support => utils}/prepare.ts (100%) rename test/{support => utils}/simple-package.json (100%) rename test/{support => utils}/testDefaults.ts (100%) diff --git a/test/breakingChanges.ts b/test/breakingChanges.ts index c77f626469..857d41aea0 100644 --- a/test/breakingChanges.ts +++ b/test/breakingChanges.ts @@ -3,8 +3,7 @@ import promisifyTape from 'tape-promise' import fs = require('mz/fs') import mkdirp = require('mkdirp') import path = require('path') -import prepare from './support/prepare' -import testDefaults from './support/testDefaults' +import {prepare, testDefaults} from './utils' import {installPkgs} from '../src' const test = promisifyTape(tape) diff --git a/test/cache.ts b/test/cache.ts index 618c16e9ef..76a36653a2 100644 --- a/test/cache.ts +++ b/test/cache.ts @@ -1,11 +1,9 @@ import {installPkgs, install} from '../src' -import {add as addDistTag} from './support/distTags' -import testDefaults from './support/testDefaults' +import {prepare, addDistTag, testDefaults} from './utils' import tape = require('tape') import promisifyTape from 'tape-promise' import exists = require('exists-file') import path = require('path') -import prepare from './support/prepare' const test = promisifyTape(tape) diff --git a/test/cli.ts b/test/cli.ts index a7f0792998..e97f69012f 100644 --- a/test/cli.ts +++ b/test/cli.ts @@ -4,9 +4,12 @@ import promisifyTape from 'tape-promise' const test = promisifyTape(tape) import spawn = require('cross-spawn') import exists = require('exists-file') -import {add as addDistTag} from './support/distTags' -import prepare from './support/prepare' -import execPnpm, {sync as execPnpmSync} from './support/execPnpm' +import { + prepare, + addDistTag, + execPnpm, + execPnpmSync, +} from './utils' test('return error status code when underlying command fails', t => { const result = execPnpmSync('invalid-command') diff --git a/test/install.ts b/test/install.ts index bfed8d06b6..83582585c0 100644 --- a/test/install.ts +++ b/test/install.ts @@ -10,15 +10,18 @@ import crossSpawn = require('cross-spawn') const spawnSync = crossSpawn.sync import isCI = require('is-ci') import rimraf = require('rimraf-then') -import {add as addDistTag} from './support/distTags' -import prepare from './support/prepare' +import { + prepare, + addDistTag, + testDefaults, + pathToLocalPkg, + local, + execPnpmSync, +} from './utils' import loadJsonFile = require('load-json-file') -const basicPackageJson = loadJsonFile.sync(path.join(__dirname, './support/simple-package.json')) +const basicPackageJson = loadJsonFile.sync(path.join(__dirname, './utils/simple-package.json')) import {install, installPkgs, uninstall} from '../src' -import testDefaults from './support/testDefaults' import exists = require('exists-file') -import {pathToLocalPkg, local} from './support/localPkg' -import {sync as execPnpmSync} from './support/execPnpm' import isWindows = require('is-windows') const IS_WINDOWS = isWindows() diff --git a/test/link.ts b/test/link.ts index e9e454e3af..3d1e759164 100644 --- a/test/link.ts +++ b/test/link.ts @@ -2,8 +2,12 @@ import tape = require('tape') import promisifyTape from 'tape-promise' const test = promisifyTape(tape) import path = require('path') -import isExecutable from './support/isExecutable' -import prepare from './support/prepare' +import { + prepare, + isExecutable, + pathToLocalPkg, + testDefaults, + } from './utils' import mkdirp = require('mkdirp') import thenify = require('thenify') import ncpCB = require('ncp') @@ -14,8 +18,6 @@ import { linkFromGlobal, installPkgs } from '../src' -import {pathToLocalPkg} from './support/localPkg' -import testDefaults from './support/testDefaults' test('relative link', async function (t) { prepare(t) diff --git a/test/prune.ts b/test/prune.ts index 5b42899bc5..ab48eb69df 100644 --- a/test/prune.ts +++ b/test/prune.ts @@ -3,10 +3,9 @@ import promisifyTape from 'tape-promise' const test = promisifyTape(tape) import path = require('path') import {installPkgs, prune, prunePkgs} from '../src' -import prepare from './support/prepare' +import {prepare, testDefaults} from './utils' import exists = require('exists-file') import existsSymlink = require('exists-link') -import testDefaults from './support/testDefaults' test('prune removes extraneous packages', async function (t) { const project = prepare(t) diff --git a/test/uninstall.ts b/test/uninstall.ts index 3c23df6e97..faf0a3d259 100644 --- a/test/uninstall.ts +++ b/test/uninstall.ts @@ -5,8 +5,7 @@ import path = require('path') import fs = require('fs') import exists = require('exists-file') import existsSymlink = require('exists-link') -import prepare from './support/prepare' -import testDefaults from './support/testDefaults' +import {prepare, testDefaults} from './utils' import {installPkgs, uninstall} from '../src' test('uninstall package with no dependencies', async function (t) { diff --git a/test/support/distTags.ts b/test/utils/distTags.ts similarity index 100% rename from test/support/distTags.ts rename to test/utils/distTags.ts diff --git a/test/support/execPnpm.ts b/test/utils/execPnpm.ts similarity index 100% rename from test/support/execPnpm.ts rename to test/utils/execPnpm.ts diff --git a/test/utils/index.ts b/test/utils/index.ts new file mode 100644 index 0000000000..94bb653c37 --- /dev/null +++ b/test/utils/index.ts @@ -0,0 +1,16 @@ +import prepare from './prepare' +import testDefaults from './testDefaults' +import execPnpm, {sync as execPnpmSync} from './execPnpm' +import isExecutable from './isExecutable' +import {add as addDistTag} from './distTags' + +export { + prepare, + testDefaults, + execPnpm, + execPnpmSync, + isExecutable, + addDistTag, +} + +export * from './localPkg' diff --git a/test/support/isExecutable.ts b/test/utils/isExecutable.ts similarity index 100% rename from test/support/isExecutable.ts rename to test/utils/isExecutable.ts diff --git a/test/support/localPkg.ts b/test/utils/localPkg.ts similarity index 100% rename from test/support/localPkg.ts rename to test/utils/localPkg.ts diff --git a/test/support/prepare.ts b/test/utils/prepare.ts similarity index 100% rename from test/support/prepare.ts rename to test/utils/prepare.ts diff --git a/test/support/simple-package.json b/test/utils/simple-package.json similarity index 100% rename from test/support/simple-package.json rename to test/utils/simple-package.json diff --git a/test/support/testDefaults.ts b/test/utils/testDefaults.ts similarity index 100% rename from test/support/testDefaults.ts rename to test/utils/testDefaults.ts diff --git a/test/verify.ts b/test/verify.ts index 713bb9dd5c..ab5d827c9e 100644 --- a/test/verify.ts +++ b/test/verify.ts @@ -1,10 +1,8 @@ import tape = require('tape') import promisifyTape from 'tape-promise' import rimraf = require('rimraf-then') -import prepare from './support/prepare' -import testDefaults from './support/testDefaults' +import {prepare, testDefaults, execPnpm} from './utils' import {verify, installPkgs} from '../src' -import execPnpm from './support/execPnpm' const test = promisifyTape(tape)