-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
81 lines (68 loc) · 2.11 KB
/
Copy pathtest.js
File metadata and controls
81 lines (68 loc) · 2.11 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*!
* get-pkg <https://github.com/jonschlinkert/get-pkg>
*
* Copyright (c) 2015-present, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
const assert = require('assert');
const getPkg = require('./');
describe('get-pkg', function() {
// eslint-disable-next-line no-invalid-this
this.timeout(20000);
it('should fetch a package.json', async () => {
const pkg = await getPkg('generate');
assert.ok(pkg);
assert.equal(pkg.name, 'generate');
});
it('should fetch a package with version', async () => {
const pkg = await getPkg('generate@0.14.0');
assert.ok(pkg);
assert.equal(pkg.name, 'generate');
assert.equal(pkg.version, '0.14.0');
});
it('should fetch scoped packages', async () => {
const pkg = await getPkg('@folder/readdir');
assert.ok(pkg);
assert.equal(pkg.name, '@folder/readdir');
});
it('should fetch scoped, versioned packages', async () => {
const pkg = await getPkg('@folder/readdir@3.1.0');
assert.ok(pkg);
assert.equal(pkg.version, '3.1.0');
assert.equal(pkg.name, '@folder/readdir');
});
it('should support custom hostname URL', async () => {
const pkg = await getPkg('@folder/readdir@3.1.0/package.json', {
hostname: 'https://www.unpkg.com'
});
assert.ok(pkg);
assert.equal(pkg.version, '3.1.0');
assert.equal(pkg.name, '@folder/readdir');
});
it('should work with unpkg without package.json specified', async () => {
const pkg = await getPkg('@folder/readdir@3.1.0', {
hostname: 'https://www.unpkg.com'
});
assert.ok(pkg);
assert.equal(pkg.version, '3.1.0');
assert.equal(pkg.name, '@folder/readdir');
});
it('should fail when version is defined incorrectly', async () => {
try {
await getPkg('@folder/readdir@v3.1.0');
throw new Error('expected an error');
} catch (err) {
assert.ok(err.code);
assert.equal(err.status, 405);
}
});
it('should handle errors', async () => {
try {
await getPkg('fofofofofofoofofof' + Date.now());
} catch (err) {
assert.ok(err);
assert.equal(err.status, 404);
}
});
});