|
| 1 | +'use strict' |
| 2 | +const path = require('path') |
| 3 | +const test = require('tap').test |
| 4 | +const mr = require('npm-registry-mock') |
| 5 | +const Tacks = require('tacks') |
| 6 | +const fs = require('fs') |
| 7 | +const File = Tacks.File |
| 8 | +const Dir = Tacks.Dir |
| 9 | +const common = require('../common-tap.js') |
| 10 | + |
| 11 | +const basedir = path.join(__dirname, path.basename(__filename, '.js')) |
| 12 | +const testdir = path.join(basedir, 'testdir') |
| 13 | +const cachedir = path.join(basedir, 'cache') |
| 14 | +const globaldir = path.join(basedir, 'global') |
| 15 | +const tmpdir = path.join(basedir, 'tmp') |
| 16 | + |
| 17 | +const conf = { |
| 18 | + cwd: testdir, |
| 19 | + stdio: [0, 1, 2], |
| 20 | + env: Object.assign({}, process.env, { |
| 21 | + npm_config_cache: cachedir, |
| 22 | + npm_config_tmp: tmpdir, |
| 23 | + npm_config_prefix: globaldir, |
| 24 | + npm_config_registry: common.registry, |
| 25 | + npm_config_loglevel: 'silly' |
| 26 | + }) |
| 27 | +} |
| 28 | + |
| 29 | +let server |
| 30 | +const fixture = new Tacks(Dir({ |
| 31 | + cache: Dir(), |
| 32 | + global: Dir(), |
| 33 | + tmp: Dir(), |
| 34 | + testdir: Dir({ |
| 35 | + example: Dir({ |
| 36 | + 'package.json': File({ |
| 37 | + name: 'example', |
| 38 | + version: '1.0.0' |
| 39 | + }) |
| 40 | + }), |
| 41 | + 'package.json': File({ |
| 42 | + name: 'save-optional', |
| 43 | + version: '1.0.0' |
| 44 | + }) |
| 45 | + }) |
| 46 | +})) |
| 47 | + |
| 48 | +function setup () { |
| 49 | + cleanup() |
| 50 | + fixture.create(basedir) |
| 51 | +} |
| 52 | + |
| 53 | +function cleanup () { |
| 54 | + fixture.remove(basedir) |
| 55 | +} |
| 56 | + |
| 57 | +test('setup', function (t) { |
| 58 | + setup() |
| 59 | + mr({port: common.port, throwOnUnmatched: true}, function (err, s) { |
| 60 | + if (err) throw err |
| 61 | + server = s |
| 62 | + t.done() |
| 63 | + }) |
| 64 | +}) |
| 65 | + |
| 66 | +test('example', function (t) { |
| 67 | + common.npm(['install', '-O', '--package-lock-only', 'file:example'], conf, function (err, code) { |
| 68 | + if (err) throw err |
| 69 | + t.is(code, 0, 'command ran ok') |
| 70 | + const plock = JSON.parse(fs.readFileSync(`${testdir}/package-lock.json`)) |
| 71 | + t.like(plock, { dependencies: { example: { optional: true } } }, 'optional status saved') |
| 72 | + // your assertions here |
| 73 | + t.done() |
| 74 | + }) |
| 75 | +}) |
| 76 | + |
| 77 | +test('cleanup', function (t) { |
| 78 | + server.close() |
| 79 | + cleanup() |
| 80 | + t.done() |
| 81 | +}) |
0 commit comments