registry-url.test.js
2.06 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
var fs = require('fs')
var path = require('path')
var mocha = require('mocha')
var assert = require('assert')
var requireUncached = require('require-uncached')
var npmRcPath = path.join(__dirname, '..', '.npmrc')
var afterEach = mocha.afterEach
var describe = mocha.describe
var it = mocha.it
describe('registry-url', function () {
afterEach(function (done) {
fs.unlink(npmRcPath, function () {
done()
})
})
it('should read global if no local is found', function () {
var getRegistryUrl = requireUncached('../registry-url')
getRegistryUrl()
})
it('should return default registry if no url is given for scope', function (done) {
fs.writeFile(npmRcPath, 'registry=https://registry.npmjs.org/', function (err) {
var getRegistryUrl = requireUncached('../registry-url')
assert(!err, err)
assert.strictEqual(getRegistryUrl('@somescope'), 'https://registry.npmjs.org/')
done()
})
})
it('should return registry url if url is given for scope ', function (done) {
fs.writeFile(npmRcPath, '@somescope:registry=https://some.registry/', function (err) {
var getRegistryUrl = requireUncached('../registry-url')
assert(!err, err)
assert.strictEqual(getRegistryUrl('@somescope'), 'https://some.registry/')
done()
})
})
it('should append trailing slash if not present', function (done) {
fs.writeFile(npmRcPath, '@somescope:registry=https://some.registry', function (err) {
var getRegistryUrl = requireUncached('../registry-url')
assert(!err, err)
assert.strictEqual(getRegistryUrl('@somescope'), 'https://some.registry/')
done()
})
})
it('should return configured global registry if given', function (done) {
var content = [
'registry=http://registry.foobar.eu/',
'@somescope:registry=https://some.url/', ''
].join('\n')
fs.writeFile(npmRcPath, content, function (err) {
var getRegistryUrl = requireUncached('../registry-url')
assert(!err, err)
assert.strictEqual(getRegistryUrl(), 'http://registry.foobar.eu/')
done()
})
})
})