mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-04 05:56:24 -04:00
test: use nock for mocking the registry
This commit is contained in:
10
package.json
10
package.json
@@ -13,11 +13,7 @@
|
||||
"scripts": {
|
||||
"lint": "tslint -c tslint.json --project .",
|
||||
"tsc": "rimraf lib && tsc",
|
||||
"pretest": "pnpm-registry-mock prepare",
|
||||
"test": "rimraf .store && npm run lint && preview && npm run test:e2e && mos t",
|
||||
"test:tap": "ts-node test --type-check",
|
||||
"test:e2e": "npm-run-all -p -r pnpm-registry-mock test:tap",
|
||||
"pnpm-registry-mock": "pnpm-registry-mock",
|
||||
"test": "rimraf .store && npm run lint && preview && ts-node test --type-check && mos t",
|
||||
"md": "mos",
|
||||
"prepublishOnly": "npm run tsc"
|
||||
},
|
||||
@@ -59,14 +55,14 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pnpm/logger": "^1.0.0",
|
||||
"@types/nock": "^9.1.1",
|
||||
"@types/tape": "^4.2.31",
|
||||
"@types/tempy": "^0.1.0",
|
||||
"mos": "^2.0.0-alpha.3",
|
||||
"mos-plugin-readme": "^1.0.4",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"nock": "^9.1.6",
|
||||
"package-preview": "^1.0.1",
|
||||
"path-exists": "^3.0.0",
|
||||
"pnpm-registry-mock": "^1.18.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"tape": "^4.8.0",
|
||||
"tempy": "^0.2.1",
|
||||
|
||||
1434
shrinkwrap.yaml
1434
shrinkwrap.yaml
File diff suppressed because it is too large
Load Diff
368
test/index.ts
368
test/index.ts
@@ -1,23 +1,21 @@
|
||||
import test = require('tape')
|
||||
import createResolveFromNpm from '@pnpm/npm-resolver'
|
||||
import tempy = require('tempy')
|
||||
import {addDistTag} from 'pnpm-registry-mock'
|
||||
import nock = require('nock')
|
||||
import path = require('path')
|
||||
import exists = require('path-exists')
|
||||
import loadJsonFile = require('load-json-file')
|
||||
|
||||
const registry = 'http://localhost:4873/'
|
||||
const metaCache = new Map()
|
||||
const isPositiveMeta = loadJsonFile.sync(path.join(__dirname, 'meta', 'is-positive.json'))
|
||||
const sindresorhusIsMeta = loadJsonFile.sync(path.join(__dirname, 'meta', 'sindresorhus-is.json'))
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache,
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
|
||||
test('waiting for verdaccio to startup', t => setTimeout(() => t.end(), 1000))
|
||||
const registry = 'https://registry.npmjs.org/'
|
||||
|
||||
test('resolveFromNpm()', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const store = tempy.directory()
|
||||
const resolve = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
@@ -28,12 +26,12 @@ test('resolveFromNpm()', async t => {
|
||||
registry,
|
||||
})
|
||||
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.latest!.split('.').length, 3)
|
||||
t.deepEqual(resolveResult!.resolution, {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
registry,
|
||||
tarball: 'http://localhost:4873/is-positive/-/is-positive-1.0.0.tgz',
|
||||
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
})
|
||||
t.ok(resolveResult!.package)
|
||||
t.ok(resolveResult!.package!.name, 'is-positive')
|
||||
@@ -51,6 +49,10 @@ test('resolveFromNpm()', async t => {
|
||||
})
|
||||
|
||||
test('dry run', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const store = tempy.directory()
|
||||
const resolve = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
@@ -62,12 +64,12 @@ test('dry run', async t => {
|
||||
registry,
|
||||
})
|
||||
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.latest!.split('.').length, 3)
|
||||
t.deepEqual(resolveResult!.resolution, {
|
||||
integrity: 'sha1-iACYVrZKLx632LsBeUGEJK4EUss=',
|
||||
integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==',
|
||||
registry,
|
||||
tarball: 'http://localhost:4873/is-positive/-/is-positive-1.0.0.tgz',
|
||||
tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
})
|
||||
t.ok(resolveResult!.package)
|
||||
t.ok(resolveResult!.package!.name, 'is-positive')
|
||||
@@ -82,216 +84,344 @@ test('dry run', async t => {
|
||||
})
|
||||
|
||||
test('can resolve aliased dependency', async t => {
|
||||
metaCache.clear()
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({alias: 'positive', pref: 'npm:is-positive@1.0.0'}, {
|
||||
registry,
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('can resolve aliased scoped dependency', async t => {
|
||||
metaCache.clear()
|
||||
nock(registry)
|
||||
.get('/@sindresorhus%2Fis')
|
||||
.reply(200, sindresorhusIsMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({alias: 'is', pref: 'npm:@sindresorhus/is@0.6.0'}, {
|
||||
registry,
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/@sindresorhus/is/0.6.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/@sindresorhus/is/0.6.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('can resolve package with version prefixed with v', async t => {
|
||||
metaCache.clear()
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({alias: 'is-positive', pref: 'v1.0.0'}, {
|
||||
registry,
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('can resolve package version loosely', async t => {
|
||||
metaCache.clear()
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({alias: 'is-positive', pref: '= 1.0.0'}, {
|
||||
registry,
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("resolves to latest if it's inside the wanted range. Even if there are newer versions available inside the range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.0.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '3.0.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
})
|
||||
|
||||
// 1.1.0 is available but latest is 1.0.0, so preferring it
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.0.0')
|
||||
// 3.1.0 is available but latest is 3.0.0, so preferring it
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("resolves to latest if it's inside the preferred range. Even if there are newer versions available inside the preferred range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.0.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '3.0.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'range', selector: '^1.0.0'},
|
||||
'is-positive': {type: 'range', selector: '^3.0.0'},
|
||||
},
|
||||
})
|
||||
|
||||
// 1.1.0 is available but latest is 1.0.0, so preferring it
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.0.0')
|
||||
// 3.1.0 is available but latest is 3.0.0, so preferring it
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("resolve using the wanted range, when it doesn't intersect with the preferred range. Even if the preferred range contains the latest version", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '2.0.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '2.0.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'range', selector: '^2.0.0'},
|
||||
'is-positive': {type: 'range', selector: '^2.0.0'},
|
||||
},
|
||||
})
|
||||
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.3.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("use the preferred version if it's inside the wanted range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.1.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '3.1.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'version', selector: '1.0.0'},
|
||||
'is-positive': {type: 'version', selector: '3.0.0'},
|
||||
},
|
||||
})
|
||||
|
||||
// 1.1.0 is the latest but we prefer the 1.0.0
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.0.0')
|
||||
// 3.1.0 is the latest but we prefer the 3.0.0
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("ignore the preferred version if it's not inside the wanted range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.1.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '3.1.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'version', selector: '2.0.0'},
|
||||
'is-positive': {type: 'version', selector: '2.0.0'},
|
||||
},
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.1.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('use the preferred range if it intersects with the wanted range', async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.0.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '1.0.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '>=1.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'range', selector: '^1.1.0'},
|
||||
'is-positive': {type: 'range', selector: '^3.0.0'},
|
||||
},
|
||||
})
|
||||
|
||||
// 1.0.0 is the latest but we prefer a version that is also in the preferred range
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.3.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("ignore the preferred range if it doesn't intersect with the wanted range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.1.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': { latest: '3.1.0' },
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'range', selector: '^2.0.0'},
|
||||
'is-positive': {type: 'range', selector: '^2.0.0'},
|
||||
},
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.1.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("use the preferred dist-tag if it's inside the wanted range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.1.0', distTag: 'latest'})
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.0.0', distTag: 'stable'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': {
|
||||
latest: '3.1.0',
|
||||
stable: '3.0.0',
|
||||
},
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'tag', selector: 'stable'},
|
||||
'is-positive': {type: 'tag', selector: 'stable'},
|
||||
},
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("ignore the preferred dist-tag if it's not inside the wanted range", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.1.0', distTag: 'latest'})
|
||||
await addDistTag({package: 'pnpm-foo', version: '2.0.0', distTag: 'stable'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': {
|
||||
latest: '3.1.0',
|
||||
stable: '2.0.0',
|
||||
},
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '^1.0.0',
|
||||
alias: 'is-positive',
|
||||
pref: '^3.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'tag', selector: 'stable'},
|
||||
'is-positive': {type: 'tag', selector: 'stable'},
|
||||
},
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.1.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("prefer a version that is both inside the wanted and preferred ranges. Even if it's not the latest of any of them", async t => {
|
||||
metaCache.clear()
|
||||
await addDistTag({package: 'pnpm-foo', version: '1.2.0', distTag: 'latest'})
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, {
|
||||
...isPositiveMeta,
|
||||
'dist-tags': {
|
||||
latest: '3.0.0',
|
||||
},
|
||||
})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
const resolveResult = await resolveFromNpm({
|
||||
alias: 'pnpm-foo',
|
||||
pref: '1.1.0 || 1.3.0',
|
||||
alias: 'is-positive',
|
||||
pref: '1.0.0 || 2.0.0',
|
||||
}, {
|
||||
registry,
|
||||
preferredVersions: {
|
||||
'pnpm-foo': {type: 'range', selector: '1.1.0 || 1.2.0'},
|
||||
'is-positive': {type: 'range', selector: '1.0.0 || 3.0.0'},
|
||||
},
|
||||
})
|
||||
t.equal(resolveResult!.id, 'localhost+4873/pnpm-foo/1.1.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
@@ -313,6 +443,10 @@ test('offline resolution fails when package meta not found in the store', async
|
||||
})
|
||||
|
||||
test('offline resolution succeeds when package meta is found in the store', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const store = tempy.directory()
|
||||
|
||||
{
|
||||
@@ -336,27 +470,46 @@ test('offline resolution succeeds when package meta is found in the store', asyn
|
||||
})
|
||||
|
||||
const resolveResult = await resolve({ alias: 'is-positive', pref: '1.0.0' }, { registry })
|
||||
t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0')
|
||||
t.equal(resolveResult!.id, 'registry.npmjs.org/is-positive/1.0.0')
|
||||
}
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('error is thrown when package is not found in the registry', async t => {
|
||||
const notExistingPackage = 'foo'
|
||||
|
||||
nock(registry)
|
||||
.get(`/${notExistingPackage}`)
|
||||
.reply(404, {})
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
try {
|
||||
const notExistingPackage = 'sndof240jg34g-kwesdgk'
|
||||
await resolveFromNpm({ alias: notExistingPackage, pref: '1.0.0' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
} catch (err) {
|
||||
t.equal(err.message, '404 Not Found: sndof240jg34g-kwesdgk')
|
||||
t.equal(err['package'], 'sndof240jg34g-kwesdgk')
|
||||
t.equal(err.message, `404 Not Found: ${notExistingPackage}`)
|
||||
t.equal(err['package'], notExistingPackage)
|
||||
t.equal(err['code'], 'E404')
|
||||
t.equal(err['uri'], 'http://localhost:4873/sndof240jg34g-kwesdgk')
|
||||
t.equal(err['uri'], `${registry}${notExistingPackage}`)
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
test('error is thrown when there is no package found for the requested version', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
try {
|
||||
await resolveFromNpm({ alias: 'is-positive', pref: '1000.0.0' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
@@ -367,6 +520,15 @@ test('error is thrown when there is no package found for the requested version',
|
||||
})
|
||||
|
||||
test('error is thrown when package needs authorization', async t => {
|
||||
nock(registry)
|
||||
.get('/needs-auth')
|
||||
.reply(403)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
try {
|
||||
await resolveFromNpm({ alias: 'needs-auth', pref: '*' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
@@ -374,12 +536,21 @@ test('error is thrown when package needs authorization', async t => {
|
||||
t.equal(err.message, '403 Forbidden: needs-auth')
|
||||
t.equal(err['package'], 'needs-auth')
|
||||
t.equal(err['code'], 'E403')
|
||||
t.equal(err['uri'], 'http://localhost:4873/needs-auth')
|
||||
t.equal(err['uri'], `${registry}needs-auth`)
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
test('error is thrown when there is no package found for the requested range', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
try {
|
||||
await resolveFromNpm({ alias: 'is-positive', pref: '^1000.0.0' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
@@ -390,6 +561,15 @@ test('error is thrown when there is no package found for the requested range', a
|
||||
})
|
||||
|
||||
test('error is thrown when there is no package found for the requested tag', async t => {
|
||||
nock(registry)
|
||||
.get('/is-positive')
|
||||
.reply(200, isPositiveMeta)
|
||||
|
||||
const resolveFromNpm = createResolveFromNpm({
|
||||
metaCache: new Map(),
|
||||
store: tempy.directory(),
|
||||
rawNpmConfig: { registry },
|
||||
})
|
||||
try {
|
||||
await resolveFromNpm({ alias: 'is-positive', pref: 'unknown-tag' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
|
||||
78
test/meta/is-positive.json
Normal file
78
test/meta/is-positive.json
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"versions": {
|
||||
"1.0.0": {
|
||||
"name": "is-positive",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"ava": "^0.0.4"
|
||||
},
|
||||
"_hasShrinkwrap": false,
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==",
|
||||
"shasum": "88009856b64a2f1eb7d8bb0179418424ae0452cb",
|
||||
"tarball": "https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"2.0.0": {
|
||||
"name": "is-positive",
|
||||
"version": "2.0.0",
|
||||
"devDependencies": {
|
||||
"ava": "^0.0.4"
|
||||
},
|
||||
"_hasShrinkwrap": false,
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-K+obMwRFQAMZb54Jia82SjPdOyBQ4UX8DSowwWCVhzwJOnAxZZ7UsAEI8sH2R6GhFI9efNeH3VGgOLPdzkMTaA==",
|
||||
"shasum": "b14f06bd2db810ae6c8b12741d136bfaef0d87bd",
|
||||
"tarball": "https://registry.npmjs.org/is-positive/-/is-positive-2.0.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"3.0.0": {
|
||||
"name": "is-positive",
|
||||
"version": "3.0.0",
|
||||
"devDependencies": {
|
||||
"ava": "^0.0.4"
|
||||
},
|
||||
"_hasShrinkwrap": false,
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-k1fsSAMxK5AjqPB45vXZrojz/UvY+BMSut1nrFBv5MM7uBIrncljDKEElsem5yEkFGxIiRpbCwgaMvny+85DsQ==",
|
||||
"shasum": "8ef0ee22f7ce24f7633f8908030ec48b62acf4a3",
|
||||
"tarball": "https://registry.npmjs.org/is-positive/-/is-positive-3.0.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"3.1.0": {
|
||||
"name": "is-positive",
|
||||
"version": "3.1.0",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"_hasShrinkwrap": false,
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-9Qa5b+9n69IEuxk4FiNcavXqkixb9lD03BLtdTeu2bbORnLZQrw+pR/exiSg7SoODeu08yxS47mdZa9ddodNwQ==",
|
||||
"shasum": "857db584a1ba5d1cb2980527fc3b6c435d37b0fd",
|
||||
"tarball": "https://registry.npmjs.org/is-positive/-/is-positive-3.1.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": "is-positive",
|
||||
"dist-tags": {
|
||||
"latest": "3.1.0"
|
||||
},
|
||||
"modified": "2017-08-17T19:26:00.508Z"
|
||||
}
|
||||
172
test/meta/sindresorhus-is.json
Normal file
172
test/meta/sindresorhus-is.json
Normal file
@@ -0,0 +1,172 @@
|
||||
{
|
||||
"versions": {
|
||||
"0.1.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.1.0",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "d0ff822b2b92e6476b7f52ca0f0289992f47061b",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.1.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.2.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.2.0",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "c7f5e01c8d3372c682e888f73fd72992514c13c9",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.2.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.2.1": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.2.1",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"xo": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "537fe5655c9e6b22313776494abc712f0b327e79",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.2.1.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.3.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.3.0",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"jsdom": "^9.12.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "ae248b274cb9eec2d8c7acdf6a70689126ff7237",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.3.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.4.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.4.0",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"jsdom": "^9.12.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-5WG0MPK5JOCf16GDyP26gmTYI2pMU5eBbiN0bUTb5GzEgBYT7Dj7S7Jjl6dn/pgAXegmACqjD009v5tVFX200g==",
|
||||
"shasum": "45bfece11eb55cac415e65b8de352eb75de1b968",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.4.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.5.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.5.0",
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^2.0.31",
|
||||
"@types/node": "^8.0.47",
|
||||
"ava": "*",
|
||||
"del-cli": "^1.1.0",
|
||||
"jsdom": "^9.12.0",
|
||||
"tslint": "^5.8.0",
|
||||
"tslint-xo": "^0.3.0",
|
||||
"typescript": "^2.6.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-6cNJTqnikB7E8BV8kYgoYCAwMBh3QSCUte3fq56ldWASPxrGteIDJR5kJ+BJ+AaTRTzI073VUFMHlWrhACn+Jg==",
|
||||
"shasum": "5398b9c4f0963c170d0c8d5873709999f82f508c",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.5.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.6.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.6.0",
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^2.0.31",
|
||||
"@types/node": "^8.0.47",
|
||||
"@types/tempy": "^0.1.0",
|
||||
"ava": "*",
|
||||
"del-cli": "^1.1.0",
|
||||
"jsdom": "^9.12.0",
|
||||
"tempy": "^0.2.1",
|
||||
"tslint": "^5.8.0",
|
||||
"tslint-xo": "^0.3.0",
|
||||
"typescript": "^2.6.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "383f456b26bc96c7889f0332079f4358b16c58dc",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.6.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
},
|
||||
"0.7.0": {
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "0.7.0",
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^2.0.31",
|
||||
"@types/node": "^8.0.47",
|
||||
"@types/tempy": "^0.1.0",
|
||||
"ava": "*",
|
||||
"del-cli": "^1.1.0",
|
||||
"jsdom": "^9.12.0",
|
||||
"tempy": "^0.2.1",
|
||||
"tslint": "^5.8.0",
|
||||
"tslint-xo": "^0.3.0",
|
||||
"typescript": "^2.6.1"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow==",
|
||||
"shasum": "9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd",
|
||||
"tarball": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"_hasShrinkwrap": false
|
||||
}
|
||||
},
|
||||
"name": "@sindresorhus/is",
|
||||
"dist-tags": {
|
||||
"latest": "0.7.0"
|
||||
},
|
||||
"modified": "2017-12-11T20:40:22.859Z"
|
||||
}
|
||||
Reference in New Issue
Block a user