nci/test/executor.js

120 lines
2.7 KiB
JavaScript
Raw Normal View History

'use strict';
var expect = require('expect.js'),
path = require('path'),
createExecutor = require('../lib/executor').createExecutor,
2015-06-23 19:18:13 +00:00
_ = require('underscore'),
helpers = require('./helpers'),
mercurialRevs = helpers.mercurialRevs;
['local'].forEach(function(type) {
describe(type + ' executor', function() {
var workspacePath = path.join(__dirname, 'workspace');
var clearWorkspace = function(done) {
helpers.removeDirIfExists(workspacePath, done);
};
2015-06-23 19:18:13 +00:00
var makeExecutorParams = function(params) {
params = params || {};
return {
type: type,
2015-06-23 19:18:13 +00:00
project: _({
dir: __dirname,
2015-03-30 21:06:08 +00:00
name: 'test project',
scm: {
type: 'mercurial',
repository: path.join(__dirname, 'repos', 'mercurial'),
rev: 'default'
},
steps: [
{type: 'shell', cmd: 'echo 1'},
{type: 'shell', cmd: 'echo 2'}
]
2015-06-23 19:18:13 +00:00
}).extend(params.project)
};
};
var executor, scmData;
describe('with scm rev default and without catch rev', function() {
before(clearWorkspace);
it('instance should be created without errors', function() {
executor = createExecutor(makeExecutorParams());
});
it('should run without errors', function(done) {
executor.run({}, function(err) {
expect(err).not.ok();
done();
});
executor.on('scmData', function(data) {
scmData = data;
});
});
it(
'scm data should be rev: last, changes: [0-last], is latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[mercurialRevs.length - 1],
changes: mercurialRevs.slice().reverse(),
isLatest: true
});
}
);
});
2015-05-09 16:59:27 +00:00
2015-06-23 19:18:13 +00:00
describe('with scm rev default and catch rev "first revision"', function() {
before(clearWorkspace);
it('instance should be created without errors', function() {
executor = createExecutor(makeExecutorParams({
project: {
catchRev: {comment: 'first revision'}
}
}));
});
it('should run without errors', function(done) {
executor.run({}, function(err) {
expect(err).not.ok();
done();
});
executor.on('scmData', function(data) {
scmData = data;
});
});
it('scm data should be rev: 1, changes: [0, 1], not latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[1],
changes: mercurialRevs.slice(0, 2).reverse(),
isLatest: false
});
});
it('should run it again without errors', function(done) {
executor.run({}, done);
});
it(
'scm data should be rev: last, changes: [2-last], is latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[mercurialRevs.length - 1],
changes: mercurialRevs.slice(2).reverse(),
isLatest: true
});
}
);
2015-05-09 16:59:27 +00:00
});
});
2015-06-23 19:18:13 +00:00
});