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

shrinkwrap-version-match.js « tap « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb4e92550490808a947b7aeda1462fb1845c0f5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict'
var test = require('tap').test
var fs = require('fs')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var path = require('path')
var common = require('../common-tap.js')

var testdir = path.resolve(__dirname, path.basename(__filename, '.js'))
var modAdir = path.resolve(testdir, 'modA')
var modB1dir = path.resolve(testdir, 'modB@1')
var modB2dir = path.resolve(testdir, 'modB@2')
var modCdir = path.resolve(testdir, 'modC')
var testjson = {
  dependencies: {
    modA: 'file://' + modAdir,
    modC: 'file://' + modCdir
  }
}
var testshrinkwrap = {
  dependencies: {
    modA: {
      version: '1.0.0',
      from: 'modA',
      resolved: 'file://' + modAdir
    },
    modB: {
      version: '1.0.0',
      from: 'modB@1',
      resolved: 'file://' + modB1dir
    }
  }
}
var modAjson = {
  name: 'modA',
  version: '1.0.0',
  dependencies: {
    'modB': 'file://' + modB1dir
  }
}
var modCjson = {
  name: 'modC',
  version: '1.0.0',
  dependencies: {
    'modB': 'file://' + modB2dir
  }
}
var modB1json = {
  name: 'modB',
  version: '1.0.0'
}
var modB2json = {
  name: 'modB',
  version: '2.0.0'
}

function writepjson (dir, content) {
  writejson(dir, 'package.json', content)
}
function writejson (dir, file, content) {
  writefile(dir, file, JSON.stringify(content, null, 2))
}
function writefile (dir, file, content) {
  fs.writeFileSync(path.join(dir, file), content)
}

function setup () {
  mkdirp.sync(testdir)
  writepjson(testdir, testjson)
  writejson(testdir, 'npm-shrinkwrap.json', testshrinkwrap)
  mkdirp.sync(modAdir)
  writepjson(modAdir, modAjson)
  mkdirp.sync(modB1dir)
  writepjson(modB1dir, modB1json)
  writefile(modB1dir, 'B1', '')
  mkdirp.sync(modB2dir)
  writepjson(modB2dir, modB2json)
  writefile(modB2dir, 'B2', '')
  mkdirp.sync(modCdir)
  writepjson(modCdir, modCjson)
}

function cleanup () {
  rimraf.sync(testdir)
}

test('setup', function (t) {
  cleanup()
  setup()
  t.end()
})

// Shrinkwraps need to let you override dependency versions specified in
// package.json files.  Indeed, this was already supported, but it was a bit
// to keen on this.  Previously, if you had a dep in your shrinkwrap then
// anything that required that dependency would count as a match, regardless
// of version.

// This test ensures that the broad matching is not done when the matched
// module is not a direct child of the module doing the requiring.

test('bundled', function (t) {
  common.npm(['install'], {cwd: testdir}, function (err, code, out, stderr) {
    t.is(err, null, 'No fatal errors running npm')
    t.is(code, 0, 'npm itself completed ok')
    // Specifically, if B2 exists (or the modB directory under modC at all)
    // that means modC was given its own copy of modB.  Without the patch
    // that went with this test, it wouldn't have been installed because npm
    // would have consider modB@1 to have fulfilled modC's requirement.
    fs.stat(path.join(testdir, 'node_modules', 'modC', 'node_modules', 'modB', 'B2'), function (missing) {
      t.ok(!missing, 'modC got the right version of modB')
      t.end()
    })
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})