From f5c0cdb8c1ff217688947c31ca52fcbb9e035a27 Mon Sep 17 00:00:00 2001 From: Jon Linklater-Johnson Date: Mon, 7 Sep 2015 17:38:53 +0100 Subject: [PATCH 1/2] Updates Node releases from both release and rc download directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds on the work by Michał Gołębiowski to make two requests to both https://nodejs.org/download/release/ and https://nodejs.org/download/rc/ to add release candidates to the list of the Node versions and subsequently (as of 7th Sep 2015) show 4.0.0-rc.2 at /node/unstable - was previously incorrectly showing 0.12.7 --- lib/sources/node.js | 29 +++++++++++++++++++++++++---- test/node/integration.test.coffee | 12 +++++++++--- test/node/source.test.coffee | 7 +++++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/sources/node.js b/lib/sources/node.js index e437e80..ce4a350 100644 --- a/lib/sources/node.js +++ b/lib/sources/node.js @@ -13,7 +13,8 @@ module.exports = NodeSource; function NodeSource(options) { _.extend(this, { name: 'node', - url: 'http://nodejs.org/dist/', + releaseUrl: 'https://nodejs.org/download/release/', + candidateUrl: 'https://nodejs.org/download/rc/', all: [], stable: [], updated: undefined @@ -21,10 +22,12 @@ function NodeSource(options) { } NodeSource.prototype.update = function(done) { + var responseText = ''; + done = done || NOOP; agent - .get(this.url) + .get(this.releaseUrl) .timeout(TIMEOUT) .end(parseResponse.bind(this)); @@ -33,12 +36,30 @@ NodeSource.prototype.update = function(done) { if (!res.text) return done(new Error('No response'), false); if (res.status !== 200) return done(new Error('Bad response'), false); - this._parse(res.text) - done(undefined, true); + responseText += res.text; + + agent + .get(this.candidateUrl) + .timeout(TIMEOUT) + .end(parseResponse.bind(this)); + + function parseResponse(err, res) { + if (err) return done(err, false); + if (!res.text) return done(new Error('No response'), false); + if (res.status !== 200) return done(new Error('Bad response'), false); + + responseText += res.text; + this._parse(responseText) + done(undefined, true); + + } + } + }; NodeSource.prototype._parse = function(body) { + var versions = _.unique(body.match(SEMVER)); this.all = versions.sort(semver.compare); diff --git a/test/node/integration.test.coffee b/test/node/integration.test.coffee index 5e2e036..38ce712 100644 --- a/test/node/integration.test.coffee +++ b/test/node/integration.test.coffee @@ -34,7 +34,15 @@ describe "Node Routes", -> it "redirects the failing app to a false endpoint", (done) -> this.timeout(20000) - failingApp.resolvers.node.source.url = 'http://nodejs.org/fail/'; + failingApp.resolvers.node.source.releaseUrl = 'http://nodejs.org/fail/'; + failingApp.resolvers.node.update (err, updated) -> + assert(err) + assert(!updated) + done() + + it "redirects the failing app to a false endpoint", (done) -> + this.timeout(20000) + failingApp.resolvers.node.source.candidateUrl = 'http://nodejs.org/fail/'; failingApp.resolvers.node.update (err, updated) -> assert(err) assert(!updated) @@ -77,7 +85,6 @@ describe "Node Routes", -> .end (err, res) -> return done(err) if err assert semver.valid(res.text) - assert.equal(semver.parse(res.text).minor, 12) done() it "works with a failing endpoint", (done) -> @@ -88,7 +95,6 @@ describe "Node Routes", -> .end (err, res) -> return done(err) if err assert semver.valid(res.text) - assert.equal(semver.parse(res.text).minor, 12) done() describe "GET /node/resolve/0.8.x", -> diff --git a/test/node/source.test.coffee b/test/node/source.test.coffee index 66f757a..ca3423d 100644 --- a/test/node/source.test.coffee +++ b/test/node/source.test.coffee @@ -20,8 +20,11 @@ describe "Node Source", -> it "default to empty stable array", -> assert.equal this.s.stable.length, 0 - it "defaults to the 'http://nodejs.org/dist/' url", -> - assert.equal this.s.url, 'http://nodejs.org/dist/' + it "defaults releases to the 'https://nodejs.org/download/release/' url", -> + assert.equal this.s.releaseUrl, 'https://nodejs.org/download/release/' + + it "defaults release candidates to the 'https://nodejs.org/download/rc/' url", -> + assert.equal this.s.candidateUrl, 'https://nodejs.org/download/rc/' it "has never been updated", -> assert.ok !this.s.updated From fc004bfa01b7be97406e08782623b3f1c436d9d6 Mon Sep 17 00:00:00 2001 From: Jon Linklater-Johnson Date: Mon, 7 Sep 2015 18:30:14 +0100 Subject: [PATCH 2/2] Fixes indentation --- lib/sources/node.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/sources/node.js b/lib/sources/node.js index ce4a350..4a996b9 100644 --- a/lib/sources/node.js +++ b/lib/sources/node.js @@ -36,23 +36,23 @@ NodeSource.prototype.update = function(done) { if (!res.text) return done(new Error('No response'), false); if (res.status !== 200) return done(new Error('Bad response'), false); - responseText += res.text; + responseText += res.text; - agent - .get(this.candidateUrl) - .timeout(TIMEOUT) - .end(parseResponse.bind(this)); + agent + .get(this.candidateUrl) + .timeout(TIMEOUT) + .end(parseResponse.bind(this)); - function parseResponse(err, res) { - if (err) return done(err, false); - if (!res.text) return done(new Error('No response'), false); - if (res.status !== 200) return done(new Error('Bad response'), false); + function parseResponse(err, res) { + if (err) return done(err, false); + if (!res.text) return done(new Error('No response'), false); + if (res.status !== 200) return done(new Error('Bad response'), false); - responseText += res.text; - this._parse(responseText) - done(undefined, true); + responseText += res.text; + this._parse(responseText) + done(undefined, true); - } + } }