• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap.js')
2var mr = require('npm-registry-mock')
3
4var test = require('tap').test
5var rimraf = require('rimraf')
6var fs = require('fs')
7var path = require('path')
8var fakeBrowser = path.join(common.pkg, '_script.sh')
9var outFile = path.join(common.pkg, '_output')
10var opts = { cwd: common.pkg }
11var mkdirp = require('mkdirp')
12
13common.pendIfWindows('This is trickier to convert without opening new shells')
14
15test('setup', function (t) {
16  mkdirp.sync(common.pkg)
17  var s = '#!/usr/bin/env bash\n' +
18          'echo "$@" > ' + JSON.stringify(common.pkg) + '/_output\n'
19  fs.writeFileSync(fakeBrowser, s, 'ascii')
20  fs.chmodSync(fakeBrowser, '0755')
21  t.pass('made script')
22  t.end()
23})
24
25test('npm repo underscore', function (t) {
26  mr({ port: common.port }, function (er, s) {
27    common.npm([
28      'repo', 'underscore',
29      '--registry=' + common.registry,
30      '--loglevel=silent',
31      '--browser=' + fakeBrowser
32    ], opts, function (err, code, stdout, stderr) {
33      t.ifError(err, 'repo command ran without error')
34      t.equal(code, 0, 'exit ok')
35      var res = fs.readFileSync(outFile, 'ascii')
36      s.close()
37      t.equal(res, 'https://github.com/jashkenas/underscore\n')
38      rimraf.sync(outFile)
39      t.end()
40    })
41  })
42})
43
44test('npm repo underscore --json', function (t) {
45  mr({ port: common.port }, function (er, s) {
46    common.npm([
47      'repo', 'underscore',
48      '--json',
49      '--registry=' + common.registry,
50      '--loglevel=silent',
51      '--no-browser'
52    ], opts, function (err, code, stdout, stderr) {
53      t.ifError(err, 'repo command ran without error')
54      t.equal(code, 0, 'exit ok')
55      t.matchSnapshot(stdout, 'should print json result')
56      s.close()
57      t.end()
58    })
59  })
60})
61
62test('npm repo underscore --no-browser', function (t) {
63  mr({ port: common.port }, function (er, s) {
64    common.npm([
65      'repo', 'underscore',
66      '--no-browser',
67      '--registry=' + common.registry,
68      '--loglevel=silent'
69    ], opts, function (err, code, stdout, stderr) {
70      t.ifError(err, 'repo command ran without error')
71      t.equal(code, 0, 'exit ok')
72      t.matchSnapshot(stdout, 'should print alternative msg')
73      s.close()
74      t.end()
75    })
76  })
77})
78
79test('npm repo optimist - github (https://)', function (t) {
80  mr({ port: common.port }, function (er, s) {
81    common.npm([
82      'repo', 'optimist',
83      '--registry=' + common.registry,
84      '--loglevel=silent',
85      '--browser=' + fakeBrowser
86    ], opts, function (err, code, stdout, stderr) {
87      t.ifError(err, 'repo command ran without error')
88      t.equal(code, 0, 'exit ok')
89      var res = fs.readFileSync(outFile, 'ascii')
90      s.close()
91      t.equal(res, 'https://github.com/substack/node-optimist\n')
92      rimraf.sync(outFile)
93      t.end()
94    })
95  })
96})
97
98test('npm repo npm-test-peer-deps - no repo', function (t) {
99  mr({ port: common.port }, function (er, s) {
100    common.npm([
101      'repo', 'npm-test-peer-deps',
102      '--registry=' + common.registry,
103      '--loglevel=silent',
104      '--browser=' + fakeBrowser
105    ], opts, function (err, code, stdout, stderr) {
106      t.ifError(err, 'repo command ran without error')
107      t.equal(code, 1, 'exit not ok')
108      s.close()
109      t.end()
110    })
111  })
112})
113
114test('npm repo test-repo-url-http - non-github (http://)', function (t) {
115  mr({ port: common.port }, function (er, s) {
116    common.npm([
117      'repo', 'test-repo-url-http',
118      '--registry=' + common.registry,
119      '--loglevel=silent',
120      '--browser=' + fakeBrowser
121    ], opts, function (err, code, stdout, stderr) {
122      t.ifError(err, 'repo command ran without error')
123      t.equal(code, 0, 'exit ok')
124      var res = fs.readFileSync(outFile, 'ascii')
125      s.close()
126      t.equal(res, 'http://gitlab.com/evanlucas/test-repo-url-http\n')
127      rimraf.sync(outFile)
128      t.end()
129    })
130  })
131})
132
133test('npm repo test-repo-url-https - non-github (https://)', function (t) {
134  mr({ port: common.port }, function (er, s) {
135    common.npm([
136      'repo', 'test-repo-url-https',
137      '--registry=' + common.registry,
138      '--loglevel=silent',
139      '--browser=' + fakeBrowser
140    ], opts, function (err, code, stdout, stderr) {
141      t.ifError(err, 'repo command ran without error')
142      t.equal(code, 0, 'exit ok')
143      var res = fs.readFileSync(outFile, 'ascii')
144      s.close()
145      t.equal(res, 'https://gitlab.com/evanlucas/test-repo-url-https\n')
146      rimraf.sync(outFile)
147      t.end()
148    })
149  })
150})
151
152test('npm repo test-repo-url-ssh - non-github (ssh://)', function (t) {
153  mr({ port: common.port }, function (er, s) {
154    common.npm([
155      'repo', 'test-repo-url-ssh',
156      '--registry=' + common.registry,
157      '--loglevel=silent',
158      '--browser=' + fakeBrowser
159    ], opts, function (err, code, stdout, stderr) {
160      t.ifError(err, 'repo command ran without error')
161      t.equal(code, 0, 'exit ok')
162      var res = fs.readFileSync(outFile, 'ascii')
163      s.close()
164      t.equal(res, 'https://gitlab.com/evanlucas/test-repo-url-ssh\n')
165      rimraf.sync(outFile)
166      t.end()
167    })
168  })
169})
170
171test('cleanup', function (t) {
172  fs.unlinkSync(fakeBrowser)
173  t.pass('cleaned up')
174  t.end()
175})
176