refactor(tests): quiet by default and use API for testing
This commit is contained in:
1 parent
3a61c252ac
commit
aa71a3e01b
5 files changed
+75
-73
No files matched your search
+43
-44
@@ -12,8 +12,7 @@ import isCI = require('is-ci')
|
||||
import prepare from './support/prepare'
|
||||
import requireJson from '../src/fs/requireJson'
|
||||
const basicPackageJson = requireJson(path.join(__dirname, './support/simple-package.json'))
|
||||
import install from '../src/cmd/install'
|
||||
import uninstall from '../src/cmd/uninstall'
|
||||
import {install, installPkgs, uninstall} from '../src'
|
||||
import isExecutable from './support/isExecutable'
|
||||
import exists from './support/exists'
|
||||
import globalPath from './support/globalPath'
|
||||
@@ -28,7 +27,7 @@ if (!caw() && !isWindows) {
|
||||
|
||||
test('small with dependencies (rimraf)', async function (t) {
|
||||
prepare()
|
||||
await install(['rimraf@2.5.1'], { quiet: true })
|
||||
await installPkgs(['rimraf@2.5.1'])
|
||||
|
||||
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'))
|
||||
t.ok(typeof rimraf === 'function', 'rimraf() is available')
|
||||
@@ -37,7 +36,7 @@ test('small with dependencies (rimraf)', async function (t) {
|
||||
|
||||
test('no dependencies (lodash)', async function (t) {
|
||||
prepare()
|
||||
await install(['lodash@4.0.0'], { quiet: true })
|
||||
await installPkgs(['lodash@4.0.0'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', 'lodash'))
|
||||
t.ok(typeof _ === 'function', '_ is available')
|
||||
@@ -46,7 +45,7 @@ test('no dependencies (lodash)', async function (t) {
|
||||
|
||||
test('scoped modules without version spec (@rstacruz/tap-spec)', async function (t) {
|
||||
prepare()
|
||||
await install(['@rstacruz/tap-spec'], { quiet: true })
|
||||
await installPkgs(['@rstacruz/tap-spec'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof _ === 'function', 'tap-spec is available')
|
||||
@@ -54,7 +53,7 @@ test('scoped modules without version spec (@rstacruz/tap-spec)', async function
|
||||
|
||||
test('scoped modules with versions (@rstacruz/tap-spec@4.1.1)', async function (t) {
|
||||
prepare()
|
||||
await install(['@rstacruz/tap-spec@4.1.1'], { quiet: true })
|
||||
await installPkgs(['@rstacruz/tap-spec@4.1.1'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof _ === 'function', 'tap-spec is available')
|
||||
@@ -62,7 +61,7 @@ test('scoped modules with versions (@rstacruz/tap-spec@4.1.1)', async function (
|
||||
|
||||
test('scoped modules (@rstacruz/tap-spec@*)', async function (t) {
|
||||
prepare()
|
||||
await install(['@rstacruz/tap-spec@*'], { quiet: true })
|
||||
await installPkgs(['@rstacruz/tap-spec@*'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof _ === 'function', 'tap-spec is available')
|
||||
@@ -70,7 +69,7 @@ test('scoped modules (@rstacruz/tap-spec@*)', async function (t) {
|
||||
|
||||
test('multiple scoped modules (@rstacruz/...)', async function (t) {
|
||||
prepare()
|
||||
await install(['@rstacruz/tap-spec@*', '@rstacruz/travis-encrypt@*'], { quiet: true })
|
||||
await installPkgs(['@rstacruz/tap-spec@*', '@rstacruz/travis-encrypt@*'])
|
||||
|
||||
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof tapSpec === 'function', 'tap-spec is available')
|
||||
@@ -80,7 +79,7 @@ test('multiple scoped modules (@rstacruz/...)', async function (t) {
|
||||
|
||||
test('nested scoped modules (test-pnpm-issue219 -> @zkochan/test-pnpm-issue219)', async function (t) {
|
||||
prepare()
|
||||
await install(['test-pnpm-issue219@1.0.2'], { quiet: true })
|
||||
await installPkgs(['test-pnpm-issue219@1.0.2'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', 'test-pnpm-issue219'))
|
||||
t.ok(_ === 'test-pnpm-issue219,@zkochan/test-pnpm-issue219', 'nested scoped package is available')
|
||||
@@ -88,7 +87,7 @@ test('nested scoped modules (test-pnpm-issue219 -> @zkochan/test-pnpm-issue219)'
|
||||
|
||||
test('scoped modules from a directory', async function (t) {
|
||||
prepare()
|
||||
await install([local('local-scoped-pkg')], { quiet: true })
|
||||
await installPkgs([local('local-scoped-pkg')])
|
||||
|
||||
const localPkg = require(
|
||||
path.join(process.cwd(), 'node_modules', '@scope', 'local-scoped-pkg'))
|
||||
@@ -98,7 +97,7 @@ test('scoped modules from a directory', async function (t) {
|
||||
|
||||
test('skip failing optional dependencies', async function (t) {
|
||||
prepare()
|
||||
await install(['pkg-with-failing-optional-dependency@1.0.1'], { quiet: true })
|
||||
await installPkgs(['pkg-with-failing-optional-dependency@1.0.1'])
|
||||
|
||||
const isNegative = require(path.join(process.cwd(), 'node_modules', 'pkg-with-failing-optional-dependency'))
|
||||
t.ok(isNegative(-1), 'package with failed optional dependency has the dependencies installed correctly')
|
||||
@@ -106,8 +105,8 @@ test('skip failing optional dependencies', async function (t) {
|
||||
|
||||
test('idempotency (rimraf)', async function (t) {
|
||||
prepare()
|
||||
await install(['rimraf@2.5.1'], { quiet: true })
|
||||
await install(['rimraf@2.5.1'], { quiet: true })
|
||||
await installPkgs(['rimraf@2.5.1'])
|
||||
await installPkgs(['rimraf@2.5.1'])
|
||||
|
||||
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'))
|
||||
t.ok(typeof rimraf === 'function', 'rimraf is available')
|
||||
@@ -115,8 +114,8 @@ test('idempotency (rimraf)', async function (t) {
|
||||
|
||||
test('overwriting (lodash@3.10.1 and @4.0.0)', async function (t) {
|
||||
prepare()
|
||||
await install(['lodash@3.10.1'], { quiet: true })
|
||||
await install(['lodash@4.0.0'], { quiet: true })
|
||||
await installPkgs(['lodash@3.10.1'])
|
||||
await installPkgs(['lodash@4.0.0'])
|
||||
|
||||
const _ = require(path.join(process.cwd(), 'node_modules', 'lodash', 'package.json'))
|
||||
t.ok(_.version === '4.0.0', 'lodash is 4.0.0')
|
||||
@@ -124,7 +123,7 @@ test('overwriting (lodash@3.10.1 and @4.0.0)', async function (t) {
|
||||
|
||||
test('big with dependencies and circular deps (babel-preset-2015)', async function (t) {
|
||||
prepare()
|
||||
await install(['babel-preset-es2015@6.3.13'], { quiet: true })
|
||||
await installPkgs(['babel-preset-es2015@6.3.13'])
|
||||
|
||||
const b = require(path.join(process.cwd(), 'node_modules', 'babel-preset-es2015'))
|
||||
t.ok(typeof b === 'object', 'babel-preset-es2015 is available')
|
||||
@@ -137,7 +136,7 @@ test('bundleDependencies (fsevents@1.0.6)', async function (t) {
|
||||
}
|
||||
|
||||
prepare()
|
||||
await install(['fsevents@1.0.6'], { quiet: true })
|
||||
await installPkgs(['fsevents@1.0.6'])
|
||||
|
||||
isExecutable(t, path.join(process.cwd(), 'node_modules', 'fsevents', 'node_modules', '.bin', 'mkdirp'))
|
||||
})
|
||||
@@ -149,7 +148,7 @@ test('compiled modules (ursa@0.9.1)', async function (t) {
|
||||
}
|
||||
|
||||
prepare()
|
||||
await install(['ursa@0.9.1'], { quiet: false })
|
||||
await installPkgs(['ursa@0.9.1'])
|
||||
|
||||
const ursa = require(path.join(process.cwd(), 'node_modules', 'ursa'))
|
||||
t.ok(typeof ursa === 'object', 'ursa() is available')
|
||||
@@ -157,7 +156,7 @@ test('compiled modules (ursa@0.9.1)', async function (t) {
|
||||
|
||||
test('tarballs (is-array-1.0.1.tgz)', async function (t) {
|
||||
prepare()
|
||||
await install(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], { quiet: true })
|
||||
await installPkgs(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'])
|
||||
|
||||
const isArray = require(
|
||||
path.join(process.cwd(), 'node_modules', 'is-array'))
|
||||
@@ -172,7 +171,7 @@ test('tarballs (is-array-1.0.1.tgz)', async function (t) {
|
||||
|
||||
test('tarballs from GitHub (is-negative)', async function (t) {
|
||||
prepare()
|
||||
await install(['is-negative@https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz'], { quiet: true })
|
||||
await installPkgs(['is-negative@https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz'])
|
||||
|
||||
const isNegative = require(
|
||||
path.join(process.cwd(), 'node_modules', 'is-negative'))
|
||||
@@ -182,7 +181,7 @@ test('tarballs from GitHub (is-negative)', async function (t) {
|
||||
|
||||
test('local file', async function (t) {
|
||||
prepare()
|
||||
await install([local('local-pkg')], { quiet: true })
|
||||
await installPkgs([local('local-pkg')])
|
||||
|
||||
const localPkg = require(
|
||||
path.join(process.cwd(), 'node_modules', 'local-pkg'))
|
||||
@@ -192,7 +191,7 @@ test('local file', async function (t) {
|
||||
|
||||
test('nested local dependency of a local dependency', async function (t) {
|
||||
prepare()
|
||||
await install([local('pkg-with-local-dep')], { quiet: true })
|
||||
await installPkgs([local('pkg-with-local-dep')])
|
||||
|
||||
const pkgWithLocalDep = require(
|
||||
path.join(process.cwd(), 'node_modules', 'pkg-with-local-dep'))
|
||||
@@ -204,7 +203,7 @@ test('nested local dependency of a local dependency', async function (t) {
|
||||
|
||||
test('from a github repo', async function (t) {
|
||||
prepare()
|
||||
await install(['kevva/is-negative'], { quiet: true })
|
||||
await installPkgs(['kevva/is-negative'])
|
||||
|
||||
const localPkg = require(
|
||||
path.join(process.cwd(), 'node_modules', 'is-negative'))
|
||||
@@ -218,7 +217,7 @@ test('from a git repo', async function (t) {
|
||||
return t.end()
|
||||
}
|
||||
prepare()
|
||||
await install(['git+ssh://git@github.com/kevva/is-negative.git'], { quiet: true })
|
||||
await installPkgs(['git+ssh://git@github.com/kevva/is-negative.git'])
|
||||
|
||||
const localPkg = require(
|
||||
path.join(process.cwd(), 'node_modules', 'is-negative'))
|
||||
@@ -229,7 +228,7 @@ test('from a git repo', async function (t) {
|
||||
test('shrinkwrap compatibility', async function (t) {
|
||||
prepare({ dependencies: { rimraf: '*' } })
|
||||
|
||||
await install(['rimraf@2.5.1'], { quiet: true })
|
||||
await installPkgs(['rimraf@2.5.1'])
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = crossSpawn.spawn('npm', ['shrinkwrap'])
|
||||
@@ -248,7 +247,7 @@ test('shrinkwrap compatibility', async function (t) {
|
||||
|
||||
test('run pre/postinstall scripts', async function (t) {
|
||||
prepare()
|
||||
await install([local('pre-and-postinstall-scripts-example')], { quiet: true })
|
||||
await installPkgs([local('pre-and-postinstall-scripts-example')])
|
||||
|
||||
const generatedByPreinstall = require(path.join(process.cwd(), 'node_modules', 'pre-and-postinstall-scripts-example/generated-by-preinstall'))
|
||||
t.ok(typeof generatedByPreinstall === 'function', 'generatedByPreinstall() is available')
|
||||
@@ -259,7 +258,7 @@ test('run pre/postinstall scripts', async function (t) {
|
||||
|
||||
test('run install scripts', async function (t) {
|
||||
prepare()
|
||||
await install([local('install-script-example')], { quiet: true })
|
||||
await installPkgs([local('install-script-example')])
|
||||
|
||||
const generatedByInstall = require(path.join(process.cwd(), 'node_modules', 'install-script-example/generated-by-install'))
|
||||
t.ok(typeof generatedByInstall === 'function', 'generatedByInstall() is available')
|
||||
@@ -267,7 +266,7 @@ test('run install scripts', async function (t) {
|
||||
|
||||
test('save to package.json (rimraf@2.5.1)', async function (t) {
|
||||
prepare()
|
||||
await install(['rimraf@2.5.1'], { quiet: true, save: true })
|
||||
await installPkgs(['rimraf@2.5.1'], { save: true })
|
||||
|
||||
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'))
|
||||
t.ok(typeof rimraf === 'function', 'rimraf() is available')
|
||||
@@ -279,7 +278,7 @@ test('save to package.json (rimraf@2.5.1)', async function (t) {
|
||||
|
||||
test('saveDev scoped module to package.json (@rstacruz/tap-spec)', async function (t) {
|
||||
prepare()
|
||||
await install(['@rstacruz/tap-spec'], { quiet: true, saveDev: true })
|
||||
await installPkgs(['@rstacruz/tap-spec'], { saveDev: true })
|
||||
|
||||
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof tapSpec === 'function', 'tapSpec() is available')
|
||||
@@ -291,7 +290,7 @@ test('saveDev scoped module to package.json (@rstacruz/tap-spec)', async functio
|
||||
|
||||
test('multiple save to package.json with `exact` versions (@rstacruz/tap-spec & rimraf@2.5.1) (in sorted order)', async function (t) {
|
||||
prepare()
|
||||
await install(['rimraf@2.5.1', '@rstacruz/tap-spec@latest'], { quiet: true, save: true, saveExact: true })
|
||||
await installPkgs(['rimraf@2.5.1', '@rstacruz/tap-spec@latest'], { save: true, saveExact: true })
|
||||
|
||||
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
|
||||
t.ok(typeof tapSpec === 'function', 'tapSpec() is available')
|
||||
@@ -311,7 +310,7 @@ test('multiple save to package.json with `exact` versions (@rstacruz/tap-spec &
|
||||
|
||||
test('flattening symlinks (minimatch@3.0.0)', async function (t) {
|
||||
prepare()
|
||||
await install(['minimatch@3.0.0'], { quiet: true })
|
||||
await installPkgs(['minimatch@3.0.0'])
|
||||
|
||||
const stat = fs.lstatSync(path.join(process.cwd(), 'node_modules', '.store', 'node_modules', 'balanced-match'))
|
||||
t.ok(stat.isSymbolicLink(), 'balanced-match is linked into store node_modules')
|
||||
@@ -322,8 +321,8 @@ test('flattening symlinks (minimatch@3.0.0)', async function (t) {
|
||||
|
||||
test('flattening symlinks (minimatch + balanced-match)', async function (t) {
|
||||
prepare()
|
||||
await install(['minimatch@3.0.0'], { quiet: true })
|
||||
await install(['balanced-match@^0.3.0'], { quiet: true })
|
||||
await installPkgs(['minimatch@3.0.0'])
|
||||
await installPkgs(['balanced-match@^0.3.0'])
|
||||
|
||||
let _ = await exists(path.join(process.cwd(), 'node_modules', '.store', 'node_modules', 'balanced-match'))
|
||||
t.ok(!_, 'balanced-match is removed from store node_modules')
|
||||
@@ -335,7 +334,7 @@ test('flattening symlinks (minimatch + balanced-match)', async function (t) {
|
||||
test('production install (with --production flag)', async function (t) {
|
||||
prepare(basicPackageJson)
|
||||
|
||||
await install([], { quiet: true, production: true })
|
||||
await install({ production: true })
|
||||
|
||||
const rimrafDir = fs.statSync(path.join(process.cwd(), 'node_modules', 'rimraf'))
|
||||
|
||||
@@ -355,7 +354,7 @@ test('production install (with production NODE_ENV)', async function (t) {
|
||||
process.env.NODE_ENV = 'production'
|
||||
prepare(basicPackageJson)
|
||||
|
||||
await install([], { quiet: true })
|
||||
await install()
|
||||
|
||||
// reset NODE_ENV
|
||||
process.env.NODE_ENV = originalNodeEnv
|
||||
@@ -376,9 +375,9 @@ const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
test('fail when trying to install into the same store simultaneously', t => {
|
||||
prepare()
|
||||
return Promise.all([
|
||||
install([local('pkg-that-installs-slowly')], { quiet: true }),
|
||||
installPkgs([local('pkg-that-installs-slowly')]),
|
||||
wait(500) // to be sure that lock was created
|
||||
.then(_ => install(['rimraf@2.5.1'], { quiet: true }))
|
||||
.then(_ => installPkgs(['rimraf@2.5.1']))
|
||||
.then(_ => t.fail('the store should have been locked'))
|
||||
.catch(err => t.ok(err, 'store is locked'))
|
||||
])
|
||||
@@ -387,9 +386,9 @@ test('fail when trying to install into the same store simultaneously', t => {
|
||||
test('fail when trying to install and uninstall from the same store simultaneously', t => {
|
||||
prepare()
|
||||
return Promise.all([
|
||||
install([local('pkg-that-installs-slowly')], { quiet: true }),
|
||||
installPkgs([local('pkg-that-installs-slowly')]),
|
||||
wait(500) // to be sure that lock was created
|
||||
.then(_ => uninstall(['rimraf@2.5.1'], { quiet: true }))
|
||||
.then(_ => uninstall(['rimraf@2.5.1']))
|
||||
.then(_ => t.fail('the store should have been locked'))
|
||||
.catch(err => t.ok(err, 'store is locked'))
|
||||
])
|
||||
@@ -401,7 +400,7 @@ test('packages should find the plugins they use when symlinks are preserved', as
|
||||
return
|
||||
}
|
||||
prepare()
|
||||
await install([local('pkg-that-uses-plugins'), local('plugin-example')], { quiet: true, save: true })
|
||||
await installPkgs([local('pkg-that-uses-plugins'), local('plugin-example')], { save: true })
|
||||
const result = spawnSync('pkg-that-uses-plugins', [], {
|
||||
env: extendPathWithLocalBin()
|
||||
})
|
||||
@@ -411,7 +410,7 @@ test('packages should find the plugins they use when symlinks are preserved', as
|
||||
|
||||
test('run js bin file', async function (t) {
|
||||
prepare()
|
||||
await install([local('hello-world-js-bin')], { quiet: true, save: true })
|
||||
await installPkgs([local('hello-world-js-bin')], { save: true })
|
||||
|
||||
const result = spawnSync('hello-world-js-bin', [], {
|
||||
env: extendPathWithLocalBin()
|
||||
@@ -477,7 +476,7 @@ test('prepublish is executed after installation', t => {
|
||||
})
|
||||
|
||||
test('global installation', async function (t) {
|
||||
await install(['is-positive'], {quiet: true, globalPath, global: true})
|
||||
await installPkgs(['is-positive'], {globalPath, global: true})
|
||||
|
||||
const isPositive = require(path.join(globalPath, 'node_modules', 'is-positive'))
|
||||
t.ok(typeof isPositive === 'function', 'isPositive() is available')
|
||||
@@ -485,7 +484,7 @@ test('global installation', async function (t) {
|
||||
|
||||
test('tarball local package', async function (t) {
|
||||
prepare()
|
||||
await install([pathToLocalPkg('tar-pkg/tar-pkg-1.0.0.tgz')], { quiet: true })
|
||||
await installPkgs([pathToLocalPkg('tar-pkg/tar-pkg-1.0.0.tgz')])
|
||||
|
||||
const localPkg = require(path.join(process.cwd(), 'node_modules', 'tar-pkg'))
|
||||
|
||||
@@ -494,7 +493,7 @@ test('tarball local package', async function (t) {
|
||||
|
||||
test("don't fail when peer dependency is fetched from GitHub", t => {
|
||||
prepare()
|
||||
return install([local('test-pnpm-peer-deps')], { quiet: true })
|
||||
return installPkgs([local('test-pnpm-peer-deps')])
|
||||
})
|
||||
|
||||
test('create a pnpm-debug.log file when the command fails', async function (t) {
|
||||
|
||||
+10
-6
@@ -8,8 +8,12 @@ import mkdirp = require('mkdirp')
|
||||
import thenify = require('thenify')
|
||||
import ncpCB = require('ncp')
|
||||
const ncp = thenify(ncpCB.ncp)
|
||||
import link from '../src/cmd/link'
|
||||
import install from '../src/cmd/install'
|
||||
import {
|
||||
linkFromRelative,
|
||||
linkToGlobal,
|
||||
linkFromGlobal,
|
||||
installPkgs
|
||||
} from '../src'
|
||||
import globalPath from './support/globalPath'
|
||||
import {pathToLocalPkg} from './support/localPkg'
|
||||
|
||||
@@ -21,7 +25,7 @@ test('relative link', async function (t) {
|
||||
const linkedPkgPath = path.resolve(tmpDir, linkedPkgDirName)
|
||||
|
||||
await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
|
||||
await link([`../${linkedPkgDirName}`], { quiet: true })
|
||||
await linkFromRelative(`../${linkedPkgDirName}`)
|
||||
|
||||
isExecutable(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'))
|
||||
})
|
||||
@@ -35,10 +39,10 @@ test('global link', async function (t) {
|
||||
await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
|
||||
|
||||
process.chdir(linkedPkgPath)
|
||||
await link([], { globalPath, quiet: true })
|
||||
await linkToGlobal({ globalPath })
|
||||
|
||||
prepare()
|
||||
await link([linkedPkgName], { globalPath, quiet: true })
|
||||
await linkFromGlobal(linkedPkgName, { globalPath })
|
||||
|
||||
isExecutable(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'))
|
||||
})
|
||||
@@ -51,7 +55,7 @@ test('link local package if link-local = true', async function (t) {
|
||||
const linkedPkgPath = path.resolve(tmpDir, linkedPkgDirName)
|
||||
|
||||
await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
|
||||
await install([`file:../${linkedPkgDirName}`], { quiet: true, linkLocal: true })
|
||||
await installPkgs([`file:../${linkedPkgDirName}`], { linkLocal: true })
|
||||
|
||||
isExecutable(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'))
|
||||
})
|
||||
+14
-15
@@ -2,19 +2,18 @@ import tape = require('tape')
|
||||
import promisifyTape = require('tape-promise')
|
||||
const test = promisifyTape(tape)
|
||||
import path = require('path')
|
||||
import prune from '../src/cmd/prune'
|
||||
import install from '../src/cmd/install'
|
||||
import {installPkgs, prune, prunePkgs} from '../src'
|
||||
import prepare from './support/prepare'
|
||||
import exists, {existsSymlink} from './support/exists'
|
||||
|
||||
test('prune removes extraneous packages', async function (t) {
|
||||
prepare()
|
||||
|
||||
await install(['is-negative@2.1.0'], {save: true, quiet: true})
|
||||
await install(['applyq@0.2.1'], {saveDev: true, quiet: true})
|
||||
await install(['fnumber@0.1.0'], {saveOptional: true, quiet: true})
|
||||
await install(['is-positive@2.0.0', '@zkochan/logger@0.1.0'], {quiet: true})
|
||||
await prune([], {})
|
||||
await installPkgs(['is-negative@2.1.0'], {save: true})
|
||||
await installPkgs(['applyq@0.2.1'], {saveDev: true})
|
||||
await installPkgs(['fnumber@0.1.0'], {saveOptional: true})
|
||||
await installPkgs(['is-positive@2.0.0', '@zkochan/logger@0.1.0'])
|
||||
await prune()
|
||||
|
||||
const store = path.join(process.cwd(), 'node_modules', '.store')
|
||||
const modules = path.join(process.cwd(), 'node_modules')
|
||||
@@ -53,8 +52,8 @@ test('prune removes extraneous packages', async function (t) {
|
||||
test('prune removes only the specified extraneous packages', async function (t) {
|
||||
prepare()
|
||||
|
||||
await install(['is-positive@2.0.0', 'is-negative@2.1.0'], {quiet: true})
|
||||
await prune(['is-positive'], {})
|
||||
await installPkgs(['is-positive@2.0.0', 'is-negative@2.1.0'])
|
||||
await prunePkgs(['is-positive'])
|
||||
|
||||
const store = path.join(process.cwd(), 'node_modules', '.store')
|
||||
const modules = path.join(process.cwd(), 'node_modules')
|
||||
@@ -75,10 +74,10 @@ test('prune removes only the specified extraneous packages', async function (t)
|
||||
test('prune throws error when trying to removes not an extraneous package', async function (t) {
|
||||
prepare()
|
||||
|
||||
await install(['is-positive@2.0.0'], {quiet: true, save: true})
|
||||
await installPkgs(['is-positive@2.0.0'], {save: true})
|
||||
|
||||
try {
|
||||
await prune(['is-positive'], {})
|
||||
await prunePkgs(['is-positive'])
|
||||
t.fail('prune had to fail')
|
||||
} catch (err) {
|
||||
t.equal(err['code'], 'PRUNE_NOT_EXTR', 'cannot prune non-extraneous package error thrown')
|
||||
@@ -88,10 +87,10 @@ test('prune throws error when trying to removes not an extraneous package', asyn
|
||||
test('prune removes dev dependencies in production', async function (t) {
|
||||
prepare()
|
||||
|
||||
await install(['is-positive@2.0.0'], {quiet: true, saveDev: true})
|
||||
await install(['is-negative@2.1.0'], {quiet: true, save: true})
|
||||
await install(['fnumber@0.1.0'], {quiet: true, saveOptional: true})
|
||||
await prune([], {production: true})
|
||||
await installPkgs(['is-positive@2.0.0'], {saveDev: true})
|
||||
await installPkgs(['is-negative@2.1.0'], {save: true})
|
||||
await installPkgs(['fnumber@0.1.0'], {saveOptional: true})
|
||||
await prune({production: true})
|
||||
|
||||
const store = path.join(process.cwd(), 'node_modules', '.store')
|
||||
const modules = path.join(process.cwd(), 'node_modules')
|
||||
|
||||
@@ -13,6 +13,7 @@ const npmrc = stripIndent`
|
||||
fetch-retries = 5
|
||||
fetch-retry-maxtimeout = 180000
|
||||
registry = https://registry.npmjs.org/
|
||||
quiet = true
|
||||
`
|
||||
fs.writeFileSync(path.join(tmpPath, '.npmrc'), npmrc, 'utf-8')
|
||||
|
||||
|
||||
+7
-8
@@ -5,12 +5,11 @@ import path = require('path')
|
||||
import fs = require('fs')
|
||||
import exists, {existsSymlink} from './support/exists'
|
||||
import prepare from './support/prepare'
|
||||
import install from '../src/cmd/install'
|
||||
import uninstall from '../src/cmd/uninstall'
|
||||
import {installPkgs, uninstall} from '../src'
|
||||
|
||||
test('uninstall package with no dependencies', async function (t) {
|
||||
prepare()
|
||||
await install(['is-negative@2.1.0'], { quiet: true, save: true })
|
||||
await installPkgs(['is-negative@2.1.0'], { save: true })
|
||||
await uninstall(['is-negative'], { save: true })
|
||||
|
||||
let stat = await exists(path.join(process.cwd(), 'node_modules', '.store', 'is-negative@2.1.0'))
|
||||
@@ -27,7 +26,7 @@ test('uninstall package with no dependencies', async function (t) {
|
||||
|
||||
test('uninstall scoped package', async function (t) {
|
||||
prepare()
|
||||
await install(['@zkochan/logger@0.1.0'], { quiet: true, save: true })
|
||||
await installPkgs(['@zkochan/logger@0.1.0'], { save: true })
|
||||
await uninstall(['@zkochan/logger'], { save: true })
|
||||
|
||||
let stat = await exists(path.join(process.cwd(), 'node_modules', '.store', '@zkochan+logger@0.1.0'))
|
||||
@@ -44,7 +43,7 @@ test('uninstall scoped package', async function (t) {
|
||||
|
||||
test('uninstall tarball dependency', async function (t) {
|
||||
prepare()
|
||||
await install(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], { quiet: true, save: true })
|
||||
await installPkgs(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], { save: true })
|
||||
await uninstall(['is-array'], { save: true })
|
||||
|
||||
let stat = await exists(path.join(process.cwd(), 'node_modules', '.store', 'is-array-1.0.1#a83102a9c117983e6ff4d85311fb322231abe3d6'))
|
||||
@@ -61,7 +60,7 @@ test('uninstall tarball dependency', async function (t) {
|
||||
|
||||
test('uninstall package with dependencies and do not touch other deps', async function (t) {
|
||||
prepare()
|
||||
await install(['is-negative@2.1.0', 'camelcase-keys@3.0.0'], { quiet: true, save: true })
|
||||
await installPkgs(['is-negative@2.1.0', 'camelcase-keys@3.0.0'], { save: true })
|
||||
await uninstall(['camelcase-keys'], { save: true })
|
||||
|
||||
let stat = await exists(path.join(process.cwd(), 'node_modules', '.store', 'camelcase-keys@2.1.0'))
|
||||
@@ -98,7 +97,7 @@ test('uninstall package with dependencies and do not touch other deps', async fu
|
||||
|
||||
test('uninstall package with its bin files', async function (t) {
|
||||
prepare()
|
||||
await install(['sh-hello-world@1.0.0'], { quiet: true, save: true })
|
||||
await installPkgs(['sh-hello-world@1.0.0'], { save: true })
|
||||
await uninstall(['sh-hello-world'], { save: true })
|
||||
|
||||
// check for both a symlink and a file because in some cases the file will be a proxied not symlinked
|
||||
@@ -111,7 +110,7 @@ test('uninstall package with its bin files', async function (t) {
|
||||
|
||||
test('keep dependencies used by others', async function (t) {
|
||||
prepare()
|
||||
await install(['hastscript@3.0.0', 'camelcase-keys@3.0.0'], { quiet: true, save: true })
|
||||
await installPkgs(['hastscript@3.0.0', 'camelcase-keys@3.0.0'], { save: true })
|
||||
await uninstall(['camelcase-keys'], { save: true })
|
||||
|
||||
let stat = await exists(path.join(process.cwd(), 'node_modules', '.store', 'camelcase-keys@2.1.0'))
|
||||
|
||||
Reference in new issue
Block a user