-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed dedupe --save documentation and attempted implementation. * Remove some unneeded otplease mocks from test `npm dedupe --save` didn't work in a easy to understand way. It would only update a top level dependency that was duplicated in the tree. Found this out rewriting the dedupe tests to be real. This is not very intuitive and it's best if folks use update or install for saving to package.json.
- Loading branch information
Showing
9 changed files
with
389 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
// Will tag the last entry in versions as latest | ||
// Versions can be an array of versions or an array of package.json | ||
function mockManifest ({ name = 'test-package', versions = ['1.0.0']}) { | ||
versions = versions.map(v => { | ||
if (!v.version) { | ||
return { version: v } | ||
} | ||
return v | ||
}) | ||
const latest = versions.slice(-1)[0] | ||
const manifest = { | ||
_id: `${name}@${latest.version}`, | ||
_rev: '00-testdeadbeef', | ||
name, | ||
description: 'test package mock manifest', | ||
dependencies: {}, | ||
versions: {}, | ||
time: {}, | ||
'dist-tags': { latest: latest.version }, | ||
...latest, | ||
} | ||
for (const v of versions) { | ||
manifest.versions[v.version] = { | ||
_id: `${name}@{v.version}`, | ||
name, | ||
description: 'test package mock manifest', | ||
dependencies: {}, | ||
dist: { | ||
tarball: `https://registry.npmjs.org/${name}/-/${name}-${v.version}.tgz`, | ||
}, | ||
...v, | ||
} | ||
manifest.time[v.version] = new Date() | ||
} | ||
|
||
return manifest | ||
} | ||
module.exports = mockManifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Mock registry class | ||
* | ||
* This should end up as the centralized place where we generate test fixtures | ||
* for tests against any registry data. | ||
*/ | ||
const pacote = require('pacote') | ||
class MockRegistry { | ||
|
||
#tap | ||
#nock | ||
#registry | ||
#authorization | ||
|
||
constructor(opts) { | ||
if (!opts.registry) { | ||
throw new Error('mock registry requires a registry value') | ||
} | ||
this.#registry = (new URL(opts.registry)).origin | ||
this.#authorization = opts.authorization | ||
// Required for this.package | ||
this.#tap = opts.tap | ||
} | ||
|
||
get nock() { | ||
if (!this.#nock) { | ||
const tnock = require('./tnock.js') | ||
const reqheaders = {} | ||
if (this.#authorization) { | ||
reqheaders.authorization = `Bearer ${this.#authorization}` | ||
} | ||
this.#nock = tnock(this.#tap, this.#registry, { reqheaders }) | ||
} | ||
return this.#nock | ||
} | ||
|
||
set nock(nock) { | ||
this.#nock = nock | ||
} | ||
|
||
async package({ manifest, times = 1, query, tarballs }) { | ||
let nock = this.nock | ||
if (!nock) { | ||
throw new Error('cannot mock packages without a tap fixture') | ||
} | ||
nock = nock.get(`/${manifest.name}`).times(times) | ||
if (query) { | ||
nock = nock.query(query) | ||
} | ||
nock = nock.reply(200, manifest) | ||
if (tarballs) { | ||
for (const version in manifest.versions) { | ||
const packument = manifest.versions[version] | ||
const dist = new URL(packument.dist.tarball) | ||
const tarball = await pacote.tarball(tarballs[version]) | ||
nock.get(dist.pathname).reply(200, tarball) | ||
} | ||
} | ||
this.nock = nock | ||
} | ||
|
||
//tar contents are all under package/ | ||
// so package/package.json | ||
|
||
tarball({ cwd, files }) { | ||
const tarball = pacote.tarball(cwd) | ||
} | ||
// the last packument in the packuments array will be tagged as latest | ||
manifest({ name = 'test-package', packuments } = {}) { | ||
packuments = this.packuments(packuments, name) | ||
const latest = packuments.slice(-1)[0] | ||
const manifest = { | ||
_id: `${name}@${latest.version}`, | ||
_rev: '00-testdeadbeef', | ||
name, | ||
description: 'test package mock manifest', | ||
dependencies: {}, | ||
versions: {}, | ||
time: {}, | ||
'dist-tags': { latest: latest.version }, | ||
...latest, | ||
} | ||
|
||
for (const packument of packuments) { | ||
manifest.versions[packument.version] = { | ||
_id: `${name}@${packument.version}`, | ||
name, | ||
description: 'test package mock manifest', | ||
dependencies: {}, | ||
dist: { | ||
tarball: `${this.#registry}/${name}/-/${name}-${packument.version}.tgz`, | ||
}, | ||
...packument, | ||
} | ||
manifest.time[packument.version] = new Date() | ||
} | ||
|
||
return manifest | ||
} | ||
|
||
packuments(packuments = ['1.0.0'], name) { | ||
return packuments.map(p => this.packument(p, name)) | ||
} | ||
|
||
// Generate packument from shorthand | ||
packument(packument, name = 'test-package') { | ||
if (!packument.version) { | ||
packument = { version: packument } | ||
} | ||
return { | ||
name, | ||
version: '1.0.0', | ||
description: 'mocked test package', | ||
dependencies: {}, | ||
...packument | ||
} | ||
} | ||
} | ||
|
||
module.exports = MockRegistry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.