Skip to content

Commit

Permalink
npm test
Browse files Browse the repository at this point in the history
  • Loading branch information
arunasank committed Jul 10, 2018
1 parent 2c9a670 commit a863d41
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/bin.watchbot-binary-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <patch|minor|major>`)', async (assert) => {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6';

// stubs and spies
Expand Down Expand Up @@ -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';

Expand Down

0 comments on commit a863d41

Please sign in to comment.