• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2const tar = require('tar')
3const common = require('../common-tap.js')
4const pkg = common.pkg
5const rimraf = require('rimraf')
6const { writeFileSync, statSync, chmodSync } = require('fs')
7const { resolve } = require('path')
8const mkdirp = require('mkdirp')
9
10t.test('setup', t => {
11  mkdirp.sync(resolve(pkg, 'package'))
12  const pj = resolve(pkg, 'package', 'package.json')
13  writeFileSync(pj, JSON.stringify({
14    name: 'foo',
15    version: '1.2.3'
16  }))
17  chmodSync(pj, 0o640)
18  tar.c({
19    sync: true,
20    file: resolve(pkg, 'foo.tgz'),
21    gzip: true,
22    cwd: pkg
23  }, ['package'])
24  writeFileSync(resolve(pkg, 'package.json'), JSON.stringify({
25    name: 'root',
26    version: '1.2.3',
27    dependencies: {
28      foo: 'file:foo.tgz'
29    }
30  }))
31  t.end()
32})
33
34t.test('run install to generate package-lock', t =>
35  common.npm(['install'], { cwd: pkg }).then(([code]) => t.equal(code, 0)))
36
37t.test('remove node_modules', t => rimraf(resolve(pkg, 'node_modules'), t.end))
38
39t.test('run ci and check modes', t =>
40  common.npm(['ci'], { cwd: pkg, stdio: 'inherit' }).then(([code]) => {
41    t.equal(code, 0)
42    const file = resolve(pkg, 'node_modules', 'foo', 'package.json')
43    // bitwise AND against 0o705 so that we can detect whether
44    // the file is world-readable.
45    // Typical unix systems would leave the file 0o644
46    // Travis-ci and some other Linux systems will be 0o664
47    // Windows is 0o666
48    // The regression this is detecting (ie, the default in the tarball)
49    // leaves the file as 0o640.
50    // Bitwise-AND 0o705 should always result in 0o604, and never 0o600
51    const mode = statSync(file).mode & 0o705
52    t.equal(mode, 0o604)
53  }))
54