I am working on a command line application in node that makes some file system, reads and expresses application material, and all my tests pass locally, however, Travis has a problem creating (turning off the time, which is a Jasmine node thing). Here is what i have
.travis.yml
language: node_js
node_js:
- '>=0.10'
before_script:
- npm install -g grunt-cli
- npm link
script:
- "grunt --verbose"
sickmerge_spec.js
process.env.NODE_ENV = 'test';
var exec = require('child_process').exec,
fs = require('fs'),
version = require('../package.json').version,
request = require('request');
function execSickmerge (options, callback) {
exec('sickmerge ' + options, function(err, stdout) {
console.log(stdout);
callback(stdout);
});
}
describe('web application services', function() {
it('should respond when with a 200 when http requested', function(done) {
execSickmerge('./spec/fixtures/javascript.js', function() {
request('http://127.0.0.1:3000/', function(err, response) {
expect(response.statusCode).toEqual(200);
done();
});
});
});
});
Team code
#! /usr/bin/env node
var fs = require('fs'),
program = require('commander'),
syntaxOptions = require('./lib/syntax'),
version = require('./package.json').version,
fileLocation,
env = require('./lib/config')();
program
.version(version)
.usage('[options] <conflicted file location>')
.option('-h, --hostname [value]', 'The host URL you wish to query in the browser (defaults to localhost).')
.option('-o, --syntaxes', 'Will show the available syntax options for syntax highlighting.')
.option('-p, --port <n>', 'The port you wish to deploy on (defaults to 3000).', parseInt)
.option('-s, --syntax [value]', 'The language of the file for syntax highlighting (optional), defaults to no highlighting. Run with "-o" to see the available options.')
.option('-m, --merge [value]', 'Specify the initial view in the middle (merged) window on instantiation. Valid options are "yours", "theirs", and "both". Defaults to "yours"')
.parse(process.argv);
fileLocation = program.args[0];
function printSyntaxOptions () {
console.log('Available options include:\n' + syntaxOptions.showSupportedSyntaxes());
return;
}
if (program.syntaxes) {
printSyntaxOptions();
return;
}
if (!fileLocation) {
program.outputHelp();
return;
}
if (program.merge && ['yours', 'theirs', 'both'].indexOf(program.merge) === -1) {
console.log('You\'ve specified an invalid initial merged view: "' + program.merge + '".\nPlease use either "yours", "theirs", or "both"');
return;
}
if (program.syntax && syntaxOptions.indexOf(program.syntax) === -1) {
console.log('You\'ve specified an invalid syntax option: ' + program.syntax);
printSyntaxOptions();
return;
}
fs.readFile(fileLocation, function(err, result) {
if (err) return console.log('There was an error loading your file! ' + err);
var hostname = (program.hostname) ? program.hostname : 'localhost',
port = (program.port) ? program.port : 3000,
merge = (program.merge) ? program.merge : 'yours',
extension = fileLocation.split('.').pop(),
syntax = (program.syntax) ? program.syntax : syntaxOptions.getSyntax(extension),
threeWayMerge = require('./lib/gitStrip')(result.toString(), merge),
express = require('express'),
app = express(),
path = require('path'),
open = require('open');
app.use(express.bodyParser());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function (req, res) {
res.render('editor', {
title: fileLocation,
syntax: syntax,
body: threeWayMerge
});
});
app.post('/save', function (req, res) {
var content = req.body.content;
fs.writeFile(fileLocation, content, function (err) {
if (err) throw "There was an issues saving your file: " + err;
res.send('complete');
process.exit();
});
});
app.get('/cancel', function (req, res) {
res.send('terminated');
process.exit();
});
console.log(
'Sickmerge is waiting for changes.\n' +
'Visit http://' + hostname + ':' + port + '/ in your browser to make changes\n' +
'Pressing "Save" or "Cancel" will do the action and close the sickmerge program.\n'+
'Press CTRL+C if you\'ve closed your web browser and didn\'t click either of those buttons.'
);
app.listen(port);
if( env !== 'test') open('http://' + hostname + ':' + port);
});
You can also see the code in github while building in Travis . Initially, I thought app.list () prevents the console from executing, but deleting it also does not work.
Is Travis just blocking certain ports? Does the file system request allow?