• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const BB = require('bluebird')
4
5const common = require('../common-tap.js')
6const fs = BB.promisifyAll(require('fs'))
7const path = require('path')
8const rimraf = BB.promisify(require('rimraf'))
9const test = require('tap').test
10const Tacks = require('tacks')
11
12const File = Tacks.File
13const Dir = Tacks.Dir
14
15const testDir = common.pkg
16const modAdir = path.resolve(testDir, 'modA')
17const modBdir = path.resolve(testDir, 'modB')
18const modCdir = path.resolve(testDir, 'modC')
19
20test('conflicts in shrinkwrap are auto-resolved on install', (t) => {
21  const fixture = new Tacks(Dir({
22    'package.json': File({
23      name: 'foo',
24      dependencies: {
25        modA: 'file://' + modAdir,
26        modB: 'file://' + modBdir
27      },
28      devDependencies: {
29        modC: 'file://' + modCdir
30      }
31    }),
32    'npm-shrinkwrap.json': File(
33      `
34{
35  "name": "foo",
36  "requires": true,
37  "lockfileVersion": 1,
38  "dependencies": {
39<<` + `<<` + `<<` + `< HEAD
40    "modA": {
41      "version": "file:modA"
42||` + `||` + `||` + `| merged common ancestors
43    "modB": {
44      "version": "file:modB"
45==` + `==` + `==` + `=
46    "modC": {
47      "version": "file:modC",
48      "dev": true
49>>` + `>>` + `>>` + `> branch
50    }
51  }
52}
53`),
54    'modA': Dir({
55      'package.json': File({
56        name: 'modA',
57        version: '1.0.0'
58      })
59    }),
60    'modB': Dir({
61      'package.json': File({
62        name: 'modB',
63        version: '1.0.0'
64      })
65    }),
66    'modC': Dir({
67      'package.json': File({
68        name: 'modC',
69        version: '1.0.0'
70      })
71    })
72  }))
73  fixture.create(testDir)
74  function readJson (file) {
75    return fs.readFileAsync(path.join(testDir, file)).then(JSON.parse)
76  }
77  return BB.fromNode((cb) => {
78    common.npm([
79      'install',
80      '--loglevel', 'warn'
81    ], {cwd: testDir}, (err, code, out, stderr) => {
82      t.comment(stderr)
83      t.match(stderr, /warn.*conflict/gi, 'warns about a conflict')
84      cb(err || (code && new Error('non-zero exit code')) || null, out)
85    })
86  })
87    .then(() => BB.join(
88      readJson('npm-shrinkwrap.json'),
89      readJson('node_modules/modA/package.json'),
90      readJson('node_modules/modB/package.json'),
91      readJson('node_modules/modC/package.json'),
92      (lockfile, A, B, C) => {
93        t.deepEqual(lockfile, {
94          name: 'foo',
95          requires: true,
96          lockfileVersion: 1,
97          dependencies: {
98            modA: {
99              version: 'file:modA'
100            },
101            modB: {
102              version: 'file:modB'
103            },
104            modC: {
105              version: 'file:modC',
106              dev: true
107            }
108          }
109        }, 'resolved lockfile matches expectations')
110        t.equal(A.name, 'modA', 'installed modA')
111        t.equal(B.name, 'modB', 'installed modB')
112        t.equal(C.name, 'modC', 'installed modC')
113      }
114    ))
115})
116
117test('cleanup', () => rimraf(testDir))
118