1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 04:37:13 +01:00
metamask-extension/app/scripts/platforms/extension.test.js
Mark Stacey 23e3f52a04
Update version parsing to allow rollback release (#14288)
* Update version parsing to allow rollback release

When we want to rollback a release on Chrome, sometimes we use the
fourth part of the version for the rollback release. This is because
the Chrome web stores does not directly allow rolling back, but instead
requires us to re-submit the release we want to roll back to with a
higher version number.

The manifest version parsing now allows for a fourth version part.

The comments have also been updated to be more descriptive, and to fix
a minor inaccuracy.

* Fix typo in comment

Co-authored-by: David Walsh <davidwalsh83@gmail.com>

Co-authored-by: David Walsh <davidwalsh83@gmail.com>
2022-05-03 14:18:36 -02:30

95 lines
2.8 KiB
JavaScript

import browser from 'webextension-polyfill';
import ExtensionPlatform from './extension';
jest.mock('webextension-polyfill', () => {
return {
runtime: {
getManifest: jest.fn(),
},
};
});
describe('extension platform', () => {
beforeEach(() => {
// TODO: Delete this an enable 'resetMocks' in `jest.config.js` instead
jest.resetAllMocks();
});
describe('getVersion', () => {
it('should return non-prerelease version', () => {
browser.runtime.getManifest.mockReturnValue({ version: '1.2.3' });
const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion();
expect(version).toBe('1.2.3');
});
it('should return rollback version', () => {
browser.runtime.getManifest.mockReturnValue({ version: '1.2.3.1' });
const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion();
expect(version).toBe('1.2.3.1');
});
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.0',
version_name: '1.2.3-beta.0',
});
const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion();
expect(version).toBe('1.2.3-beta.0');
});
it('should return SemVer-formatted version for Firefox style manifest of prerelease', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3beta0',
});
const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion();
expect(version).toBe('1.2.3-beta.0');
});
it('should throw error if build version is missing from Chrome style prerelease manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3',
version_name: '1.2.3-beta.0',
});
const extensionPlatform = new ExtensionPlatform();
expect(() => extensionPlatform.getVersion()).toThrow(
'Version missing build number:',
);
});
it('should throw error if build version is missing from Firefox style prerelease manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.3beta',
});
const extensionPlatform = new ExtensionPlatform();
expect(() => extensionPlatform.getVersion()).toThrow(
'Version contains invalid prerelease:',
);
});
it('should throw error if patch is missing from Firefox style prerelease manifest', () => {
browser.runtime.getManifest.mockReturnValue({
version: '1.2.beta0',
});
const extensionPlatform = new ExtensionPlatform();
expect(() => extensionPlatform.getVersion()).toThrow(
'Version contains invalid prerelease:',
);
});
});
});