2013-12-04 1 views
4

Я работаю над приложением командной строки в узле, в котором некоторые файловые системы читают и выражают приложения, и все мои тесты проходят локально, однако Трэвис, похоже, иметь проблему при создании (тайм-аут, который является предметом Jasmine Node). Вот что я получилTravis CI разыгрывает тесты на узлом жасмина, но проходит локально

.travis.yml

language: node_js 
node_js: 
    - '>=0.10' 
before_script: 
    - npm install -g grunt-cli 
    - npm link 
script: 
    - "grunt --verbose" 

sickmerge_spec.js

// Set the test environment 
process.env.NODE_ENV = 'test'; 

// Dependencies 
var exec = require('child_process').exec, 
    fs = require('fs'), 
    version = require('../package.json').version, 
    request = require('request'); 
    // Helper function to exectue the sickmerge cli 
    function execSickmerge (options, callback) { 
     exec('sickmerge ' + options, function(err, stdout) { 
      console.log(stdout); 
      callback(stdout); 
     }); 
    } 
// ... Lots of other tests that exec the command, test below fails 
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(); 
      }); 
     }); 
    }); 
}); 

Команда Код

#! /usr/bin/env node 
/* 
* sickmerge 
* https://github.com/jgriffith/sickmerge 
* 
* Copyright (c) 2013 jgriffith 
* Licensed under the MIT license. 
*/ 

/* 
* Module Dependencies/Setup 
*/ 
var fs = require('fs'), 
    program = require('commander'), 
    syntaxOptions = require('./lib/syntax'), 
    version = require('./package.json').version, 
    fileLocation, 
    env = require('./lib/config')(); 

// Program Setup and Options 
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); 

// Store the file location so we can persist later 
fileLocation = program.args[0]; 

// For printing available syntax options 
function printSyntaxOptions() { 
    console.log('Available options include:\n' + syntaxOptions.showSupportedSyntaxes()); 
    return; 
} 

// If the user wants to see the syntax options 
if (program.syntaxes) { 
    printSyntaxOptions(); 
    return; 
} 

// No File given, print help since it's required 
if (!fileLocation) { 
    program.outputHelp(); 
    return; 
} 

// Invalid merge option 
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; 
} 

// Invalid syntax option 
if (program.syntax && syntaxOptions.indexOf(program.syntax) === -1) { 
    console.log('You\'ve specified an invalid syntax option: ' + program.syntax); 
    printSyntaxOptions(); 
    return; 
} 

// Read the passed file, strip the git comments, and build the web service 
fs.readFile(fileLocation, function(err, result) { 
    if (err) return console.log('There was an error loading your file! ' + err); 

    // Setup parameters, load additional files 
    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'); 


    // Web server setup 
    app.use(express.bodyParser()); 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'ejs'); 
    app.use(express.static(path.join(__dirname, 'public'))); 

    // Build the base route for the page 
    app.get('/', function (req, res) { 
     res.render('editor', { 
      title: fileLocation, 
      syntax: syntax, 
      body: threeWayMerge 
     }); 
    }); 

    // Post route for saving the file (this is final) and closes the process 
    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(); 
     }); 
    }); 

    // Get route for cancelling the file (this is final) and closes the process 
    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); 
}); 

Вы также можете увидеть the code on github и builds in Travis. Первоначально я думал, что app.list() предотвращает выполнение консоли, но удаление его тоже не работает.

Действительно ли Travis блокирует определенные порты? Разве это не позволяет запросы файловой системы?

+0

Я бы предположил, что запрос ('http://127.0.0.1:3000/' делает тайм-аут? Может быть, вы должны использовать supertest вместо этого. –

ответ

1

Похоже the current script работает что:

.travis.yml

language: node_js 
node_js: 
    - '>=0.10' 
before_install: 
    - npm install -g grunt-cli 
before_script: 
    - npm link 
script: 
    - "grunt --verbose" 

ли не позволить файловой системы запросов?

Travis-CI позволяет запрашивать файловые системы.