Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Updates Node releases from both release and rc download directories #43

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 25 additions & 4 deletions lib/sources/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ 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
}, options);
}

NodeSource.prototype.update = function(done) {
var responseText = '';

done = done || NOOP;

agent
.get(this.url)
.get(this.releaseUrl)
.timeout(TIMEOUT)
.end(parseResponse.bind(this));

Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions test/node/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) ->
Expand All @@ -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", ->
Expand Down
7 changes: 5 additions & 2 deletions test/node/source.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down