Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKat Marchán <kzm@zkat.tech>2019-02-19 02:02:15 +0300
committerGitHub <noreply@github.com>2019-02-19 02:02:15 +0300
commitb7b54f2d18e2d8d65ec67c850b21ae9f01c60e7e (patch)
treec245e6784f0a5ade3d541f07d169f138d670fd05 /test
parent2ce23baf53b1ce7d11b8efb80c598ddaf9cef9e7 (diff)
install: add support for package aliases (#3)
PR-URL: https://github.com/npm/cli/pull/3 Credit: @zkat Reviewed-By: @aeschright
Diffstat (limited to 'test')
-rw-r--r--test/tap/404-parent.js2
-rw-r--r--test/tap/aliases.js268
-rw-r--r--test/tap/install-actions.js6
3 files changed, 270 insertions, 6 deletions
diff --git a/test/tap/404-parent.js b/test/tap/404-parent.js
index 4321f7d82..67835efc1 100644
--- a/test/tap/404-parent.js
+++ b/test/tap/404-parent.js
@@ -14,7 +14,7 @@ test('404-parent: if parent exists, specify parent in error message', function (
rimraf.sync(path.resolve(pkg, 'node_modules'))
performInstall(function (err) {
t.ok(err instanceof Error, 'error was returned')
- t.ok(err.parent === '404-parent-test', "error's parent set")
+ t.equal(err.parent, '404-parent', "error's parent set")
t.end()
})
})
diff --git a/test/tap/aliases.js b/test/tap/aliases.js
new file mode 100644
index 000000000..19f0b1293
--- /dev/null
+++ b/test/tap/aliases.js
@@ -0,0 +1,268 @@
+'use strict'
+
+const BB = require('bluebird')
+
+const common = require('../common-tap.js')
+const fs = require('graceful-fs')
+const mockTar = require('../util/mock-tarball.js')
+const mr = common.fakeRegistry.compat
+const path = require('path')
+const rimraf = BB.promisify(require('rimraf'))
+const Tacks = require('tacks')
+const { test } = require('tap')
+
+const { Dir, File } = Tacks
+const readdirAsync = BB.promisify(fs.readdir)
+const readFileAsync = BB.promisify(fs.readFile)
+
+const testDir = path.join(__dirname, path.basename(__filename, '.js'))
+
+let server
+test('setup', t => {
+ mr({}, (err, s) => {
+ t.ifError(err, 'registry mocked successfully')
+ server = s
+ t.end()
+ })
+})
+
+test('installs an npm: protocol alias package', t => {
+ const fixture = new Tacks(Dir({
+ 'package.json': File({})
+ }))
+ fixture.create(testDir)
+ const packument = {
+ name: 'foo',
+ 'dist-tags': { latest: '1.2.4' },
+ versions: {
+ '1.2.3': {
+ name: 'foo',
+ version: '1.2.3',
+ dist: {
+ tarball: `${server.registry}/foo/-/foo-1.2.3.tgz`
+ }
+ },
+ '1.2.4': {
+ name: 'foo',
+ version: '1.2.4',
+ dist: {
+ tarball: `${server.registry}/foo/-/foo-1.2.4.tgz`
+ }
+ }
+ }
+ }
+ server.get('/foo').reply(200, packument)
+ return mockTar({
+ 'package.json': JSON.stringify({
+ name: 'foo',
+ version: '1.2.3'
+ })
+ }).then(tarball => {
+ server.get('/foo/-/foo-1.2.3.tgz').reply(200, tarball)
+ server.get('/foo/-/foo-1.2.4.tgz').reply(200, tarball)
+ return common.npm([
+ 'install', 'foo@1.2.3',
+ '--cache', path.join(testDir, 'npmcache'),
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 0)
+ t.comment(stdout)
+ t.comment(stderr)
+ return common.npm([
+ 'install', 'bar@npm:foo@1.2.3',
+ '--cache', path.join(testDir, 'npmcache'),
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 0)
+ t.comment(stdout)
+ t.comment(stderr)
+ t.match(stdout, /\+ foo@1\.2\.3 \(as bar\)/, 'useful message')
+ return readFileAsync(
+ path.join(testDir, 'node_modules', 'bar', 'package.json'),
+ 'utf8'
+ )
+ }).then(JSON.parse).then(pkg => {
+ t.similar(pkg, {
+ name: 'foo',
+ version: '1.2.3'
+ }, 'successfully installed foo as bar in node_modules')
+ return common.npm(['ls', '--json'], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.comment(stdout)
+ t.comment(stderr)
+ t.equal(code, 0, 'ls is clean')
+ t.deepEqual(JSON.parse(stdout), {
+ dependencies: {
+ bar: {
+ version: '1.2.3',
+ from: 'bar@npm:foo@1.2.3',
+ resolved: 'http://localhost:1337/foo/-/foo-1.2.3.tgz'
+ },
+ foo: {
+ version: '1.2.3',
+ from: 'foo@1.2.3',
+ resolved: 'http://localhost:1337/foo/-/foo-1.2.3.tgz'
+ }
+ }
+ }, 'both dependencies listed correctly')
+ return common.npm([
+ 'outdated', '--json',
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 1, 'non-zero because some packages outdated')
+ t.comment(stdout)
+ t.comment(stderr)
+ const parsed = JSON.parse(stdout)
+ t.deepEqual(parsed, {
+ foo: {
+ current: '1.2.3',
+ wanted: '1.2.4',
+ latest: '1.2.4',
+ location: 'node_modules/foo'
+ },
+ bar: {
+ current: 'npm:foo@1.2.3',
+ wanted: 'npm:foo@1.2.4',
+ latest: 'npm:foo@1.2.4',
+ location: 'node_modules/bar'
+ }
+ }, 'both regular and aliased dependency reported')
+ return common.npm([
+ 'update',
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 0, 'update succeeded')
+ t.comment(stdout)
+ t.comment(stderr)
+ return common.npm(['ls', '--json'], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 0, 'ls succeeded')
+ t.comment(stdout)
+ t.comment(stderr)
+ const parsed = JSON.parse(stdout)
+ t.deepEqual(parsed, {
+ dependencies: {
+ bar: {
+ version: '1.2.4',
+ from: 'bar@npm:foo@1.2.4',
+ resolved: 'http://localhost:1337/foo/-/foo-1.2.4.tgz'
+ },
+ foo: {
+ version: '1.2.4',
+ from: 'foo@1.2.4',
+ resolved: 'http://localhost:1337/foo/-/foo-1.2.4.tgz'
+ }
+ }
+ }, 'ls shows updated packages')
+ return common.npm([
+ 'rm', 'bar',
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.equal(code, 0, 'rm succeeded')
+ t.comment(stdout)
+ t.comment(stderr)
+ t.match(stdout, 'removed 1 package', 'notified of removed package')
+ return readdirAsync(path.join(testDir, 'node_modules'))
+ }).then(dir => {
+ t.deepEqual(dir, ['foo'], 'regular foo left in place')
+ }).then(() => rimraf(testDir))
+})
+
+test('installs a tarball dep as a different name than package.json', t => {
+ return mockTar({
+ 'package.json': JSON.stringify({
+ name: 'foo',
+ version: '1.2.3'
+ })
+ }).then(tarball => {
+ const fixture = new Tacks(Dir({
+ 'package.json': File({}),
+ 'foo.tgz': File(tarball)
+ }))
+ fixture.create(testDir)
+ return common.npm([
+ 'install', 'file:foo.tgz',
+ '--cache', path.join(testDir, 'npmcache'),
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ return common.npm([
+ 'install', 'bar@file:foo.tgz',
+ '--cache', path.join(testDir, 'npmcache'),
+ '--registry', server.registry
+ ], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.comment(stdout)
+ t.comment(stderr)
+ t.match(stdout, /^\+ foo@1\.2\.3 \(as bar\)/, 'useful message')
+ return readFileAsync(
+ path.join(testDir, 'node_modules', 'bar', 'package.json'),
+ 'utf8'
+ )
+ }).then(JSON.parse).then(pkg => {
+ t.similar(pkg, {
+ name: 'foo',
+ version: '1.2.3'
+ }, 'successfully installed foo as bar in node_modules')
+ return common.npm(['ls', '--json'], { cwd: testDir })
+ }).then(([code, stdout, stderr]) => {
+ t.comment(stdout)
+ t.comment(stderr)
+ t.similar(JSON.parse(stdout), {
+ dependencies: {
+ bar: {
+ version: '1.2.3',
+ from: 'file:foo.tgz'
+ },
+ foo: {
+ version: '1.2.3',
+ from: 'file:foo.tgz'
+ }
+ }
+ }, 'both dependencies present')
+ }).then(() => rimraf(testDir))
+})
+
+test('installs a symlink dep as a different name than package.json', t => {
+ const fixture = new Tacks(Dir({
+ 'package.json': File({}),
+ 'foo': Dir({
+ 'package.json': File({
+ name: 'foo',
+ version: '1.2.3'
+ })
+ })
+ }))
+ fixture.create(testDir)
+ return common.npm([
+ 'install', 'bar@file:foo',
+ '--cache', path.join(testDir, 'npmcache'),
+ '--registry', server.registry
+ ], { cwd: testDir }).then(([code, stdout, stderr]) => {
+ t.comment(stdout)
+ t.comment(stderr)
+ t.match(stdout, /^\+ foo@1\.2\.3 \(as bar\)/, 'useful message')
+ return readFileAsync(
+ path.join(testDir, 'node_modules', 'bar', 'package.json'),
+ 'utf8'
+ )
+ }).then(JSON.parse).then(pkg => {
+ t.similar(pkg, {
+ name: 'foo',
+ version: '1.2.3'
+ }, 'successfully installed foo as bar in node_modules')
+ }).then(() => rimraf(testDir))
+})
+
+test('cleanup', t => {
+ server.close()
+ return rimraf(testDir)
+})
+
+test('npm audit supports aliases')
+test('npm audit fix supports aliases')
diff --git a/test/tap/install-actions.js b/test/tap/install-actions.js
index 6ca6e3353..b34be3ad0 100644
--- a/test/tap/install-actions.js
+++ b/test/tap/install-actions.js
@@ -91,6 +91,7 @@ test('->dep:b,->optdep:a->dep:b', function (t) {
moduleA.requires = [moduleB]
var tree = {
+ name: 'tree',
path: '/',
package: {
dependencies: {
@@ -109,13 +110,8 @@ test('->dep:b,->optdep:a->dep:b', function (t) {
moduleA.parent = tree
moduleB.parent = tree
- t.plan(3)
return actions.postinstall('/', moduleA, mockLog).then(() => {
- throw new Error('was not supposed to succeed')
- }, (err) => {
- t.ok(err && err.code === 'ELIFECYCLE', 'Lifecycle failed')
t.ok(moduleA.failed, 'moduleA (optional dep) is marked failed')
t.ok(!moduleB.failed, 'moduleB (direct dep of moduleA) is marked as failed')
- t.end()
})
})