This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
spec-from-lock.js
60 lines (49 loc) · 1.68 KB
/
spec-from-lock.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
const sfl = require('../lib/spec-from-lock.js')
const t = require('tap')
const cwd = process.cwd()
const dirname = require('path').dirname(cwd)
t.cleanSnapshot = s => s
.split(cwd).join('{CWD}')
.split(dirname).join('{..}')
.split(/\s+"pathmatch": .*/g).join('\n{pathmatch regexp},')
t.matchSnapshot(sfl('x', {
version: '1.2.3',
integrity: 'integral',
}), 'version and integrity')
t.matchSnapshot(sfl('gitthing', {
version: 'git+ssh://git@github.com/isaacs/abbrev-js#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb',
from: 'github:isaacs/abbrev-js#some-ref',
}), 'git repo with resolved value')
t.matchSnapshot(sfl('legacy', {
from: '1.2.3',
}), 'legacy metadata with "from" and no integrity')
t.matchSnapshot(sfl('x', {
version: 'foo.tgz',
integrity: 'integral',
}), 'version (file) and integrity set')
t.matchSnapshot(sfl('x', {
version: '1.2.3',
from: '^1.2.0',
shasum: 'deadbeef0cafebad',
resolved: 'https://registry.npmjs.org/x/-/x-1.2.3.tgz',
}), 'version and range, no integrity')
t.matchSnapshot(sfl('x', {
version: 'file:x-1.2.3.tgz',
from: 'x-1.2.3.tgz',
}), 'file with from, no integrity')
t.matchSnapshot(sfl('x', {
version: 'file:x-1.2.3.tgz',
resolved: '/path/to/x-1.2.3.tgz',
}), 'file with resolved, no integrity')
t.matchSnapshot(sfl('x', {
version: 'file:x-1.2.3.tgz',
from: 'file:x-1.2.3.tgz',
resolved: '/path/to/x-1.2.3.tgz',
}), 'file with resolved and from')
t.matchSnapshot(sfl('x', {
version: 'file:../some/path',
}), 'directory symlink')
t.matchSnapshot(sfl('really bad and invalid', {
version: 'url:// not even close to a ! valid @ npm @ specifier',
resolved: 'this: is: also: not: valid!',
}), 'completely invalid, return empty object')