4

我一直在节点中开发一个命令行应用程序,它执行一些文件系统读取和表达应用程序的内容,并且我的所有测试都在本地通过,但是 Travis 在构建时似乎遇到了问题(超时,这是一个 Jasmine 节点事物)。这就是我所拥有的

.travis.yml

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

生病合并规范.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);
});

您还可以在 github 上查看代码,并在 Travis 中查看构建。我最初认为 app.list() 阻止了控制台的执行,但删除它也不起作用。

Travis 是否只是阻止某些端口?它不允许文件系统查询吗?

4

1 回答 1

1

看起来当前脚本正在运行,它是:

.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 确实允许文件系统查询。

于 2015-06-10T02:51:27.047 回答