gpt4 book ai didi

javascript - Travis CI 在 Node Jasmine 测试中超时,但在本地通过

转载 作者:搜寻专家 更新时间:2023-10-31 23:25:25 25 4
gpt4 key购买 nike

我一直在 node 中开发一个命令行应用程序,它执行一些文件系统读取和表达应用程序的东西,我的所有测试都在本地通过,但是 Travis 在构建时似乎遇到了问题(超时,这是 Jasmine Node 的东西)。这是我得到的

.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 是否只是阻止某些端口?它不允许文件系统查询吗?

最佳答案

看起来像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"

Does it not allow filesystem queries?

Travis-CI 允许文件系统查询。

关于javascript - Travis CI 在 Node Jasmine 测试中超时,但在本地通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20387609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com