NodeJS 和 supertest:使用 npm 命令开始测试
NodeJS and supertest : start tests with npm command
我用supertest。我想启动测试目录中的所有测试。
我的 /tests/tests.js 文件:
var request = require('supertest');
var app = require('express.io')();
//add good url with http:// and redirection
request(app)
.post('/add/')
.expect(201)
.send({url: 'http://www.google.fr'})
.end(function(err, res){
console.log(res.body.url);
if (err) throw err;
request(app)
.get('/redirect/' + res.body.url.generatedid)
.expect(302)
.end(function(err, res){
if (err) throw err;
});
});
//add good url with www. and redirection
request(app)
.post('/add/')
.expect(201)
.send({url: 'www.google.com'})
.end(function(err, res){
if (err) throw err;
request(app)
.get('/redirect/' + res.body.url.generatedid)
.expect(302)
.end(function(err, res){
if (err) throw err;
});
});
我想使用 npm 命令启动:npm 运行 测试。
我更改了 package.json 文件。
{
"name": "UrlShortener",
"version": "0.0.1",
"description": "Licence pro Web JS project",
"main": "index.js",
"scripts": {
"start": "node index",
"release" : "npm install",
"tests" : "supertest tests/*.js",
"dev" : "DEBUG=feedback supervisor index"
},
"dependencies": {
"express.io": "^1.1.13",
"mongoose": "^3.8.21",
"nunjucks": "^1.1.0",
"short-id": "0.1.0-1",
"socket.io": "^1.2.1",
"validator": "^3.27.0"
},
"devDependencies": {
"supertest": "^0.15.0"
},
"engines": {
"node": "0.10.x"
}
}
npm 运行 开始工作但是当我尝试 npm 运行 测试时我有:
> UrlShortener@0.0.1 tests c:\Users\Damien\Desktop\Nouveau dossier\urlshortener
> supertest tests/*.js
'supertest' n'est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
npm ERR! UrlShortener@0.0.1 tests: `supertest tests/*.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the UrlShortener@0.0.1 tests script.
npm ERR! This is most likely a problem with the UrlShortener package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! supertest tests/*.js
npm ERR! You can get their info via:
npm ERR! npm owner ls UrlShortener
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "d:\NodeJS\node.exe" "d:\NodeJS\node_modules\npm\bin\np
-cli.js" "run" "tests"
npm ERR! cwd c:\Users\Damien\Desktop\Nouveau dossier\urlshortener
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\Users\Damien\Desktop\Nouveau dossier\urlshortener\npm-debug.log
npm ERR! not ok code 0
如何使用 npm 命令启动我的测试(超级测试)?
supertest
软件包不包含可执行脚本。将 package.json
中的 scripts.tests
替换为:
"scripts": {
"tests" : "node tests/tests.js"
}
您可以通过要求在 tests.js
中指定哪些测试文件应该是 运行。
我用supertest。我想启动测试目录中的所有测试。
我的 /tests/tests.js 文件:
var request = require('supertest');
var app = require('express.io')();
//add good url with http:// and redirection
request(app)
.post('/add/')
.expect(201)
.send({url: 'http://www.google.fr'})
.end(function(err, res){
console.log(res.body.url);
if (err) throw err;
request(app)
.get('/redirect/' + res.body.url.generatedid)
.expect(302)
.end(function(err, res){
if (err) throw err;
});
});
//add good url with www. and redirection
request(app)
.post('/add/')
.expect(201)
.send({url: 'www.google.com'})
.end(function(err, res){
if (err) throw err;
request(app)
.get('/redirect/' + res.body.url.generatedid)
.expect(302)
.end(function(err, res){
if (err) throw err;
});
});
我想使用 npm 命令启动:npm 运行 测试。
我更改了 package.json 文件。
{
"name": "UrlShortener",
"version": "0.0.1",
"description": "Licence pro Web JS project",
"main": "index.js",
"scripts": {
"start": "node index",
"release" : "npm install",
"tests" : "supertest tests/*.js",
"dev" : "DEBUG=feedback supervisor index"
},
"dependencies": {
"express.io": "^1.1.13",
"mongoose": "^3.8.21",
"nunjucks": "^1.1.0",
"short-id": "0.1.0-1",
"socket.io": "^1.2.1",
"validator": "^3.27.0"
},
"devDependencies": {
"supertest": "^0.15.0"
},
"engines": {
"node": "0.10.x"
}
}
npm 运行 开始工作但是当我尝试 npm 运行 测试时我有:
> UrlShortener@0.0.1 tests c:\Users\Damien\Desktop\Nouveau dossier\urlshortener
> supertest tests/*.js
'supertest' n'est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
npm ERR! UrlShortener@0.0.1 tests: `supertest tests/*.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the UrlShortener@0.0.1 tests script.
npm ERR! This is most likely a problem with the UrlShortener package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! supertest tests/*.js
npm ERR! You can get their info via:
npm ERR! npm owner ls UrlShortener
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "d:\NodeJS\node.exe" "d:\NodeJS\node_modules\npm\bin\np
-cli.js" "run" "tests"
npm ERR! cwd c:\Users\Damien\Desktop\Nouveau dossier\urlshortener
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\Users\Damien\Desktop\Nouveau dossier\urlshortener\npm-debug.log
npm ERR! not ok code 0
如何使用 npm 命令启动我的测试(超级测试)?
supertest
软件包不包含可执行脚本。将 package.json
中的 scripts.tests
替换为:
"scripts": {
"tests" : "node tests/tests.js"
}
您可以通过要求在 tests.js
中指定哪些测试文件应该是 运行。