Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 0da38b7

Browse filesBrowse files
committed
test: Ensure optional status is saved to lock file
1 parent 3888d20 commit 0da38b7
Copy full SHA for 0da38b7

File tree

Expand file treeCollapse file tree

1 file changed

+81
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+81
-0
lines changed

‎test/tap/save-optional.js

Copy file name to clipboard
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.