From a863d417db2575688d4ac5269dc23b069e7e925a Mon Sep 17 00:00:00 2001 From: arunasank Date: Tue, 10 Jul 2018 22:04:06 +0530 Subject: [PATCH] npm test --- test/bin.watchbot-binary-generator.test.js | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/test/bin.watchbot-binary-generator.test.js b/test/bin.watchbot-binary-generator.test.js index 21f00da4..7ffd65b7 100644 --- a/test/bin.watchbot-binary-generator.test.js +++ b/test/bin.watchbot-binary-generator.test.js @@ -34,7 +34,7 @@ test('getTagForSha: commit not found', async (assert) => { assert.end(); }); -test('uploadBundle: tag found', async (assert) => { +test('uploadBundle: tag found (Tag created using `npm version `)', async (assert) => { process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6'; // stubs and spies @@ -83,6 +83,56 @@ test('uploadBundle: tag found', async (assert) => { assert.end(); }); + +test('uploadBundle: tag found (Tag created manually)', async (assert) => { + process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6'; + + // stubs and spies + const execStub = sinon.stub(wbg, 'exec').callsFake(() => { + return Promise.resolve({ stdout: 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6\t/refs/tags/4.1.1' }); + }); + const fsCreateReadStreamStub = sinon.stub(fs, 'createReadStream').callsFake((file) => file); + const s3Stub = AWS.stub('S3', 'putObject', function () { + this.request.promise.returns(Promise.resolve()); + }); + const log = sinon.spy(console, 'log'); + + await wbg.uploadBundle(); + + assert.ok(execStub.calledWith('npm ci --production')); + assert.ok(execStub.calledWith('npm install -g pkg')); + assert.ok(execStub.calledWith('pkg .')); + assert.ok(execStub.calledWith('git ls-remote --tags https://github.com/mapbox/ecs-watchbot')); + + assert.ok(s3Stub.calledWith({ + Bucket: 'watchbot-binaries', + Key: 'linux/4.1.1/watchbot', + Body: fs.createReadStream('watchbot-linux'), + ACL: 'public-read' + })); + assert.ok(s3Stub.calledWith({ + Bucket: 'watchbot-binaries', + Key: 'macosx/4.1.1/watchbot', + Body: fs.createReadStream('watchbot-macos'), + ACL: 'public-read' + })); + assert.ok(s3Stub.calledWith({ + Bucket: 'watchbot-binaries', + Key: 'windows/4.1.1/watchbot', + Body: fs.createReadStream('watchbot-win.exe'), + ACL: 'public-read' + })); + assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/linux/4.1.1/watchbot')); + assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/macosx/4.1.1/watchbot')); + assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/windows/4.1.1/watchbot')); + + fsCreateReadStreamStub.restore(); + log.restore(); + execStub.restore(); + s3Stub.restore(); + assert.end(); +}); + test('uploadBundle: tag not found', async (assert) => { process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = '123456';