forked from smysnk/gulp-cloudfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
116 lines (91 loc) · 2.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var cloundfront = require("./index");
var toolFactory = require("./tool");
var should = require("should");
var gulp = require("gulp");
var es = require("event-stream");
var fs = require("fs");
var util = require("util");
var Stream = require("stream");
var assert = require("assert");
var path = require('path');
var gutil = require("gulp-util");
var glob = require("glob");
var sinon = require("sinon");
require("mocha");
describe("gulp-cloudfront", function () {
var stream;
var writeFile = function(globPath) {
//write all files to stream
glob(globPath + "/**/*.*", {}, function (er, fileNames) {
fileNames.forEach(function (fileName) {
stream.write(new gutil.File({
path: path.join(__dirname, fileName),
contents: fs.readFileSync(fileName),
base: path.join(__dirname, globPath)
}));
});
stream.end();
});
}
it("should identify default index pattern", function(done) {
var dirRoot = 'test/fixtures/config1';
var callback = sinon.mock().withArgs('/index.abcd1234.html').once().returns({
then: function (success, error) {
success();
}
});
var tool = {
updateDefaultRootObject: callback
};
stream = cloundfront({
tool: tool
});
stream.on('data', function (file) {});
stream.on('end', function () {
callback.verify();
done();
});
writeFile(dirRoot);
});
it("should identify default index pattern gzipped", function(done) {
var dirRoot = 'test/fixtures/gzip';
var callback = sinon.mock().withArgs('/index.abcd1234.html').once().returns({
then: function (success, error) {
success();
}
});
var tool = {
updateDefaultRootObject: callback
};
stream = cloundfront({
tool: tool
});
stream.on('data', function (file) {});
stream.on('end', function () {
callback.verify();
done();
});
writeFile(dirRoot);
});
it("should identify custom pattern", function(done) {
var dirRoot = 'test/fixtures/config1';
var callback = sinon.mock().withArgs('/custom.a1b2.html').once().returns({
then: function (success, error) {
success();
}
});
var tool = {
updateDefaultRootObject: callback
};
stream = cloundfront({
patternIndex: /^\/custom\.[a-f0-9]{4}\.html$/gi,
tool: tool
});
stream.on('data', function (file) {});
stream.on('end', function () {
callback.verify();
done();
});
writeFile(dirRoot);
});
});