forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var wrench = require('wrench'); | ||
var request = require('request'); | ||
var exec = require('child_process').exec; | ||
var spawn = require('child_process').spawn; | ||
|
||
describe('Starting sails server with lift', function () { | ||
var sailsBin = './bin/sails.js'; | ||
var appName = 'testApp'; | ||
var sailsServer; | ||
|
||
before(function() { | ||
if (fs.existsSync(appName)) { | ||
wrench.rmdirSyncRecursive(appName); | ||
} | ||
}); | ||
|
||
after(function() { | ||
if (fs.existsSync(appName)) { | ||
wrench.rmdirSyncRecursive(appName); | ||
} | ||
}); | ||
|
||
describe('in an empty directory', function () { | ||
|
||
before(function () { | ||
// Make empty folder and move into it | ||
fs.mkdirSync('empty'); | ||
process.chdir('empty'); | ||
sailsBin = '.' + sailsBin; | ||
}); | ||
|
||
after(function () { | ||
// Delete empty folder and move out of it | ||
process.chdir('../'); | ||
fs.rmdirSync('empty'); | ||
sailsBin = sailsBin.substr(1); | ||
}); | ||
|
||
it('should throw an error', function(done) { | ||
|
||
sailsServer = spawn(sailsBin, ['lift']); | ||
|
||
sailsServer.stderr.on('data', function (data) { | ||
var dataString = data + ''; | ||
assert(dataString.indexOf('error') !== -1); | ||
sailsServer.kill(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('in an sails app directory', function () { | ||
|
||
it('should start server without error', function(done) { | ||
|
||
exec(sailsBin + ' new ' + appName, function (err) { | ||
if (err) done(new Error(err)); | ||
|
||
// Move into app directory | ||
process.chdir(appName); | ||
sailsBin = '.' + sailsBin; | ||
|
||
sailsServer = spawn(sailsBin, ['lift']); | ||
|
||
sailsServer.stdout.on('data', function (data) { | ||
var dataString = data + ''; | ||
assert(dataString.indexOf('error') === -1); | ||
|
||
// Move out of app directory | ||
process.chdir('../'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should respond to a request to port 1337 with a 200 status code', function(done) { | ||
|
||
request('http://localhost:1337/', function (err, response) { | ||
if (err) done(new Error(err)); | ||
|
||
assert(response.statusCode === 200); | ||
sailsServer.kill(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |