etcher/tests/shared/release.spec.js
Juan Cruz Viotti d3b35742a6 refactor(GUI): integrate etcher-latest-version into the main repo (#1183)
`etcher-latest-version` was kept in a separate repository in order to
re-use it with the Etcher website, however the Etcher website is not
using it at all, and we're moving towards having the website in the main
repository.

Therefore, this commit brings back the logic from
`etcher-latest-version`, but introduces it as
`lib/shared/s3-packages.js`, in order to not tie ourselves to the
AngularJS framework, and as a step towards the Etcher SDK.

As a nice little bonus, this commit adds support for an
`ETCHER_FAKE_S3_LATEST_VERSION` environment variable that can be used to
trick Etcher that there is an available update, and therefore show the
update notifier modal.

Also, this commit adds support for snapshot builds update-checks, by
checking the `resin-nightly-downloads` S3 bucket if the current version
contains a git commit hash build number.

If the version is not a production release, then the update notifier
modal doesn't present the checkbox to disable update notifications for X
days.

We also add a property called `updates.semverRange` to `package.json`,
which can be used to fine control which versions are considered as
candidates for an update notification.

This commit adds a setting called `includeUnstableChannel`, which can be
used to tweak whether unstable (beta) releases are considered or not
when checking for the latest available version.

See: https://github.com/resin-io-modules/etcher-latest-version
Fixes: https://github.com/resin-io/etcher/issues/953
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
2017-04-26 23:52:04 -04:00

133 lines
4.8 KiB
JavaScript

/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const m = require('mochainon');
const _ = require('lodash');
const release = require('../../lib/shared/release');
describe('Shared: Release', function() {
describe('.RELEASE_TYPE', function() {
it('should be a plain object', function() {
m.chai.expect(_.isPlainObject(release.RELEASE_TYPE)).to.be.true;
});
it('should contain keys with different values', function() {
const keys = _.keys(release.RELEASE_TYPE);
const uniqueValues = _.uniq(_.values(release.RELEASE_TYPE));
m.chai.expect(_.size(keys)).to.equal(_.size(uniqueValues));
});
});
describe('.getReleaseType()', function() {
it('should return the unknown release type if the version is not valid semver', function() {
const releaseType = release.getReleaseType('foo.bar');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
});
describe('given the version has a short git commit hash build number', function() {
it('should return the snapshot release type', function() {
const releaseType = release.getReleaseType('1.0.0+6374412');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
});
it('should return the snapshot release type if the version has a pre release tag', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+6374412');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
});
});
describe('given the version has a long git commit hash build number', function() {
it('should return the snapshot release type', function() {
const releaseType = release.getReleaseType('1.0.0+6374412554b034799bfc6e13b4e39c3f5e6386e6');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
});
it('should return the snapshot release type if the version has a pre release tag', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+6374412554b034799bfc6e13b4e39c3f5e6386e6');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
});
});
describe('given the version has no build number', function() {
it('should return the production release type', function() {
const releaseType = release.getReleaseType('1.0.0');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION);
});
it('should return the production release type if the version has a pre release tag', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION);
});
});
describe('given a build number that is not a git commit hash', function() {
it('should return the unknown release type', function() {
const releaseType = release.getReleaseType('1.0.0+foo');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
});
it('should return the unknown release type if the version has a pre release tag', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+foo');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
});
});
});
describe('.isStableRelease()', function() {
it('should return true if given a production stable version', function() {
m.chai.expect(release.isStableRelease('1.0.0')).to.be.true;
});
it('should return false if given a production release candidate version', function() {
m.chai.expect(release.isStableRelease('1.0.0-rc.2')).to.be.false;
});
it('should return false if given a production beta version', function() {
m.chai.expect(release.isStableRelease('1.0.0-beta.1')).to.be.false;
});
it('should return true if given a snapshot stable version', function() {
m.chai.expect(release.isStableRelease('1.0.0+6374412')).to.be.true;
});
it('should return false if given a snapshot release candidate version', function() {
m.chai.expect(release.isStableRelease('1.0.0-rc.2+6374412')).to.be.false;
});
it('should return false if given a snapshot beta version', function() {
m.chai.expect(release.isStableRelease('1.0.0-beta.1+6374412')).to.be.false;
});
});
});