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

tree-style.js « need-npm5-update « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b2bf0ce709f4e8711f2ebb420a73b934828792e7 (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
'use strict'
var test = require('tap').test
var path = require('path')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var fs = require('graceful-fs')
var common = require('../common-tap')

var base = path.resolve(__dirname, path.basename(__filename, '.js'))
var modA = path.resolve(base, 'modA')
var modB = path.resolve(base, 'modB')
var modC = path.resolve(base, 'modC')
var testNormal = path.resolve(base, 'testNormal')
var testGlobal = path.resolve(base, 'testGlobal')
var testLegacy = path.resolve(base, 'testLegacy')

var json = {
  'name': 'test-tree-style',
  'version': '1.0.0',
  'dependencies': {
    'modA': modA
  }
}

var modAJson = {
  'name': 'modA',
  'version': '1.0.0',
  'dependencies': {
    'modB': modB
  }
}

var modBJson = {
  'name': 'modB',
  'version': '1.0.0',
  'dependencies': {
    'modC': modC
  }
}

var modCJson = {
  'name': 'modC',
  'version': '1.0.0'
}

function modJoin () {
  var modules = Array.prototype.slice.call(arguments)
  return modules.reduce(function (a, b) {
    return path.resolve(a, 'node_modules', b)
  })
}

function writeJson (mod, data) {
  fs.writeFileSync(path.resolve(mod, 'package.json'), JSON.stringify(data))
}

function setup () {
  cleanup()
  ;[modA, modB, modC, testNormal, testGlobal, testLegacy].forEach(function (mod) {
    mkdirp.sync(mod)
  })
  writeJson(modA, modAJson)
  writeJson(modB, modBJson)
  writeJson(modC, modCJson)
  ;[testNormal, testGlobal, testLegacy].forEach(function (mod) { writeJson(mod, json) })
}

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

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

function exists (t, filepath, msg) {
  try {
    fs.statSync(filepath)
    t.pass(msg)
    return true
  } catch (ex) {
    t.fail(msg, {found: null, wanted: 'exists', compare: 'fs.stat(' + filepath + ')'})
    return false
  }
}

test('tree-style', function (t) {
  t.plan(12)
  common.npm(['install'], {cwd: testNormal}, function (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'normal install; result code')
    t.is(stderr, '', 'normal install; no errors')
    exists(t, modJoin(testNormal, 'modA'), 'normal install; module A')
    exists(t, modJoin(testNormal, 'modB'), 'normal install; module B')
    exists(t, modJoin(testNormal, 'modC'), 'normal install; module C')
  })
  common.npm(['install', '--global-style'], {cwd: testGlobal}, function (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'global-style install; result code')
    t.is(stderr, '', 'global-style install; no errors')
    exists(t, modJoin(testGlobal, 'modA', 'modB'), 'global-style install; module B')
    exists(t, modJoin(testGlobal, 'modA', 'modC'), 'global-style install; module C')
  })
  common.npm(['install', '--legacy-bundling'], {cwd: testLegacy}, function (err, code, stdout, stderr) {
    if (err) throw err
    t.is(code, 0, 'legacy-bundling install; result code')
    t.is(stderr, '', 'legacy-bundling install; no errors')
    exists(t, modJoin(testLegacy, 'modA', 'modB', 'modC'), 'legacy-bundling install; module C')
  })
})

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