Skip to content

Commit

Permalink
uses request instead of superagent in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Dec 18, 2013
1 parent c926c12 commit 57f578f
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 218 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ exports.pipeline = function(root){

}

exports.pkg = pkg


/**
* Compile
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"mocha": "1.8.1",
"should": "1.2.2",
"superagent": "0.12.4"
"request": "2.30.0"
},
"scripts": {
"test": "mocha --reporter spec"
Expand Down
77 changes: 34 additions & 43 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require("should")
var superagent = require('superagent')
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
Expand Down Expand Up @@ -27,10 +27,9 @@ describe("basic", function(){
var staticGlobals = require(path.join(outputPath, "globals.json"))
staticGlobals.should.have.property("environment", "production")
staticGlobals.should.have.property("public")
var agent = superagent.agent()
agent.get('http://localhost:8100/globals.json').end(function(err, rsp){
rsp.should.have.status(200)
var dynamicGlobals = JSON.parse(rsp.text)
request('http://localhost:8100/globals.json', function (e, r, b) {
r.statusCode.should.eql(200)
var dynamicGlobals = JSON.parse(b)
dynamicGlobals.should.have.property("environment", "development")
dynamicGlobals.should.have.property("public")
done()
Expand All @@ -41,10 +40,9 @@ describe("basic", function(){
var staticCurrent = require(path.join(outputPath, "current.json"))
staticCurrent.should.have.property("path")
staticCurrent.should.have.property("source", "current")
var agent = superagent.agent()
agent.get('http://localhost:8100/current.json').end(function(err, rsp){
rsp.should.have.status(200)
var dynamicCurrent = JSON.parse(rsp.text)
request('http://localhost:8100/current.json', function (e, r, b) {
r.statusCode.should.eql(200)
var dynamicCurrent = JSON.parse(b)
dynamicCurrent.should.have.property("path")
dynamicCurrent.should.have.property("source", "current")
done()
Expand All @@ -55,11 +53,10 @@ describe("basic", function(){
fs.readFile(path.join(outputPath, "index.html"), function(err, contents){
contents.toString().should.include("Kitchen Sink")
contents.toString().should.include("Home")
var agent = superagent.agent()
agent.get('http://localhost:8100/').end(function(err, rsp){
rsp.should.have.status(200)
rsp.text.should.include("Kitchen Sink")
rsp.text.should.include("Home")
request('http://localhost:8100/', function (e, r, b) {
r.statusCode.should.eql(200)
b.should.include("Kitchen Sink")
b.should.include("Home")
done()
})
})
Expand All @@ -69,13 +66,12 @@ describe("basic", function(){
fs.readFile(path.join(outputPath, "404.html"), function(err, contents){
contents.toString().should.not.include("Kitchen Sink")
contents.toString().should.include("Custom, Page Not Found")
var agent = superagent.agent()
agent.get('http://localhost:8100/some/missing/path').end(function(err, rsp){
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.text.should.not.include("Kitchen Sink")
rsp.text.should.include("Custom, Page Not Found")
rsp.text.should.eql(contents.toString())
request('http://localhost:8100/some/missing/path', function (e, r, b) {
r.statusCode.should.eql(404)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.not.include("Kitchen Sink")
b.should.include("Custom, Page Not Found")
b.should.eql(contents.toString())
done()
})
})
Expand All @@ -84,21 +80,19 @@ describe("basic", function(){
it("should return CSS file", function(done){
fs.readFile(path.join(outputPath, "css", "main.css"), function(err, contents){
contents.toString().should.include("background")
var agent = superagent.agent()
agent.get('http://localhost:8100/css/main.css').end(function(err, rsp){
rsp.status.should.eql(200)
rsp.text.should.include("background")
rsp.text.should.eql(contents.toString())
request('http://localhost:8100/css/main.css', function (e, r, b) {
r.statusCode.should.eql(200)
b.should.include("background")
b.should.eql(contents.toString())
done()
})
})
})

it("should return proper mime type on 404 page", function(done){
var agent = superagent.agent()
agent.get('http://localhost:8100/some/missing/path.css').end(function(err, rsp){
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
request('http://localhost:8100/some/missing/path.css', function (e, r, b) {
r.statusCode.should.eql(404)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
Expand All @@ -107,30 +101,27 @@ describe("basic", function(){
fs.readFile(path.join(outputPath, "basic.html"), function(err, contents){
contents.toString().should.not.include("Kitchen Sink")
contents.toString().should.include("<h1>Basic HTML Page</h1>")
var agent = superagent.agent()
agent.get('http://localhost:8100/basic').end(function(err, rsp){
rsp.status.should.eql(200)
rsp.text.should.not.include("Kitchen Sink")
rsp.text.should.include("<h1>Basic HTML Page</h1>")
rsp.text.should.eql(contents.toString())
request('http://localhost:8100/basic', function(e,r,b){
r.statusCode.should.eql(200)
b.should.not.include("Kitchen Sink")
b.should.include("<h1>Basic HTML Page</h1>")
b.should.eql(contents.toString())
done()
})
})
})

it("should not return file starting with underscore", function(done){
var agent = superagent.agent()
agent.get('http://localhost:8100/shared/_nav.jade').end(function(err, rsp){
rsp.status.should.eql(404)
request('http://localhost:8100/shared/_nav.jade', function(e,r,b){
r.statusCode.should.eql(404)
done()
})
})

it("should render HTML page with spaces in the file name", function(done){
var agent = superagent.agent()
agent.get('http://localhost:8100/articles/with%20spaces').end(function(err, rsp){
rsp.status.should.eql(200)
rsp.text.should.include("foo article")
request('http://localhost:8100/articles/with%20spaces', function(e,r,b){
r.statusCode.should.eql(200)
b.should.include("foo article")
done()
})
})
Expand Down
25 changes: 11 additions & 14 deletions test/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require("should")
var superagent = require('superagent')
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
Expand All @@ -19,9 +19,8 @@ describe("errors", function(){
})

it("should get error message for invalid harp.json", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/').end(function(err, rsp){
rsp.should.have.status(500)
request('http://localhost:'+ port +'/', function (e, r, b) {
r.statusCode.should.eql(500)
harp.compile(projectPath, outputPath, function(error){
should.exist(error)
error.should.have.property("source")
Expand All @@ -48,9 +47,9 @@ describe("errors", function(){
})

it("should get error message for invalid _data.json", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/').end(function(err, rsp){
rsp.should.have.status(500)
request('http://localhost:'+ port +'/', function (e, r, b) {
r.statusCode.should.eql(500)
//b.should.include(harp.pkg.version)
harp.compile(projectPath, outputPath, function(error){
should.exist(error)
error.should.have.property("source")
Expand All @@ -77,9 +76,8 @@ describe("errors", function(){
})

it("should get error message for invalid _data.json", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/').end(function(err, rsp){
rsp.should.have.status(500)
request('http://localhost:'+ port +'/', function (e, r, b) {
r.statusCode.should.eql(500)
harp.compile(projectPath, outputPath, function(error){
should.exist(error)
error.should.have.property("source")
Expand All @@ -106,10 +104,9 @@ describe("errors", function(){
})

it("should return proper mime type on 404 page", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/some/missing/path.css').end(function(err, rsp){
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
request('http://localhost:'+ port +'/some/missing/path.css', function (e, r, b) {
r.statusCode.should.eql(404)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})
Expand Down
34 changes: 15 additions & 19 deletions test/fallbacks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var should = require("should")
var superagent = require('superagent')
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
Expand All @@ -21,22 +21,20 @@ describe("fallbacks", function(){
})

it("should return proper mime type on 200 page", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/some/fallback/path').end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
request('http://localhost:'+ port +'/some/fallback/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})

it("should have custom 200 page", function(done){
fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
should.not.exist(err)
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/some/missing/path').end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.text.should.eql(contents.toString())
request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
Expand All @@ -58,22 +56,20 @@ describe("fallbacks", function(){
})

it("should return proper mime type on 200 page", function(done){
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/some/fallback/path').end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
request('http://localhost:'+ port +'/some/fallback/path', function(e, r, b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
done()
})
})

it("should have custom 200 page", function(done){
fs.readFile(path.join(outputPath, "200.html"), function(err, contents){
should.not.exist(err)
var agent = superagent.agent()
agent.get('http://localhost:'+ port +'/some/missing/path').end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.text.should.eql(contents.toString())
request('http://localhost:'+ port +'/some/missing/path', function(e,r,b){
r.statusCode.should.eql(200)
r.headers.should.have.property("content-type", "text/html; charset=UTF-8")
b.should.eql(contents.toString())
done()
})
})
Expand Down
Loading

0 comments on commit 57f578f

Please sign in to comment.