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