|
| 1 | +'use strict' |
| 2 | +constfs=require('fs') |
| 3 | +constpath=require('path') |
| 4 | +consttest=require('tap').test |
| 5 | +constmr=require('npm-registry-mock') |
| 6 | +constTacks=require('tacks') |
| 7 | +constFile=Tacks.File |
| 8 | +constDir=Tacks.Dir |
| 9 | +constcommon=require('../common-tap.js') |
| 10 | + |
| 11 | +constbasedir=common.pkg |
| 12 | +consttestdir=path.join(basedir,'testdir') |
| 13 | +constcachedir=common.cache |
| 14 | +constglobaldir=path.join(basedir,'global') |
| 15 | +consttmpdir=path.join(basedir,'tmp') |
| 16 | + |
| 17 | +constpkgPath=path.join(testdir,'package.json') |
| 18 | +constpkgLockPath=path.join(testdir,'package-lock.json') |
| 19 | +constshrinkwrapPath=path.join(testdir,'npm-shrinkwrap.json') |
| 20 | +constCRLFreg=/\r\n|\r|\n/ |
| 21 | + |
| 22 | +constenv=common.newEnv().extend({ |
| 23 | +npm_config_cache: cachedir, |
| 24 | +npm_config_tmp: tmpdir, |
| 25 | +npm_config_prefix: globaldir, |
| 26 | +npm_config_registry: common.registry, |
| 27 | +npm_config_loglevel: 'warn', |
| 28 | +npm_config_format_package_lock: false |
| 29 | +}) |
| 30 | + |
| 31 | +varserver |
| 32 | +varfixture=newTacks(Dir({ |
| 33 | +cache: Dir(), |
| 34 | +global: Dir(), |
| 35 | +tmp: Dir(), |
| 36 | +testdir: Dir({ |
| 37 | +'package.json': File({ |
| 38 | +name: 'install-package-lock-only', |
| 39 | +version: '1.0.0', |
| 40 | +dependencies: { |
| 41 | +mkdirp: '^0.3.4' |
| 42 | +} |
| 43 | +}) |
| 44 | +}) |
| 45 | +})) |
| 46 | + |
| 47 | +functionsetup(){ |
| 48 | +cleanup() |
| 49 | +fixture.create(basedir) |
| 50 | +} |
| 51 | + |
| 52 | +functioncleanup(){ |
| 53 | +fixture.remove(basedir) |
| 54 | +} |
| 55 | + |
| 56 | +test('setup',function(t){ |
| 57 | +mr({port: common.port,throwOnUnmatched: true},function(err,s){ |
| 58 | +if(err)throwerr |
| 59 | +server=s |
| 60 | +t.done() |
| 61 | +}) |
| 62 | +}) |
| 63 | + |
| 64 | +test('package-lock.json unformatted, package.json formatted when config has `format-package-lock: false`',function(t){ |
| 65 | +setup() |
| 66 | +common.npm(['install'],{cwd: testdir, env}).spread((code,stdout,stderr)=>{ |
| 67 | +t.is(code,0,'ok') |
| 68 | +t.ok(fs.existsSync(pkgLockPath),'ensure that package-lock.json was created') |
| 69 | +constpkgLockUtf8=fs.readFileSync(pkgLockPath,'utf-8') |
| 70 | +t.equal(pkgLockUtf8.split(CRLFreg).length,2,'package-lock.json is unformatted') |
| 71 | +constpkgUtf8=fs.readFileSync(pkgPath,'utf-8') |
| 72 | +t.notEqual(pkgUtf8.split(CRLFreg).length,2,'package.json is formatted') |
| 73 | +t.done() |
| 74 | +}) |
| 75 | +}) |
| 76 | + |
| 77 | +test('npm-shrinkwrap.json unformatted when config has `format-package-lock: false`',function(t){ |
| 78 | +setup() |
| 79 | +common.npm(['shrinkwrap'],{cwd: testdir, env}).spread((code,stdout,stderr)=>{ |
| 80 | +t.is(code,0,'ok') |
| 81 | +t.ok(fs.existsSync(shrinkwrapPath),'ensure that npm-shrinkwrap.json was created') |
| 82 | +constshrinkwrapUtf8=fs.readFileSync(shrinkwrapPath,'utf-8') |
| 83 | +t.equal(shrinkwrapUtf8.split(CRLFreg).length,2,'npm-shrinkwrap.json is unformatted') |
| 84 | +t.done() |
| 85 | +}) |
| 86 | +}) |
| 87 | + |
| 88 | +test('package-lock.json and package.json formatted when config has `format-package-lock: true`',function(t){ |
| 89 | +setup() |
| 90 | +common.npm(['install'],{cwd: testdir}).spread((code,stdout,stderr)=>{ |
| 91 | +t.is(code,0,'ok') |
| 92 | +t.ok(fs.existsSync(pkgLockPath),'ensure that package-lock.json was created') |
| 93 | +constpkgLockUtf8=fs.readFileSync(pkgLockPath,'utf-8') |
| 94 | +t.notEqual(pkgLockUtf8.split(CRLFreg).length,2,'package-lock.json is formatted') |
| 95 | +constpkgUtf8=fs.readFileSync(pkgPath,'utf-8') |
| 96 | +t.notEqual(pkgUtf8.split(CRLFreg).length,2,'package.json is formatted') |
| 97 | +t.done() |
| 98 | +}) |
| 99 | +}) |
| 100 | + |
| 101 | +test('npm-shrinkwrap.json formatted when config has `format-package-lock: true`',function(t){ |
| 102 | +setup() |
| 103 | +common.npm(['shrinkwrap'],{cwd: testdir}).spread((code,stdout,stderr)=>{ |
| 104 | +t.is(code,0,'ok') |
| 105 | +t.ok(fs.existsSync(shrinkwrapPath),'ensure that npm-shrinkwrap.json was created') |
| 106 | +constshrinkwrapUtf8=fs.readFileSync(shrinkwrapPath,'utf-8') |
| 107 | +t.notEqual(shrinkwrapUtf8.split(CRLFreg).length,2,'npm-shrinkwrap.json is unformatted') |
| 108 | +t.done() |
| 109 | +}) |
| 110 | +}) |
| 111 | + |
| 112 | +test('cleanup',function(t){ |
| 113 | +server.close() |
| 114 | +cleanup() |
| 115 | +t.done() |
| 116 | +}) |
0 commit comments