Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/parallel/test-http-status-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

// Simple test of Node's HTTP ServerResponse.statusCode
// ServerResponse.prototype.statusCode

let testsComplete = 0;
const tests = [200, 202, 300, 404, 451, 500];
let testIdx = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testsComplete and testIdx can be removed. Instead add let test;.

const countdown = new Countdown(tests.length, () => s.close());

const s = http.createServer(function(req, res) {
const t = tests[testIdx];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed and then the assert.strictEqual() can compare to the top scope test variable.

Expand All @@ -43,9 +45,6 @@ s.listen(0, nextTest);


function nextTest() {
if (testIdx + 1 === tests.length) {
return s.close();
}
const test = tests[testIdx];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just do test = tests.shift() here (and not declare it as a const).


http.get({ port: s.address().port }, function(response) {
Expand All @@ -55,13 +54,14 @@ function nextTest() {
response.on('end', function() {
testsComplete++;
testIdx += 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variable additions would both be removed.

nextTest();
if (countdown.dec())
nextTest();
});
response.resume();
});
}


process.on('exit', function() {
assert.strictEqual(5, testsComplete);
assert.strictEqual(6, testsComplete);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing 6 with tests.length ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can actually be removed, as well as the testsComplete variable. Since there's a Countdown now, there's no need to verify that all 6 test cases executed.

});