tests: remove global dependency on should

fixes #4797
This commit is contained in:
Douglas Christopher Wilson
2022-02-02 01:55:16 -05:00
parent 215f484fb4
commit bd4fdfe5f7
14 changed files with 142 additions and 165 deletions

View File

@@ -1,4 +1,5 @@
var assert = require('assert')
var express = require('../')
, fs = require('fs');
var path = require('path')
@@ -22,16 +23,16 @@ describe('app', function(){
app.render('user.html', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
it('should throw when the callback is missing', function(){
var app = express();
(function(){
assert.throws(function () {
app.engine('.html', null);
}).should.throw('callback function required');
}, /callback function required/)
})
it('should work without leading "."', function(done){
@@ -43,7 +44,7 @@ describe('app', function(){
app.render('user.html', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -58,7 +59,7 @@ describe('app', function(){
app.render('user', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -73,7 +74,7 @@ describe('app', function(){
app.render('user', function(err, str){
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})

View File

@@ -32,8 +32,8 @@ describe('app.parent', function(){
blog.use('/admin', blogAdmin);
assert(!app.parent, 'app.parent');
blog.parent.should.equal(app);
blogAdmin.parent.should.equal(blog);
assert.strictEqual(blog.parent, app)
assert.strictEqual(blogAdmin.parent, blog)
})
})
@@ -48,10 +48,10 @@ describe('app.mountpath', function(){
app.use(fallback);
blog.use('/admin', admin);
admin.mountpath.should.equal('/admin');
app.mountpath.should.equal('/');
blog.mountpath.should.equal('/blog');
fallback.mountpath.should.equal('/');
assert.strictEqual(admin.mountpath, '/admin')
assert.strictEqual(app.mountpath, '/')
assert.strictEqual(blog.mountpath, '/blog')
assert.strictEqual(fallback.mountpath, '/')
})
})
@@ -76,9 +76,9 @@ describe('app.path()', function(){
app.use('/blog', blog);
blog.use('/admin', blogAdmin);
app.path().should.equal('');
blog.path().should.equal('/blog');
blogAdmin.path().should.equal('/blog/admin');
assert.strictEqual(app.path(), '')
assert.strictEqual(blog.path(), '/blog')
assert.strictEqual(blogAdmin.path(), '/blog/admin')
})
})
@@ -86,7 +86,7 @@ describe('in development', function(){
it('should disable "view cache"', function(){
process.env.NODE_ENV = 'development';
var app = express();
app.enabled('view cache').should.be.false()
assert.ok(!app.enabled('view cache'))
process.env.NODE_ENV = 'test';
})
})
@@ -95,7 +95,7 @@ describe('in production', function(){
it('should enable "view cache"', function(){
process.env.NODE_ENV = 'production';
var app = express();
app.enabled('view cache').should.be.true()
assert.ok(app.enabled('view cache'))
process.env.NODE_ENV = 'test';
})
})
@@ -104,7 +104,7 @@ describe('without NODE_ENV', function(){
it('should default to development', function(){
process.env.NODE_ENV = '';
var app = express();
app.get('env').should.equal('development');
assert.strictEqual(app.get('env'), 'development')
process.env.NODE_ENV = 'test';
})
})

View File

@@ -1,16 +1,18 @@
var assert = require('assert')
var express = require('../')
var should = require('should')
describe('app', function(){
describe('.locals(obj)', function(){
it('should merge locals', function(){
var app = express();
Object.keys(app.locals).should.eql(['settings']);
should(Object.keys(app.locals)).eql(['settings'])
app.locals.user = 'tobi';
app.locals.age = 2;
Object.keys(app.locals).should.eql(['settings', 'user', 'age']);
app.locals.user.should.equal('tobi');
app.locals.age.should.equal(2);
should(Object.keys(app.locals)).eql(['settings', 'user', 'age'])
assert.strictEqual(app.locals.user, 'tobi')
assert.strictEqual(app.locals.age, 2)
})
})
@@ -19,8 +21,8 @@ describe('app', function(){
var app = express();
app.set('title', 'House of Manny');
var obj = app.locals.settings;
obj.should.have.property('env', 'test');
obj.should.have.property('title', 'House of Manny');
should(obj).have.property('env', 'test')
should(obj).have.property('title', 'House of Manny')
})
})
})

View File

@@ -1,4 +1,5 @@
var assert = require('assert')
var express = require('../')
, request = require('supertest');
@@ -40,7 +41,7 @@ describe('app', function(){
it('should fail if not given fn', function(){
var app = express();
app.param.bind(app, ':name', 'bob').should.throw();
assert.throws(app.param.bind(app, ':name', 'bob'))
})
})
@@ -57,24 +58,22 @@ describe('app', function(){
app.get('/post/:id', function(req, res){
var id = req.params.id;
id.should.be.a.Number()
res.send('' + id);
res.send((typeof id) + ':' + id)
});
app.get('/user/:uid', function(req, res){
var id = req.params.id;
id.should.be.a.Number()
res.send('' + id);
res.send((typeof id) + ':' + id)
});
request(app)
.get('/user/123')
.expect(200, '123', function (err) {
if (err) return done(err)
request(app)
.get('/post/123')
.expect('123', done);
})
.get('/user/123')
.expect(200, 'number:123', function (err) {
if (err) return done(err)
request(app)
.get('/post/123')
.expect('number:123', done)
})
})
})
@@ -91,13 +90,12 @@ describe('app', function(){
app.get('/user/:id', function(req, res){
var id = req.params.id;
id.should.be.a.Number()
res.send('' + id);
res.send((typeof id) + ':' + id)
});
request(app)
.get('/user/123')
.expect('123', done);
.get('/user/123')
.expect(200, 'number:123', done)
})
it('should only call once per request', function(done) {

View File

@@ -13,7 +13,7 @@ describe('app', function(){
app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -26,7 +26,7 @@ describe('app', function(){
app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -39,7 +39,7 @@ describe('app', function(){
app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -52,7 +52,7 @@ describe('app', function(){
app.render('blog/post', function (err, str) {
if (err) return done(err);
str.should.equal('<h1>blog post</h1>');
assert.strictEqual(str, '<h1>blog post</h1>')
done();
})
})
@@ -72,8 +72,8 @@ describe('app', function(){
app.set('view', View);
app.render('something', function(err, str){
err.should.be.ok()
err.message.should.equal('err!');
assert.ok(err)
assert.strictEqual(err.message, 'err!')
done();
})
})
@@ -113,7 +113,7 @@ describe('app', function(){
app.render('email.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>This is an email</p>');
assert.strictEqual(str, '<p>This is an email</p>')
done();
})
})
@@ -128,7 +128,7 @@ describe('app', function(){
app.render('email', function(err, str){
if (err) return done(err);
str.should.equal('<p>This is an email</p>');
assert.strictEqual(str, '<p>This is an email</p>')
done();
})
})
@@ -143,7 +143,7 @@ describe('app', function(){
app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -161,7 +161,7 @@ describe('app', function(){
app.render('user.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<span>tobi</span>');
assert.strictEqual(str, '<span>tobi</span>')
done();
})
})
@@ -178,7 +178,7 @@ describe('app', function(){
app.render('name.tmpl', function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -219,7 +219,7 @@ describe('app', function(){
app.render('something', function(err, str){
if (err) return done(err);
str.should.equal('abstract engine');
assert.strictEqual(str, 'abstract engine')
done();
})
})
@@ -245,12 +245,12 @@ describe('app', function(){
app.render('something', function(err, str){
if (err) return done(err);
count.should.equal(1);
str.should.equal('abstract engine');
assert.strictEqual(count, 1)
assert.strictEqual(str, 'abstract engine')
app.render('something', function(err, str){
if (err) return done(err);
count.should.equal(2);
str.should.equal('abstract engine');
assert.strictEqual(count, 2)
assert.strictEqual(str, 'abstract engine')
done();
})
})
@@ -275,12 +275,12 @@ describe('app', function(){
app.render('something', function(err, str){
if (err) return done(err);
count.should.equal(1);
str.should.equal('abstract engine');
assert.strictEqual(count, 1)
assert.strictEqual(str, 'abstract engine')
app.render('something', function(err, str){
if (err) return done(err);
count.should.equal(1);
str.should.equal('abstract engine');
assert.strictEqual(count, 1)
assert.strictEqual(str, 'abstract engine')
done();
})
})
@@ -298,7 +298,7 @@ describe('app', function(){
app.render('user.tmpl', { user: user }, function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -311,7 +311,7 @@ describe('app', function(){
app.render('user.tmpl', {}, function (err, str) {
if (err) return done(err);
str.should.equal('<p>tobi</p>');
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
@@ -325,7 +325,7 @@ describe('app', function(){
app.render('user.tmpl', { user: jane }, function (err, str) {
if (err) return done(err);
str.should.equal('<p>jane</p>');
assert.strictEqual(str, '<p>jane</p>')
done();
})
})
@@ -350,12 +350,12 @@ describe('app', function(){
app.render('something', {cache: true}, function(err, str){
if (err) return done(err);
count.should.equal(1);
str.should.equal('abstract engine');
assert.strictEqual(count, 1)
assert.strictEqual(str, 'abstract engine')
app.render('something', {cache: true}, function(err, str){
if (err) return done(err);
count.should.equal(1);
str.should.equal('abstract engine');
assert.strictEqual(count, 1)
assert.strictEqual(str, 'abstract engine')
done();
})
})

View File

@@ -51,7 +51,7 @@ describe('app.router', function(){
it('should reject numbers for app.' + method, function(){
var app = express();
app[method].bind(app, '/', 3).should.throw(/Number/);
assert.throws(app[method].bind(app, '/', 3), /Number/)
})
});
@@ -1102,6 +1102,6 @@ describe('app.router', function(){
it('should be chainable', function(){
var app = express();
app.get('/', function(){}).should.equal(app);
assert.strictEqual(app.get('/', function () {}), app)
})
})

View File

@@ -1,3 +1,5 @@
var assert = require('assert')
var express = require('../')
, request = require('supertest');
@@ -34,20 +36,20 @@ describe('app', function(){
next();
}, function(err, req, res, next){
b = true;
err.message.should.equal('fabricated error');
assert.strictEqual(err.message, 'fabricated error')
next(err);
}, function(err, req, res, next){
c = true;
err.message.should.equal('fabricated error');
assert.strictEqual(err.message, 'fabricated error')
next();
}, function(err, req, res, next){
d = true;
next();
}, function(req, res){
a.should.be.false()
b.should.be.true()
c.should.be.true()
d.should.be.false()
assert.ok(!a)
assert.ok(b)
assert.ok(c)
assert.ok(!d)
res.send(204);
});

View File

@@ -10,7 +10,7 @@ describe('app', function(){
, app = express();
blog.on('mount', function(arg){
arg.should.equal(app);
assert.strictEqual(arg, app)
done();
});
@@ -63,7 +63,7 @@ describe('app', function(){
, app = express();
app.use('/blog', blog);
blog.parent.should.equal(app);
assert.strictEqual(blog.parent, app)
})
it('should support dynamic routes', function(done){
@@ -102,11 +102,11 @@ describe('app', function(){
});
blog.once('mount', function (parent) {
parent.should.equal(app);
assert.strictEqual(parent, app)
cb();
});
other.once('mount', function (parent) {
parent.should.equal(app);
assert.strictEqual(parent, app)
cb();
});

View File

@@ -1,4 +1,5 @@
var assert = require('assert')
var express = require('../')
, request = require('supertest');
@@ -99,7 +100,8 @@ describe('req', function(){
describe('when "query parser" an unknown value', function () {
it('should throw', function () {
createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/);
assert.throws(createApp.bind(null, 'bogus'),
/unknown value.*query parser/)
});
});
})

View File

@@ -8,18 +8,20 @@ describe('req', function(){
var app = express();
app.get('/user/:id/:op?', function(req, res, next){
req.route.path.should.equal('/user/:id/:op?');
res.header('path-1', req.route.path)
next();
});
app.get('/user/:id/edit', function(req, res){
req.route.path.should.equal('/user/:id/edit');
res.header('path-2', req.route.path)
res.end();
});
request(app)
.get('/user/12/edit')
.expect(200, done);
.get('/user/12/edit')
.expect('path-1', '/user/:id/:op?')
.expect('path-2', '/user/:id/edit')
.expect(200, done)
})
})
})

View File

@@ -4,59 +4,38 @@ var express = require('../')
describe('req', function(){
describe('.xhr', function(){
before(function () {
this.app = express()
this.app.get('/', function (req, res) {
res.send(req.xhr)
})
})
it('should return true when X-Requested-With is xmlhttprequest', function(done){
var app = express();
app.use(function(req, res){
req.xhr.should.be.true()
res.end();
});
request(app)
.get('/')
.set('X-Requested-With', 'xmlhttprequest')
.expect(200, done)
request(this.app)
.get('/')
.set('X-Requested-With', 'xmlhttprequest')
.expect(200, 'true', done)
})
it('should case-insensitive', function(done){
var app = express();
app.use(function(req, res){
req.xhr.should.be.true()
res.end();
});
request(app)
.get('/')
.set('X-Requested-With', 'XMLHttpRequest')
.expect(200, done)
request(this.app)
.get('/')
.set('X-Requested-With', 'XMLHttpRequest')
.expect(200, 'true', done)
})
it('should return false otherwise', function(done){
var app = express();
app.use(function(req, res){
req.xhr.should.be.false()
res.end();
});
request(app)
.get('/')
.set('X-Requested-With', 'blahblah')
.expect(200, done)
request(this.app)
.get('/')
.set('X-Requested-With', 'blahblah')
.expect(200, 'false', done)
})
it('should return false when not present', function(done){
var app = express();
app.use(function(req, res){
req.xhr.should.be.false()
res.end();
});
request(app)
.get('/')
.expect(200, done)
request(this.app)
.get('/')
.expect(200, 'false', done)
})
})
})

View File

@@ -1,7 +1,6 @@
var express = require('../')
, request = require('supertest')
, cookie = require('cookie')
, cookieParser = require('cookie-parser')
var merge = require('utils-merge');
@@ -46,12 +45,9 @@ describe('res', function(){
});
request(app)
.get('/')
.end(function(err, res){
var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/'];
res.headers['set-cookie'].should.eql(val);
done();
})
.get('/')
.expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path=/,gender=%3F; Path=/')
.expect(200, done)
})
})
@@ -80,11 +76,9 @@ describe('res', function(){
});
request(app)
.get('/')
.end(function(err, res){
res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT');
done();
})
.get('/')
.expect('Set-Cookie', /name=tobi; Max-Age=1; Path=\/; Expires=/)
.expect(200, done)
})
it('should set max-age', function(done){
@@ -141,13 +135,9 @@ describe('res', function(){
});
request(app)
.get('/')
.end(function(err, res){
var val = res.headers['set-cookie'][0];
val = cookie.parse(val.split('.')[0]);
val.user.should.equal('s:j:{"name":"tobi"}');
done();
})
.get('/')
.expect('Set-Cookie', 'user=s%3Aj%3A%7B%22name%22%3A%22tobi%22%7D.K20xcwmDS%2BPb1rsD95o5Jm5SqWs1KteqdnynnB7jkTE; Path=/')
.expect(200, done)
})
})

View File

@@ -544,7 +544,7 @@ describe('res', function(){
var chunk = !Buffer.isBuffer(body)
? Buffer.from(body, encoding)
: body;
chunk.toString().should.equal('hello, world!');
assert.strictEqual(chunk.toString(), 'hello, world!')
return '"custom"';
});

View File

@@ -1,27 +1,28 @@
var assert = require('assert');
var Buffer = require('safe-buffer').Buffer
var should = require('should')
var utils = require('../lib/utils');
describe('utils.etag(body, encoding)', function(){
it('should support strings', function(){
utils.etag('express!')
.should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
assert.strictEqual(utils.etag('express!'),
'"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
})
it('should support utf8 strings', function(){
utils.etag('express❤', 'utf8')
.should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
assert.strictEqual(utils.etag('express❤', 'utf8'),
'"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
})
it('should support buffer', function(){
utils.etag(Buffer.from('express!'))
.should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
assert.strictEqual(utils.etag(Buffer.from('express!')),
'"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
})
it('should support empty string', function(){
utils.etag('')
.should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
assert.strictEqual(utils.etag(''),
'"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
})
})
@@ -49,23 +50,23 @@ describe('utils.setCharset(type, charset)', function () {
describe('utils.wetag(body, encoding)', function(){
it('should support strings', function(){
utils.wetag('express!')
.should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
assert.strictEqual(utils.wetag('express!'),
'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
})
it('should support utf8 strings', function(){
utils.wetag('express❤', 'utf8')
.should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
assert.strictEqual(utils.wetag('express❤', 'utf8'),
'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')
})
it('should support buffer', function(){
utils.wetag(Buffer.from('express!'))
.should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
assert.strictEqual(utils.wetag(Buffer.from('express!')),
'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')
})
it('should support empty string', function(){
utils.wetag('')
.should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
assert.strictEqual(utils.wetag(''),
'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')
})
})
@@ -89,7 +90,7 @@ describe('utils.isAbsolute()', function(){
describe('utils.flatten(arr)', function(){
it('should flatten an array', function(){
var arr = ['one', ['two', ['three', 'four'], 'five']];
utils.flatten(arr)
.should.eql(['one', 'two', 'three', 'four', 'five']);
should(utils.flatten(arr))
.eql(['one', 'two', 'three', 'four', 'five'])
})
})