Skip to content

Commit bfa3c68

Browse files
YoranBrondsemaghedamat
authored andcommitted
Fix issue #54: Delay uploading manifest.txt until all files have uploaded.
1 parent 7f7ed92 commit bfa3c68

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

lib/s3.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ module.exports = CoreObject.extend({
2828

2929
upload: function(options) {
3030
options = options || {};
31-
return this._determineFilePaths(options).then(function(filePaths){
32-
return Promise.all(this._putObjects(filePaths, options));
31+
return this._determineFilePaths(options).then(function(filePaths) {
32+
const allFilesUploaded = Promise.all(this._putObjects(filePaths, options));
33+
34+
const manifestPath = options.manifestPath;
35+
if (manifestPath) {
36+
return allFilesUploaded.then(function() {
37+
return Promise.all(this._putObjects([manifestPath], options));
38+
}.bind(this));
39+
} else {
40+
return allFilesUploaded;
41+
}
3342
}.bind(this));
3443
},
3544

@@ -75,13 +84,7 @@ module.exports = CoreObject.extend({
7584
var cacheControl = options.cacheControl;
7685
var expires = options.expires;
7786

78-
var manifestPath = options.manifestPath;
79-
var pathsToUpload = filePaths;
80-
if (manifestPath) {
81-
pathsToUpload.push(manifestPath);
82-
}
83-
84-
return pathsToUpload.map(function(filePath) {
87+
return filePaths.map(function(filePath) {
8588
var basePath = path.join(cwd, filePath);
8689
var data = fs.readFileSync(basePath);
8790
var contentType = mime.lookup(basePath);

tests/unit/lib/s3-nodetest.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('s3', function() {
1212
putObject: function(params, cb) {
1313
cb();
1414
},
15-
getObject: function(params, cb){
15+
getObject: function(params, cb) {
1616
cb(new Error("File not found"));
1717
}
1818
};
@@ -168,13 +168,13 @@ describe('s3', function() {
168168
assert.match(mockUi.messages[3], /- js-app\/app\.css/);
169169
assert.match(mockUi.messages[4], /- js-app\/manifest\.txt/);
170170
done();
171-
}).catch(function(reason){
171+
}).catch(function(reason) {
172172
done(reason);
173173
});
174174
});
175175

176176
it('only uploads missing files when manifest is present on server', function (done) {
177-
s3Client.getObject = function(params, cb){
177+
s3Client.getObject = function(params, cb) {
178178
cb(undefined, {
179179
Body: "app.js"
180180
});
@@ -197,7 +197,37 @@ describe('s3', function() {
197197
assert.match(mockUi.messages[2], /- js-app\/app\.css/);
198198
assert.match(mockUi.messages[3], /- js-app\/manifest\.txt/);
199199
done();
200-
}).catch(function(reason){
200+
}).catch(function(reason) {
201+
done(reason);
202+
});
203+
});
204+
205+
it('does not upload manifest.txt when one of the files does not succeed uploading', function(done) {
206+
s3Client.putObject = function(params, cb) {
207+
if (params.Key === 'js-app/app.css') {
208+
cb('error uploading');
209+
} else {
210+
cb();
211+
}
212+
};
213+
214+
var options = {
215+
filePaths: ['app.js', 'app.css'],
216+
cwd: process.cwd() + '/tests/fixtures/dist',
217+
prefix: 'js-app',
218+
manifestPath: 'manifest.txt'
219+
};
220+
221+
var promise = subject.upload(options);
222+
223+
return assert.isRejected(promise)
224+
.then(function() {
225+
assert.equal(mockUi.messages.length, 3);
226+
assert.match(mockUi.messages[0], /- Downloading manifest for differential deploy.../);
227+
assert.match(mockUi.messages[1], /- Manifest not found. Disabling differential deploy\./);
228+
assert.match(mockUi.messages[2], /- js-app\/app\.js/);
229+
done();
230+
}).catch(function(reason) {
201231
done(reason);
202232
});
203233
});

0 commit comments

Comments
 (0)