forked from OctopusDeploy/gulp-octo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
84 lines (65 loc) · 2.32 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
var gutil = require('gulp-util');
var octopack = require('@octopusdeploy/octopackjs');
var sinon = require('sinon');
var expect = require('chai').expect;
var plugin = require('./');
var path = require('path');
var fs = require('fs');
var vinylMap = require('vinyl-map');
describe('gulp-octo.push', function(){
it('immediately throws if host not provided', function() {
expect(function(){ plugin.push(); }).to.throw('host details must be provided.');
});
it('invokes `octo-pack.push`', function(done) {
var pkg = new gutil.File({
path: __dirname + '/bin/project.1.0.0.tar.gz',
contents: new Buffer('tarcontents')
});
var spy = sinon.stub(octopack, 'push', function(contents, options, callback){
callback(null, {Title: 'Title', Version: '1.0.0'});
});
var packer = plugin.push({host: 'http://example.org', apiKey: 'ABC'});
packer.once('data', function() {
var req = octopack.push.firstCall;
console.log(req);
expect(spy.calledOnce);
var pushOptions = spy.firstCall.args;
expect(pushOptions[0]).to.equal(pkg.contents);
expect(pushOptions[1].apikey).to.equal('ABC');
expect(pushOptions[1].host).to.equal('http://example.org');
expect(pushOptions[1].name).to.equal('project.1.0.0.tar.gz');
return done();
});
packer.end(pkg);
});
});
describe('gulp-octo.pack', function() {
it('uses package.json for package name default', function(cb) {
var spy = sinon.stub(fs, 'readFileSync');
spy.returns(JSON.stringify({version: '8.8', name: 'ProjectX'}));
var stream = plugin.pack();
addFileAndPipe(stream, function (code, filename) {
expect(filename).to.match(/ProjectX\.8\.8\.tar\.gz$/);
cb();
});
});
it('passes optional parameters to package name', function(cb) {
var stream = plugin.pack({version: '2.3', id: 'MyPack'});
addFileAndPipe(stream, function (code, filename) {
expect(filename).to.match(/MyPack\.2\.3\.tar\.gz$/);
cb();
});
});
function addFileAndPipe(stream, cb){
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: new Buffer('hello world')
}));
var evaluate = vinylMap(cb);
stream.end();
stream.pipe(evaluate);
}
});