Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Noproxy Test now uses tap.

  • Loading branch information...
commit 5d78ce0b6686d5a0b7b8d9bdd2150203543d4455 1 parent 4561cca
@vvision authored
View
4 package.json
@@ -109,8 +109,6 @@
],
"devDependencies": {
"express": "2.5.9",
- "mocha": "1.2.0",
- "chai": "1.0.4",
"ronn": "~0.3.6",
"tap": "~0.2.5"
},
@@ -119,7 +117,7 @@
"npm": "1"
},
"scripts": {
- "test": "node ./test/run.js && tap test/tap/*.js && mocha test/mocha/no_proxy_test.js -t 5000",
+ "test": "node ./test/run.js && tap test/tap/*.js && tap test/tap/no_proxy/no_proxy_test.js",
"prepublish": "npm prune ; rm -rf test/*/*/node_modules ; make -j4 doc",
"dumpconf": "env | grep npm | sort | uniq",
"echo": "node bin/npm-cli.js"
View
251 test/mocha/no_proxy_test.js
@@ -1,251 +0,0 @@
-var express = require('express')
- , server = express.createServer()
- , proxy = express.createServer()
- , assert = require('chai').assert
- , request = require('request')
- , fs = require("graceful-fs")
- , spawn = require('child_process').spawn
- , npm = require.resolve('../../bin/npm-cli.js')
- , node = process.execPath
- , noProxySave = ''
- , proxySave = ''
-
-
-describe('No-Proxy Tests', function () {
- before(function (done) {
- //Save proxy configuration
- var getProxy = spawn(node, [npm, 'config', 'get', 'proxy']
- , ['ignore', 'stream', 'ignore'])
- getProxy.stdout.on('data', function (data) {
- proxySave = data.toString().trim()
- })
-
- getProxy.on('exit', function (code) {
- done()
- })
- })
-
- before(function (done) {
- //Save noproxy configuration
- var getNoProxy = spawn(node, [npm, 'config', 'get', 'noproxy']
- , ['ignore', 'stream', 'ignore'])
- getNoProxy.stdout.on('data', function (data) {
- noProxySave = data.toString().trim()
- })
-
- getNoProxy.on('exit', function (code) {
- done()
- })
- })
-
- before(function (done) {
- //Set up the server
- server.use(express.logger())
- server.use(express.bodyParser())
- server.use(server.router)
- server.use(express.static('./public'))
-
- //Without Proxy, send file no-proxy.tar.gz back
- server.get('/test', function (req, res) {
- res.sendfile('noproxy.tar.gz')
- })
-
- //With Proxy, send file proxy.tar.gz back
- server.get('/test2', function (req, res) {
- res.sendfile('proxy.tar.gz')
- })
-
- server.listen(80, 'localhost', function () {
- console.log('server running...')
- done()
- })
- })
-
- before(function (done) {
- //Set up the proxy
- proxy.use(express.logger())
- proxy.use(express.bodyParser())
- proxy.use(proxy.router)
- proxy.use(express.static('./public'))
-
- //Redirect all req
- proxy.all('/*', function (req, res) {
- var url = 'http://localhost:80/test2'
- var x = request(url)
- req.pipe(x)
- x.pipe(res)
- })
-
- proxy.listen(8080, 'localhost', function () {
- console.log('proxy running...')
- done()
- })
- })
-
- before(function (done) {
- //Set proxy configuration
- var setProxy = spawn(node
- , [npm, 'config', 'set', 'proxy=http://localhost:8080']
- , { stdio: 'ignore' })
-
- setProxy.on('exit', function (code) {
- done()
- })
- })
-
- after(function (done) {
- server.close()
- server.on('close', function (){
- console.log('Server closed!')
- done()
- })
- })
-
- after(function (done) {
- proxy.close()
- proxy.on('close', function (){
- console.log('Proxy closed!')
- done()
- })
- })
-
- after(function (done) {
- //Set proxy configuration back
- var set = spawn(node, [npm, 'config', 'set', 'proxy='+proxySave]
- , { stdio: 'ignore' })
- set.on('exit', function (code) {
- done()
- })
- })
-
- after(function (done) {
- //Set noproxy configuration back
- var set = spawn(node, [npm, 'config', 'set', 'noproxy='+noProxySave]
- , { stdio: 'ignore' })
- set.on('exit', function (code) {
- done()
- })
- })
-
- it('Checking the route for server and proxy', function (done) {
- request.get("http://localhost:80/test", function (err, res, body) {
- assert.equal(res.statusCode, 200)
- })
- request.get("http://localhost:80/test2", function (err, res, body) {
- assert.equal(res.statusCode, 200)
- })
- request.get("http://localhost:8080/test", function (err, res, body) {
- assert.equal(res.statusCode, 200)
- })
- done()
- })
-
- it('Use npm with noproxy', function (done) {
- this.timeout(5000)
- //Set the no-proxy configuration
- var noProxy = spawn(node, [npm, 'config', 'set', 'noproxy=localhost']
- , { stdio: 'ignore' })
- noProxy.on('exit', function (code) {
- //Install from localhost:80/test
- var child = spawn(node, [npm, 'install', 'http://localhost:80/test']
- , { stdio: 'ignore' }) //change ignore with inherit for all output
- child.on('exit', function (code) {
- //console.log('Child process exited with exit code '+code)
- //Let's check if the package directory exists in node_modules
- fs.exists('../../node_modules/test-no-proxy-test', function (exists) {
- assert.equal(exists, true)
- })
- done()
- })
- })
- })
-
- it('Use npm with proxy set and noproxy null', function (done) {
- this.timeout(10000)
- //Set the noproxy configuration to null
- var noProxy = spawn(node, [npm, 'config', 'set', 'noproxy=null']
- , { stdio: 'ignore' })
- noProxy.on('exit', function (code) {
- //Install from localhost:80/test using proxy
- var child = spawn(node, [npm, 'install', 'http://localhost:80/test']
- , { stdio: 'ignore' })
- child.on('exit', function (code) {
- //console.log('Child process exited with exit code '+code)
- //Let's check if the package directory exists in node_modules
- fs.exists('../../node_modules/test-proxy-test', function (exists) {
- assert.equal(exists, true)
- })
- done()
- })
- })
- })
-
-})
-
-describe('Check test directories removal', function () {
- before(function (done) {
- //Delete package that have been installed in node_modules
- var no_proxy = spawn(node, [npm, 'uninstall', 'test-no-proxy-test']
- , { stdio: 'ignore' })
- no_proxy.on('exit', function (code) {
- done()
- })
- })
-
- before(function (done) {
- //Delete package that have been installed in node_modules
- var proxy = spawn(node, [npm, 'uninstall', 'test-proxy-test']
- , { stdio: 'ignore' })
- proxy.on('exit', function (code) {
- done()
- })
- })
-
- it('Check that no_proxy has been removed', function (done) {
- //Just check if the directory has been removed
- fs.exists('../../node_modules/test-no-proxy-test', function (exists) {
- assert.equal(exists, false)
- })
- done()
- })
-
- it('Check that proxy has been removed', function (done) {
- //Just check if directory has been removed
- fs.exists('../../node_modules/test-proxy-test', function (exists) {
- assert.equal(exists, false)
- })
- done()
- })
-})
-
-describe('Check that noproxy and proxy have there initial value', function () {
-
- it('Check noproxy', function (done) {
- var noProxyNow
- var get = spawn(node, [npm, 'config', 'get', 'noproxy']
- , ['ignore', 'stream', 'ignore'])
- get.stdout.on('data', function (data) {
- noProxyNow = data.toString().trim()
- })
-
- get.on('exit', function (code) {
- assert.equal(noProxyNow, noProxySave)
- done()
- })
- })
-
- it('Check proxy', function (done) {
- var proxyNow
- var get = spawn(node, [npm, 'config', 'get', 'proxy']
- , ['ignore', 'stream', 'ignore'])
- get.stdout.on('data', function (data) {
- proxyNow = data.toString().trim()
- })
-
- get.on('exit', function (code) {
- assert.equal(proxyNow, proxySave)
- done()
- })
- })
-
-})
View
1  test/mocha/noproxy-package/README.md
@@ -1 +0,0 @@
-just an npm test
View
BIN  test/mocha/noproxy.tar.gz
Binary file not shown
View
1  test/mocha/proxy-package/README.md
@@ -1 +0,0 @@
-just an npm test
View
BIN  test/mocha/proxy.tar.gz
Binary file not shown
View
203 test/tap/no_proxy/no_proxy_test.js
@@ -0,0 +1,203 @@
+var test = require("tap").test
+ , npm = require("npm")
+ , npmconf = require("npmconf")
+
+ , configDefs = npmconf.defs
+ , shorthands = configDefs.shorthands
+ , types = configDefs.types
+ , nopt = require('nopt')
+
+ , express = require('express')
+ , server = express.createServer()
+ , proxy = express.createServer()
+ , request = require('request')
+ , fs = require('graceful-fs')
+ , spawn = require('child_process').spawn
+ , node = process.execPath
+ , noProxySave = ''
+ , proxySave = ''
+
+var conf = nopt(types, shorthands)
+
+var startServer = function(callback) {
+ //Set up the server
+ server.use(express.logger())
+ server.use(express.bodyParser())
+ server.use(server.router)
+ server.use(express.static('./public'))
+
+ //Without Proxy, send file no-proxy.tar.gz back
+ server.get('/test', function (req, res) {
+ res.sendfile('noproxy.tar.gz')
+ })
+
+ //With Proxy, send file proxy.tar.gz back
+ server.get('/test2', function (req, res) {
+ res.sendfile('proxy.tar.gz')
+ })
+
+ server.listen(80, 'localhost', function () {
+ callback()
+ })
+}
+
+var startProxy = function(callback) {
+ //Set up the proxy
+ proxy.use(express.logger())
+ proxy.use(express.bodyParser())
+ proxy.use(proxy.router)
+ proxy.use(express.static('./public'))
+
+ //Redirect all req
+ proxy.all('/*', function (req, res) {
+ var url = 'http://localhost:80/test2'
+ var x = request(url)
+ req.pipe(x)
+ x.pipe(res)
+ })
+
+ proxy.listen(8080, 'localhost', function () {
+ callback()
+ })
+}
+
+var initialize = function(callback) {
+ npm.load(conf, function (er, npm) {
+ if (er) return errorHandler(er)
+ //Save configuration
+ proxySave = npm.config.get('proxy')
+ noProxySave = npm.config.get('noproxy')
+ //Set proxy configuration
+ npm.config.set('proxy', 'http://localhost:8080')
+ callback()
+ })
+}
+
+var closeServer = function(s) {
+ s.close()
+ s.on('close', function (){
+ console.log('Closed!')
+ })
+}
+
+var restoreConf = function(callback) {
+ //Set configuration back
+ npm.config.set('proxy', proxySave)
+ npm.config.set('noproxy', noProxySave)
+ callback()
+}
+
+test('Initialize', function (t) {
+ initialize(function() {
+ startServer(function() {
+ startProxy(function() {
+ t.end()
+ })
+ })
+ })
+})
+
+test('Checking the route for server and proxy', function(t) {
+ request.get("http://localhost:80/test", function (err, res, body) {
+ t.equal(res.statusCode, 200)
+ request.get("http://localhost:80/test2", function (err, res2, body) {
+ t.equal(res2.statusCode, 200)
+ request.get("http://localhost:8080/test", function (err, res3, body) {
+ t.equal(res3.statusCode, 200)
+ t.end()
+ })
+ })
+ })
+})
+
+test('Use npm with noproxy', function (t) {
+ //Set the no-proxy configuration
+ npm.config.set('noproxy', 'localhost')
+ t.equal('localhost', npm.config.get('noproxy'))
+ //Install from localhost:80/test
+ var child = spawn(node, [npm, 'install', 'http://localhost:80/test']
+ , { stdio: 'ignore' }) //change ignore with inherit for all output
+ child.on('exit', function (code) {
+ //Let's check if the package directory exists in node_modules
+ fs.exists('../../node_modules/test-no-proxy-test', function (exists) {
+ t.equal(exists, true)
+ })
+ t.end()
+ })
+})
+
+test('Use npm with proxy set and noproxy null', function (t) {
+ //Set the noproxy configuration to null
+ npm.config.set('noproxy', 'null')
+ t.equal('null', npm.config.get('noproxy'))
+ //Install from localhost:80/test using proxy
+ var child = spawn(node, [npm, 'install', 'http://localhost:80/test']
+ , { stdio: 'ignore' })
+ child.on('exit', function (code) {
+ //Let's check if the package directory exists in node_modules
+ fs.exists('../../node_modules/test-proxy-test', function (exists) {
+ t.equal(exists, true)
+ })
+ t.end()
+ })
+})
+
+test('Check test directories removal', function (t) {
+ test('Delete package that have been installed in node_modules', function(t) {
+ var no_proxy = spawn(node, [npm, 'uninstall', 'test-no-proxy-test']
+ , { stdio: 'ignore' })
+ no_proxy.on('exit', function (code) {
+ t.end()
+ })
+ })
+
+ test('Delete package that have been installed in node_modules', function(t) {
+ var proxy = spawn(node, [npm, 'uninstall', 'test-proxy-test']
+ , { stdio: 'ignore' })
+ proxy.on('exit', function (code) {
+ t.end()
+ })
+ })
+
+ test('Check that no_proxy has been removed', function (t) {
+ //Just check if the directory has been removed
+ fs.exists('../../node_modules/test-no-proxy-test', function (exists) {
+ t.equal(exists, false)
+ })
+ t.end()
+ })
+
+ test('Check that proxy has been removed', function (t) {
+ //Just check if directory has been removed
+ fs.exists('../../node_modules/test-proxy-test', function (exists) {
+ t.equal(exists, false)
+ })
+ t.end()
+ })
+
+ t.end()
+})
+
+test('End', function(t) {
+ closeServer(server)
+ closeServer(proxy)
+ restoreConf(function() {
+ test('Check that noproxy and proxy have there initial value', function (t) {
+ test('Check noproxy', function (t) {
+ var noProxyNow = npm.config.get('noproxy')
+ t.equal(noProxyNow, noProxySave)
+ t.end()
+ })
+
+ test('Check proxy', function (t) {
+ var proxyNow = npm.config.get('proxy')
+ t.equal(proxyNow, proxySave)
+ t.end()
+ })
+
+ t.end()
+ })
+
+ t.end()
+ })
+})
View
3  test/tap/no_proxy/noproxy-package/README.md
@@ -0,0 +1,3 @@
+Just an npm test.
+Related to noproxy.
+
View
0  test/mocha/noproxy-package/package.json → test/tap/no_proxy/noproxy-package/package.json
File renamed without changes
View
BIN  test/tap/no_proxy/noproxy.tar.gz
Binary file not shown
View
3  test/tap/no_proxy/proxy-package/README.md
@@ -0,0 +1,3 @@
+Just an npm test.
+Related to noproxy.
+
View
2  test/mocha/proxy-package/package.json → test/tap/no_proxy/proxy-package/package.json
@@ -2,6 +2,6 @@
"author": "vvision",
"name": "test-proxy-test",
"description": "Dummy package for no-proxy configuration tests",
- "version": "9.9.9",
+ "version": "7.7.7",
"main": "test"
}
View
BIN  test/tap/no_proxy/proxy.tar.gz
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.