Skip to content

Commit

Permalink
migrate assert.deepEqual => .deepStrictEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Aug 18, 2021
1 parent 4545b59 commit 4a410cc
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion __tests__/application/inspect.js
Expand Up @@ -13,7 +13,7 @@ describe('app.inspect()', () => {
});

it('should return a json representation', () => {
assert.deepEqual(
assert.deepStrictEqual(
{ subdomainOffset: 2, proxy: false, env: 'test' },
app.inspect()
);
Expand Down
8 changes: 4 additions & 4 deletions __tests__/application/respond.js
Expand Up @@ -552,7 +552,7 @@ describe('app.respond', () => {

const pkg = require('../../package');
assert.strictEqual(res.headers.hasOwnProperty('content-length'), false);
assert.deepEqual(res.body, pkg);
assert.deepStrictEqual(res.body, pkg);
});

it('should strip content-length when overwriting', async() => {
Expand All @@ -572,7 +572,7 @@ describe('app.respond', () => {

const pkg = require('../../package');
assert.strictEqual(res.headers.hasOwnProperty('content-length'), false);
assert.deepEqual(res.body, pkg);
assert.deepStrictEqual(res.body, pkg);
});

it('should keep content-length if not overwritten', async() => {
Expand All @@ -592,7 +592,7 @@ describe('app.respond', () => {

const pkg = require('../../package');
assert.strictEqual(res.headers.hasOwnProperty('content-length'), true);
assert.deepEqual(res.body, pkg);
assert.deepStrictEqual(res.body, pkg);
});

it('should keep content-length if overwritten with the same stream',
Expand All @@ -615,7 +615,7 @@ describe('app.respond', () => {

const pkg = require('../../package');
assert.strictEqual(res.headers.hasOwnProperty('content-length'), true);
assert.deepEqual(res.body, pkg);
assert.deepStrictEqual(res.body, pkg);
});

it('should handle errors', done => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/application/toJSON.js
Expand Up @@ -9,7 +9,7 @@ describe('app.toJSON()', () => {
const app = new Koa();
const obj = app.toJSON();

assert.deepEqual({
assert.deepStrictEqual({
subdomainOffset: 2,
proxy: false,
env: 'test'
Expand Down
4 changes: 2 additions & 2 deletions __tests__/application/use.js
Expand Up @@ -37,7 +37,7 @@ describe('app.use(fn)', () => {
.get('/')
.expect(404);

assert.deepEqual(calls, [1, 2, 3, 4, 5, 6]);
assert.deepStrictEqual(calls, [1, 2, 3, 4, 5, 6]);
});

it('should compose mixed middleware', async() => {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('app.use(fn)', () => {
.get('/')
.expect(404);

assert.deepEqual(calls, [1, 2, 3, 4, 5, 6]);
assert.deepStrictEqual(calls, [1, 2, 3, 4, 5, 6]);
});

// https://github.com/koajs/koa/pull/530#issuecomment-148138051
Expand Down
8 changes: 4 additions & 4 deletions __tests__/context/inspect.js
Expand Up @@ -11,13 +11,13 @@ describe('ctx.inspect()', () => {
const ctx = context();
const toJSON = ctx.toJSON(ctx);

assert.deepEqual(toJSON, ctx.inspect());
assert.deepEqual(util.inspect(toJSON), util.inspect(ctx));
assert.deepStrictEqual(toJSON, ctx.inspect());
assert.deepStrictEqual(util.inspect(toJSON), util.inspect(ctx));
});

// console.log(require.cache) will call prototype.inspect()
it('should not crash when called on the prototype', () => {
assert.deepEqual(prototype, prototype.inspect());
assert.deepEqual(util.inspect(prototype.inspect()), util.inspect(prototype));
assert.deepStrictEqual(prototype, prototype.inspect());
assert.deepStrictEqual(util.inspect(prototype.inspect()), util.inspect(prototype));
});
});
2 changes: 1 addition & 1 deletion __tests__/context/state.js
Expand Up @@ -10,7 +10,7 @@ describe('ctx.state', () => {
const app = new Koa();

app.use(ctx => {
assert.deepEqual(ctx.state, {});
assert.deepStrictEqual(ctx.state, {});
});

const server = app.listen();
Expand Down
4 changes: 2 additions & 2 deletions __tests__/context/toJSON.js
Expand Up @@ -18,15 +18,15 @@ describe('ctx.toJSON()', () => {
const req = obj.request;
const res = obj.response;

assert.deepEqual({
assert.deepStrictEqual({
method: 'POST',
url: '/items',
header: {
'content-type': 'text/plain'
}
}, req);

assert.deepEqual({
assert.deepStrictEqual({
status: 200,
message: 'OK',
header: {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/request/accept.js
Expand Up @@ -17,11 +17,11 @@ describe('ctx.accept=', () => {
it('should replace the accept object', () => {
const ctx = context();
ctx.req.headers.accept = 'text/plain';
assert.deepEqual(ctx.accepts(), ['text/plain']);
assert.deepStrictEqual(ctx.accepts(), ['text/plain']);

const request = context.request();
request.req.headers.accept = 'application/*;q=0.2, image/jpeg;q=0.8, text/html, text/plain';
ctx.accept = Accept(request.req);
assert.deepEqual(ctx.accepts(), ['text/html', 'text/plain', 'image/jpeg', 'application/*']);
assert.deepStrictEqual(ctx.accepts(), ['text/html', 'text/plain', 'image/jpeg', 'application/*']);
});
});
2 changes: 1 addition & 1 deletion __tests__/request/accepts.js
Expand Up @@ -10,7 +10,7 @@ describe('ctx.accepts(types)', () => {
it('should return all accepted types', () => {
const ctx = context();
ctx.req.headers.accept = 'application/*;q=0.2, image/jpeg;q=0.8, text/html, text/plain';
assert.deepEqual(ctx.accepts(), ['text/html', 'text/plain', 'image/jpeg', 'application/*']);
assert.deepStrictEqual(ctx.accepts(), ['text/html', 'text/plain', 'image/jpeg', 'application/*']);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/request/acceptsCharsets.js
Expand Up @@ -10,7 +10,7 @@ describe('ctx.acceptsCharsets()', () => {
it('should return accepted types', () => {
const ctx = context();
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
assert.deepEqual(ctx.acceptsCharsets(), ['utf-8', 'utf-7', 'iso-8859-1']);
assert.deepStrictEqual(ctx.acceptsCharsets(), ['utf-8', 'utf-7', 'iso-8859-1']);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/request/acceptsEncodings.js
Expand Up @@ -10,15 +10,15 @@ describe('ctx.acceptsEncodings()', () => {
it('should return accepted types', () => {
const ctx = context();
ctx.req.headers['accept-encoding'] = 'gzip, compress;q=0.2';
assert.deepEqual(ctx.acceptsEncodings(), ['gzip', 'compress', 'identity']);
assert.deepStrictEqual(ctx.acceptsEncodings(), ['gzip', 'compress', 'identity']);
assert.strictEqual(ctx.acceptsEncodings('gzip', 'compress'), 'gzip');
});
});

describe('when Accept-Encoding is not populated', () => {
it('should return identity', () => {
const ctx = context();
assert.deepEqual(ctx.acceptsEncodings(), ['identity']);
assert.deepStrictEqual(ctx.acceptsEncodings(), ['identity']);
assert.strictEqual(ctx.acceptsEncodings('gzip', 'deflate', 'identity'), 'identity');
});
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/request/acceptsLanguages.js
Expand Up @@ -10,7 +10,7 @@ describe('ctx.acceptsLanguages(langs)', () => {
it('should return accepted types', () => {
const ctx = context();
ctx.req.headers['accept-language'] = 'en;q=0.8, es, pt';
assert.deepEqual(ctx.acceptsLanguages(), ['es', 'pt', 'en']);
assert.deepStrictEqual(ctx.acceptsLanguages(), ['es', 'pt', 'en']);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/request/header.js
Expand Up @@ -7,12 +7,12 @@ const request = require('../../test-helpers/context').request;
describe('req.header', () => {
it('should return the request header object', () => {
const req = request();
assert.deepEqual(req.header, req.req.headers);
assert.deepStrictEqual(req.header, req.req.headers);
});

it('should set the request header object', () => {
const req = request();
req.header = {'X-Custom-Headerfield': 'Its one header, with headerfields'};
assert.deepEqual(req.header, req.req.headers);
assert.deepStrictEqual(req.header, req.req.headers);
});
});
4 changes: 2 additions & 2 deletions __tests__/request/headers.js
Expand Up @@ -7,12 +7,12 @@ const request = require('../../test-helpers/context').request;
describe('req.headers', () => {
it('should return the request header object', () => {
const req = request();
assert.deepEqual(req.headers, req.req.headers);
assert.deepStrictEqual(req.headers, req.req.headers);
});

it('should set the request header object', () => {
const req = request();
req.headers = {'X-Custom-Headerfield': 'Its one header, with headerfields'};
assert.deepEqual(req.headers, req.req.headers);
assert.deepStrictEqual(req.headers, req.req.headers);
});
});
4 changes: 2 additions & 2 deletions __tests__/request/inspect.js
Expand Up @@ -30,7 +30,7 @@ describe('req.inspect()', () => {
}
};

assert.deepEqual(req.inspect(), expected);
assert.deepEqual(util.inspect(req), util.inspect(expected));
assert.deepStrictEqual(req.inspect(), expected);
assert.deepStrictEqual(util.inspect(req), util.inspect(expected));
});
});
12 changes: 6 additions & 6 deletions __tests__/request/ips.js
Expand Up @@ -11,7 +11,7 @@ describe('req.ips', () => {
const req = request();
req.app.proxy = false;
req.header['x-forwarded-for'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, []);
assert.deepStrictEqual(req.ips, []);
});
});

Expand All @@ -20,7 +20,7 @@ describe('req.ips', () => {
const req = request();
req.app.proxy = true;
req.header['x-forwarded-for'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, ['127.0.0.1', '127.0.0.2']);
assert.deepStrictEqual(req.ips, ['127.0.0.1', '127.0.0.2']);
});
});
});
Expand All @@ -32,7 +32,7 @@ describe('req.ips', () => {
req.app.proxy = false;
req.app.proxyIpHeader = 'x-client-ip';
req.header['x-client-ip'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, []);
assert.deepStrictEqual(req.ips, []);
});
});

Expand All @@ -42,7 +42,7 @@ describe('req.ips', () => {
req.app.proxy = true;
req.app.proxyIpHeader = 'x-client-ip';
req.header['x-client-ip'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, ['127.0.0.1', '127.0.0.2']);
assert.deepStrictEqual(req.ips, ['127.0.0.1', '127.0.0.2']);
});
});
});
Expand All @@ -54,7 +54,7 @@ describe('req.ips', () => {
req.app.proxy = false;
req.app.maxIpsCount = 1;
req.header['x-forwarded-for'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, []);
assert.deepStrictEqual(req.ips, []);
});
});

Expand All @@ -64,7 +64,7 @@ describe('req.ips', () => {
req.app.proxy = true;
req.app.maxIpsCount = 1;
req.header['x-forwarded-for'] = '127.0.0.1,127.0.0.2';
assert.deepEqual(req.ips, ['127.0.0.2']);
assert.deepStrictEqual(req.ips, ['127.0.0.2']);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/request/query.js
Expand Up @@ -8,7 +8,7 @@ describe('ctx.query', () => {
describe('when missing', () => {
it('should return an empty object', () => {
const ctx = context({ url: '/' });
assert.deepEqual(ctx.query, {});
assert(!Object.keys(ctx.query).length);
});

it('should return the same object each time it\'s accessed', () => {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/request/subdomains.js
Expand Up @@ -9,20 +9,20 @@ describe('req.subdomains', () => {
const req = request();
req.header.host = 'tobi.ferrets.example.com';
req.app.subdomainOffset = 2;
assert.deepEqual(req.subdomains, ['ferrets', 'tobi']);
assert.deepStrictEqual(req.subdomains, ['ferrets', 'tobi']);

req.app.subdomainOffset = 3;
assert.deepEqual(req.subdomains, ['tobi']);
assert.deepStrictEqual(req.subdomains, ['tobi']);
});

it('should work with no host present', () => {
const req = request();
assert.deepEqual(req.subdomains, []);
assert.deepStrictEqual(req.subdomains, []);
});

it('should check if the host is an ip address, even with a port', () => {
const req = request();
req.header.host = '127.0.0.1:3000';
assert.deepEqual(req.subdomains, []);
assert.deepStrictEqual(req.subdomains, []);
});
});
6 changes: 3 additions & 3 deletions __tests__/response/append.js
Expand Up @@ -9,15 +9,15 @@ describe('ctx.append(name, val)', () => {
const ctx = context();
ctx.append('x-foo', 'bar1');
ctx.append('x-foo', 'bar2');
assert.deepEqual(ctx.response.header['x-foo'], ['bar1', 'bar2']);
assert.deepStrictEqual(ctx.response.header['x-foo'], ['bar1', 'bar2']);
});

it('should accept array of values', () => {
const ctx = context();

ctx.append('Set-Cookie', ['foo=bar', 'fizz=buzz']);
ctx.append('Set-Cookie', 'hi=again');
assert.deepEqual(ctx.response.header['set-cookie'], ['foo=bar', 'fizz=buzz', 'hi=again']);
assert.deepStrictEqual(ctx.response.header['set-cookie'], ['foo=bar', 'fizz=buzz', 'hi=again']);
});

it('should get reset by res.set(field, val)', () => {
Expand All @@ -37,6 +37,6 @@ describe('ctx.append(name, val)', () => {
ctx.set('Link', '<http://localhost/>');
ctx.append('Link', '<http://localhost:80/>');

assert.deepEqual(ctx.response.header.link, ['<http://localhost/>', '<http://localhost:80/>']);
assert.deepStrictEqual(ctx.response.header.link, ['<http://localhost/>', '<http://localhost:80/>']);
});
});
8 changes: 4 additions & 4 deletions __tests__/response/header.js
Expand Up @@ -11,14 +11,14 @@ describe('res.header', () => {
const res = response();
res.set('X-Foo', 'bar');
res.set('X-Number', 200);
assert.deepEqual(res.header, { 'x-foo': 'bar', 'x-number': '200' });
assert.deepStrictEqual(res.header, { 'x-foo': 'bar', 'x-number': '200' });
});

it('should use res.getHeaders() accessor when available', () => {
const res = response();
res.res._headers = null;
res.res.getHeaders = () => ({ 'x-foo': 'baz' });
assert.deepEqual(res.header, { 'x-foo': 'baz' });
assert.deepStrictEqual(res.header, { 'x-foo': 'baz' });
});

it('should return the response header object when no mocks are in use', async() => {
Expand All @@ -33,14 +33,14 @@ describe('res.header', () => {
await request(app.callback())
.get('/');

assert.deepEqual(header, { 'x-foo': '42' });
assert.deepStrictEqual(header, { 'x-foo': '42' });
});

describe('when res._headers not present', () => {
it('should return empty object', () => {
const res = response();
res.res._headers = null;
assert.deepEqual(res.header, {});
assert.deepStrictEqual(res.header, {});
});
});
});
4 changes: 2 additions & 2 deletions __tests__/response/headers.js
Expand Up @@ -8,14 +8,14 @@ describe('res.header', () => {
it('should return the response header object', () => {
const res = response();
res.set('X-Foo', 'bar');
assert.deepEqual(res.headers, { 'x-foo': 'bar' });
assert.deepStrictEqual(res.headers, { 'x-foo': 'bar' });
});

describe('when res._headers not present', () => {
it('should return empty object', () => {
const res = response();
res.res._headers = null;
assert.deepEqual(res.headers, {});
assert.deepStrictEqual(res.headers, {});
});
});
});
4 changes: 2 additions & 2 deletions __tests__/response/inspect.js
Expand Up @@ -30,7 +30,7 @@ describe('res.inspect()', () => {
body: 'hello'
};

assert.deepEqual(res.inspect(), expected);
assert.deepEqual(util.inspect(res), util.inspect(expected));
assert.deepStrictEqual(res.inspect(), expected);
assert.deepStrictEqual(util.inspect(res), util.inspect(expected));
});
});
2 changes: 1 addition & 1 deletion __tests__/response/remove.js
Expand Up @@ -9,6 +9,6 @@ describe('ctx.remove(name)', () => {
const ctx = context();
ctx.set('x-foo', 'bar');
ctx.remove('x-foo');
assert.deepEqual(ctx.response.header, {});
assert.deepStrictEqual(ctx.response.header, {});
});
});

0 comments on commit 4a410cc

Please sign in to comment.