summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/init-package-json/test/scope-in-config.js
blob: 1fa83d9c13a2d67413ba7b6163075c02e75fcef6 (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
var fs = require('fs')
var path = require('path')

var rimraf = require('rimraf')
var tap = require('tap')

var init = require('../')

var EXPECT = {
    name: '@scoped/test',
    version: '1.0.0',
    description: '',
    author: '',
    scripts: { test: 'echo \"Error: no test specified\" && exit 1' },
    main: 'basic.js',
    keywords: [],
    license: 'ISC'
}

tap.test('--yes with scope', function (t) {
  init(__dirname, __dirname, { yes: 'yes', scope: '@scoped' }, function (er, data) {
    if (er) throw er

    t.same(EXPECT, data)
    t.end()
  })
})

var json = {
  name: '@already/scoped',
  version: '1.0.0'
}

tap.test('with existing package.json', function (t) {
  fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(json, null, 2))
  init(__dirname, __dirname, { yes: 'yes', scope: '@still' }, function (er, data) {
    if (er) throw er

    t.equal(data.name, '@still/scoped', 'new scope is added, basic name is kept')
    t.end()
  })
})

tap.test('teardown', function (t) {
  rimraf.sync(path.join(__dirname, 'package.json'))
  t.end()
})