From 9c9d79cbbe9f7fdf483ffa7a59991ef7edbf83f2 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Tue, 17 Apr 2018 22:53:48 +0300 Subject: [PATCH] test: fix typings to make ts-node happy --- package.json | 1 + shrinkwrap.yaml | 7 +++++++ src/isExternalLink.ts | 0 test/api.ts | 3 ++- test/install/aliases.ts | 2 +- test/install/auth.ts | 8 ++++---- test/install/dedupe.ts | 3 ++- test/install/lifecycleScripts.ts | 3 ++- test/install/misc.ts | 3 ++- test/install/peerDependencies.ts | 3 ++- test/install/shamefullyFlatten.ts | 9 ++++++--- test/install/sideEffects.ts | 2 +- test/rebuild.ts | 16 ++++++++++------ test/shrinkwrap.ts | 14 +++++++++----- test/storePrune.ts | 3 ++- test/uninstall.ts | 6 ++++-- 16 files changed, 55 insertions(+), 28 deletions(-) delete mode 100644 src/isExternalLink.ts diff --git a/package.json b/package.json index 85615b1bba..d1a94d241a 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "@pnpm/default-resolver": "^0.1.5", "@pnpm/logger": "^1.0.0", "@pnpm/store-path": "^1.0.0", + "@types/is-windows": "^0.2.0", "@types/mkdirp": "^0.5.1", "@types/sinon": "^4.1.2", "@types/tape": "^4.2.30", diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index f0e65e4d86..ecae93c37a 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -52,6 +52,7 @@ dependencies: resolve-link-target: 1.0.1 rimraf-then: 1.0.1 semver: 5.5.0 + supi: 'link:../__package_previews__/supi/supi' symlink-dir: 1.1.2 util.promisify: 1.0.0 validate-npm-package-name: 3.0.0 @@ -66,6 +67,7 @@ devDependencies: '@pnpm/default-resolver': 0.1.5 '@pnpm/logger': 1.0.1 '@pnpm/store-path': 1.0.3 + '@types/is-windows': 0.2.0 '@types/mkdirp': 0.5.2 '@types/sinon': 4.3.1 '@types/tape': 4.2.32 @@ -678,6 +680,10 @@ packages: dev: true resolution: integrity: sha512-epDhsJAVxJsWfeqpzEDFhLnhHMbHie/VMFY+2Hvt5p7FemeW5ELM+6gcVYL/ZsUwdu3zrWpDE3VUTddXW+EMYg== + /@types/is-windows/0.2.0: + dev: true + resolution: + integrity: sha1-byTuSHMdMRaOpRBhDW3RXl/Jxv8= /@types/js-yaml/3.11.1: dev: false resolution: @@ -5490,6 +5496,7 @@ specifiers: '@pnpm/types': ^1.7.0 '@types/byline': ^4.2.31 '@types/common-tags': ^1.2.5 + '@types/is-windows': ^0.2.0 '@types/load-json-file': ^2.0.5 '@types/mkdirp': ^0.5.1 '@types/mz': ^0.0.32 diff --git a/src/isExternalLink.ts b/src/isExternalLink.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/api.ts b/test/api.ts index c0cc3e7eed..71ee91b689 100644 --- a/test/api.ts +++ b/test/api.ts @@ -17,7 +17,8 @@ test('API', (t) => { // maybe a new property should be introduced // this seems illogical as even though all save types are false, // the dependency will be saved -test.skip('install fails when all saving types are false', async (t: test.Test) => { +// tslint:disable-next-line:no-string-literal +test['skip']('install fails when all saving types are false', async (t: test.Test) => { try { await pnpm.install(await testDefaults({save: false, saveDev: false, saveOptional: false})) t.fail('installation should have failed') diff --git a/test/install/aliases.ts b/test/install/aliases.ts index 8f61930a5c..46028a3c8e 100644 --- a/test/install/aliases.ts +++ b/test/install/aliases.ts @@ -12,7 +12,7 @@ import { } from '../utils' const test = promisifyTape(tape) -test.only = promisifyTape(tape.only) +test['only'] = promisifyTape(tape.only) // tslint:disable-line:no-string-literal test('installing aliased dependency', async (t: tape.Test) => { const project = prepare(t) diff --git a/test/install/auth.ts b/test/install/auth.ts index 554eb25a70..323cebafaa 100644 --- a/test/install/auth.ts +++ b/test/install/auth.ts @@ -25,7 +25,7 @@ test('a package that need authentication', async (t: tape.Test) => { username: 'foo', }, }, (err: Error, d: object) => err ? reject(err) : resolve(d)) - }) + }) as {token: string} let rawNpmConfig = { '//localhost:4873/:_authToken': data.token, @@ -104,7 +104,7 @@ test('a scoped package that need authentication specific to scope', async (t: ta username: 'foo', }, }, (err: Error, d: object) => err ? reject(err) : resolve(d)) - }) + }) as {token: string} const rawNpmConfig = { '//localhost:4873/:_authToken': data.token, @@ -150,7 +150,7 @@ test('a package that need authentication reuses authorization tokens for tarball username: 'foo', }, }, (err: Error, d: object) => err ? reject(err) : resolve(d)) - }) + }) as {token: string} const rawNpmConfig = { '//127.0.0.1:4873/:_authToken': data.token, @@ -184,7 +184,7 @@ test('a package that need authentication reuses authorization tokens for tarball username: 'foo', }, }, (err: Error, d: object) => err ? reject(err) : resolve(d)) - }) + }) as {token: string} const rawNpmConfig = { '//127.0.0.1:4873/:_authToken': data.token, diff --git a/test/install/dedupe.ts b/test/install/dedupe.ts index abecea8c01..145568640d 100644 --- a/test/install/dedupe.ts +++ b/test/install/dedupe.ts @@ -1,4 +1,4 @@ -import {addDistTag} from 'pnpm-registry-mock' +import pnpmRegistryMock = require('pnpm-registry-mock') import {install, installPkgs} from 'supi' import tape = require('tape') import promisifyTape from 'tape-promise' @@ -8,6 +8,7 @@ import { } from '../utils' const test = promisifyTape(tape) +const addDistTag = pnpmRegistryMock.addDistTag test('prefer version ranges specified for top dependencies', async (t: tape.Test) => { const project = prepare(t, { diff --git a/test/install/lifecycleScripts.ts b/test/install/lifecycleScripts.ts index d24a53ec88..8de6f58978 100644 --- a/test/install/lifecycleScripts.ts +++ b/test/install/lifecycleScripts.ts @@ -141,7 +141,8 @@ test('installation fails if lifecycle script fails', async (t: tape.Test) => { // TODO: unskip // For some reason this fails on CI environments -test.skip('creates env for scripts', async (t: tape.Test) => { +// tslint:disable-next-line:no-string-literal +test['skip']('creates env for scripts', async (t: tape.Test) => { const project = prepare(t, { scripts: { install: `node -e "process.stdout.write(process.env.INIT_CWD)" | json-append output.json`, diff --git a/test/install/misc.ts b/test/install/misc.ts index c1de0c893d..5d272862f8 100644 --- a/test/install/misc.ts +++ b/test/install/misc.ts @@ -416,7 +416,8 @@ test("don't refetch package to store if it has been modified and verify-store-in }) // TODO: decide what to do with this case -test.skip('relink package to project if the dependency is not linked from store', async (t: tape.Test) => { +// tslint:disable-next-line:no-string-literal +test['skip']('relink package to project if the dependency is not linked from store', async (t: tape.Test) => { const project = prepare(t) await installPkgs(['magic-hook@2.0.0'], await testDefaults({save: true, saveExact: true})) diff --git a/test/install/peerDependencies.ts b/test/install/peerDependencies.ts index 1a45bde269..9fb866ba70 100644 --- a/test/install/peerDependencies.ts +++ b/test/install/peerDependencies.ts @@ -164,7 +164,8 @@ test('peer dependencies are linked when running two separate named installations t.equal(deepRequireCwd(['abc-grand-parent-with-c', 'abc-parent-with-ab', 'abc', 'peer-c', './package.json']).version, '1.0.0') }) -test.skip('peer dependencies are linked', async (t: tape.Test) => { +// tslint:disable-next-line:no-string-literal +test['skip']('peer dependencies are linked', async (t: tape.Test) => { const project = prepare(t, { dependencies: { 'abc-grand-parent-with-c': '*', diff --git a/test/install/shamefullyFlatten.ts b/test/install/shamefullyFlatten.ts index 527369e284..fac07f9e34 100644 --- a/test/install/shamefullyFlatten.ts +++ b/test/install/shamefullyFlatten.ts @@ -126,7 +126,8 @@ test('flatten by alias', async (t: tape.Test) => { await project.hasNot('dep-of-pkg-with-1-dep') const modules = await project.loadModules() - t.deepEqual(modules.hoistedAliases, {'localhost+4873/dep-of-pkg-with-1-dep/100.1.0': [ 'dep' ]}, '.modules.yaml updated correctly') + t.ok(modules) + t.deepEqual(modules!.hoistedAliases, {'localhost+4873/dep-of-pkg-with-1-dep/100.1.0': [ 'dep' ]}, '.modules.yaml updated correctly') }) test('should remove aliased flattened dependencies', async (t) => { @@ -146,7 +147,8 @@ test('should remove aliased flattened dependencies', async (t) => { t.ok(caught, 'dep removed correctly') const modules = await project.loadModules() - t.deepEqual(modules.hoistedAliases, {}, '.modules.yaml updated correctly') + t.ok(modules) + t.deepEqual(modules!.hoistedAliases, {}, '.modules.yaml updated correctly') }) test('should update .modules.yaml when pruning if we are flattening', async (t) => { @@ -163,7 +165,8 @@ test('should update .modules.yaml when pruning if we are flattening', async (t) await prune(await testDefaults({shamefullyFlatten: true})) const modules = await project.loadModules() - t.deepEqual(modules.hoistedAliases, {}, '.modules.yaml updated correctly') + t.ok(modules) + t.deepEqual(modules!.hoistedAliases, {}, '.modules.yaml updated correctly') }) test('should reflatten after pruning', async (t) => { diff --git a/test/install/sideEffects.ts b/test/install/sideEffects.ts index d95c896758..eeb893163a 100644 --- a/test/install/sideEffects.ts +++ b/test/install/sideEffects.ts @@ -12,7 +12,7 @@ import { } from '../utils' const test = promisifyTape(tape) -test.only = promisifyTape(tape.only) +test['only'] = promisifyTape(tape.only) // tslint:disable-line:no-string-literal test('caching side effects of native package', async (t) => { const project = prepare(t) diff --git a/test/rebuild.ts b/test/rebuild.ts index fbc53bdb15..f30d675ef2 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -18,7 +18,7 @@ test('rebuilds dependencies', async (t: tape.Test) => { await installPkgs(['pre-and-postinstall-scripts-example', 'zkochan/install-scripts-example'], await testDefaults({saveDev: true, ignoreScripts: true})) let modules = await project.loadModules() - t.deepEqual(modules.pendingBuilds, [ + t.deepEqual(modules!.pendingBuilds, [ '/pre-and-postinstall-scripts-example/1.0.0', 'github.com/zkochan/install-scripts-example/26950260310939009680b6a377a0efd0925df9ba', ]) @@ -26,7 +26,8 @@ test('rebuilds dependencies', async (t: tape.Test) => { await rebuild(await testDefaults()) modules = await project.loadModules() - t.equal(modules.pendingBuilds.length, 0) + t.ok(modules) + t.equal(modules!.pendingBuilds.length, 0) { const generatedByPreinstall = project.requireModule('pre-and-postinstall-scripts-example/generated-by-preinstall') @@ -67,7 +68,7 @@ test('rebuild with pending option', async (t: tape.Test) => { await installPkgs(['zkochan/install-scripts-example'], await testDefaults({ignoreScripts: true})) let modules = await project.loadModules() - t.deepEqual(modules.pendingBuilds, [ + t.deepEqual(modules!.pendingBuilds, [ '/pre-and-postinstall-scripts-example/1.0.0', 'github.com/zkochan/install-scripts-example/26950260310939009680b6a377a0efd0925df9ba', ]) @@ -81,7 +82,8 @@ test('rebuild with pending option', async (t: tape.Test) => { await rebuild(await testDefaults({rawNpmConfig: {pending: true}})) modules = await project.loadModules() - t.equal(modules.pendingBuilds.length, 0) + t.ok(modules) + t.equal(modules!.pendingBuilds.length, 0) { const generatedByPreinstall = project.requireModule('pre-and-postinstall-scripts-example/generated-by-preinstall') @@ -106,7 +108,8 @@ test('rebuild dependencies in correct order', async (t: tape.Test) => { await installPkgs(['with-postinstall-a'], await testDefaults({ignoreScripts: true})) let modules = await project.loadModules() - t.doesNotEqual(modules.pendingBuilds.length, 0) + t.ok(modules) + t.doesNotEqual(modules!.pendingBuilds.length, 0) await project.hasNot('.localhost+4873/with-postinstall-b/1.0.0/node_modules/with-postinstall-b/output.json') await project.hasNot('with-postinstall-a/output.json') @@ -114,7 +117,8 @@ test('rebuild dependencies in correct order', async (t: tape.Test) => { await rebuild(await testDefaults({rawNpmConfig: {pending: true}})) modules = await project.loadModules() - t.equal(modules.pendingBuilds.length, 0) + t.ok(modules) + t.equal(modules!.pendingBuilds.length, 0) t.ok(+project.requireModule('.localhost+4873/with-postinstall-b/1.0.0/node_modules/with-postinstall-b/output.json')[0] < +project.requireModule('with-postinstall-a/output.json')[0]) }) diff --git a/test/shrinkwrap.ts b/test/shrinkwrap.ts index decc805ed5..c55a3497f9 100644 --- a/test/shrinkwrap.ts +++ b/test/shrinkwrap.ts @@ -23,8 +23,8 @@ import { } from './utils' const test = promisifyTape(tape) -test.only = promisifyTape(tape.only) -test.skip = promisifyTape(tape.skip) +test['only'] = promisifyTape(tape.only) // tslint:disable-line:no-string-literal +test['skip'] = promisifyTape(tape.skip) // tslint:disable-line:no-string-literal const SHRINKWRAP_WARN_LOG = { level: 'warn', @@ -38,7 +38,8 @@ test('shrinkwrap file has correct format', async (t: tape.Test) => { await installPkgs(['pkg-with-1-dep', '@rstacruz/tap-spec@4.1.1', 'kevva/is-negative#1d7e288222b53a0cab90a331f1865220ec29560c'], await testDefaults({save: true})) const modules = await project.loadModules() - t.equal(modules.pendingBuilds.length, 0) + t.ok(modules) + t.equal(modules!.pendingBuilds.length, 0) const shr = await project.loadShrinkwrap() const id = '/pkg-with-1-dep/100.0.0' @@ -531,7 +532,8 @@ test('repeat install with no inner shrinkwrap should not rewrite packages in nod // Skipped because the npm-registry.compass.com server was down // might be a good idea to mock it -test.skip('installing from shrinkwrap when using npm enterprise', async (t: tape.Test) => { +// tslint:disable-next-line:no-string-literal +test['skip']('installing from shrinkwrap when using npm enterprise', async (t: tape.Test) => { const project = prepare(t) const opts = await testDefaults({registry: 'https://npm-registry.compass.com/'}) @@ -710,7 +712,9 @@ test('pendingBuilds gets updated if install removes packages', async (t: tape.Te await install(await testDefaults({ ignoreScripts: true })) const modules2 = await project.loadModules() - t.ok(modules1.pendingBuilds.length > modules2.pendingBuilds.length, 'pendingBuilds gets updated when install removes packages') + t.ok(modules1) + t.ok(modules2) + t.ok(modules1!.pendingBuilds.length > modules2!.pendingBuilds.length, 'pendingBuilds gets updated when install removes packages') }) test('dev properties are correctly updated on named install', async (t: tape.Test) => { diff --git a/test/storePrune.ts b/test/storePrune.ts index f398131c00..22d255650f 100644 --- a/test/storePrune.ts +++ b/test/storePrune.ts @@ -84,7 +84,8 @@ test('keep dependencies used by others', async (t: tape.Test) => { const shr = await project.loadShrinkwrap() t.notOk(R.isEmpty(shr.packages)) - R.toPairs(shr.packages).forEach((pair) => t.ok(pair[1].dev, `${pair[0]} is dev`)) + // tslint:disable-next-line:no-string-literal + R.toPairs(shr.packages).forEach((pair) => t.ok(pair[1]['dev'], `${pair[0]} is dev`)) await storePrune(await testDefaults()) diff --git a/test/uninstall.ts b/test/uninstall.ts index 020cb2efae..c25181f212 100644 --- a/test/uninstall.ts +++ b/test/uninstall.ts @@ -166,10 +166,12 @@ test('pendingBuilds gets updated after uninstall', async (t: tape.Test) => { await installPkgs(['pre-and-postinstall-scripts-example', 'with-postinstall-b'], await testDefaults({save: true, ignoreScripts: true})) const modules1 = await project.loadModules() - t.equal(modules1.pendingBuilds.length, 2, 'installPkgs should update pendingBuilds') + t.ok(modules1) + t.equal(modules1!.pendingBuilds.length, 2, 'installPkgs should update pendingBuilds') await uninstall(['with-postinstall-b'], await testDefaults({save: true})) const modules2 = await project.loadModules() - t.equal(modules2.pendingBuilds.length, 1, 'uninstall should update pendingBuilds') + t.ok(modules2) + t.equal(modules2!.pendingBuilds.length, 1, 'uninstall should update pendingBuilds') })