1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var rimraf = require('rimraf')
5 var path = require('path')
6 var mr = require('npm-registry-mock')
7 var osenv = require('osenv')
8 var mkdirp = require('mkdirp')
9 var fs = require('graceful-fs')
11 var pkg = path.resolve(__dirname, 'outdated-local')
12 var pkgLocal = path.resolve(pkg, 'local-module')
13 var pkgScopedLocal = path.resolve(pkg, 'another-local-module')
14 var pkgLocalUnderscore = path.resolve(pkg, 'underscore')
15 var pkgLocalOptimist = path.resolve(pkg, 'optimist')
17 var pjParent = JSON.stringify({
18 name: 'outdated-local',
21 'local-module': 'file:local-module', // updated locally, not on repo
22 '@scoped/another-local-module': 'file:another-local-module', // updated locally, scoped, not on repo
23 'underscore': 'file:underscore', // updated locally, updated but lesser version on repo
24 'optimist': 'file:optimist' // updated locally, updated and greater version on repo
28 var pjLocal = JSON.stringify({
33 var pjLocalBumped = JSON.stringify({
38 var pjScopedLocal = JSON.stringify({
39 name: '@scoped/another-local-module',
43 var pjScopedLocalBumped = JSON.stringify({
44 name: '@scoped/another-local-module',
48 var pjLocalUnderscore = JSON.stringify({
53 var pjLocalUnderscoreBumped = JSON.stringify({
58 var pjLocalOptimist = JSON.stringify({
63 var pjLocalOptimistBumped = JSON.stringify({
69 function mocks (server) {
70 server.get('/local-module')
72 server.get('/@scoped%2fanother-local-module')
76 test('setup', function (t) {
81 test('outdated support local modules', function (t) {
84 mr({ port: common.port, plugin: mocks }, function (err, s) {
85 t.ifError(err, 'mock registry started without problems')
87 function verify (actual, expected) {
88 for (var i = 0; i < expected.length; i++) {
89 var current = expected[i]
92 for (var j = 0; j < actual.length; j++) {
93 var target = actual[j]
96 for (k = 0; k < current.length; k++) {
97 if (current[k] !== target[k]) break
99 if (k === current.length) found = true
102 if (!found) return false
112 registry: common.registry
115 npm.install('.', function (err) {
116 t.ifError(err, 'install success')
118 npm.outdated(function (er, d) {
119 t.ifError(er, 'outdated success')
122 path.resolve(__dirname, 'outdated-local'),
130 path.resolve(__dirname, 'outdated-local'),
131 '@scoped/another-local-module',
135 'file:another-local-module'
138 path.resolve(__dirname, 'outdated-local'),
146 path.resolve(__dirname, 'outdated-local'),
153 ]), 'got expected outdated output')
162 test('cleanup', function (t) {
167 function bootstrap () {
169 fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent)
171 mkdirp.sync(pkgLocal)
172 fs.writeFileSync(path.resolve(pkgLocal, 'package.json'), pjLocal)
174 mkdirp.sync(pkgScopedLocal)
175 fs.writeFileSync(path.resolve(pkgScopedLocal, 'package.json'), pjScopedLocal)
177 mkdirp.sync(pkgLocalUnderscore)
178 fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscore)
180 mkdirp.sync(pkgLocalOptimist)
181 fs.writeFileSync(path.resolve(pkgLocalOptimist, 'package.json'), pjLocalOptimist)
184 function bumpLocalModules () {
185 fs.writeFileSync(path.resolve(pkgLocal, 'package.json'), pjLocalBumped)
186 fs.writeFileSync(path.resolve(pkgScopedLocal, 'package.json'), pjScopedLocalBumped)
187 fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscoreBumped)
188 fs.writeFileSync(path.resolve(pkgLocalOptimist, 'package.json'), pjLocalOptimistBumped)
191 function cleanup () {
192 process.chdir(osenv.tmpdir())