mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-13 21:27:12 +01:00
8866c39623
The Firefox extension version format does not support the version format we use (SemVer), so we have to specially format the extension version to be compatible. The format we chose was `[major].[minor].[patch].[buildType][buildVersion]`. But when we tried to submit a build with a version in that format, it was rejected as invalid for unknown reasons. The Firefox extension format has been updated to `[major].[minor].[patch][buildType][buildVersion]`. This seems to pass validation.
104 lines
3.2 KiB
JavaScript
104 lines
3.2 KiB
JavaScript
import extension from 'extensionizer';
|
|
import ExtensionPlatform from './extension';
|
|
|
|
jest.mock('extensionizer', () => {
|
|
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', () => {
|
|
extension.runtime.getManifest.mockReturnValue({ version: '1.2.3' });
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
const version = extensionPlatform.getVersion();
|
|
|
|
expect(version).toBe('1.2.3');
|
|
});
|
|
|
|
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
|
|
extension.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', () => {
|
|
extension.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', () => {
|
|
extension.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 version name is missing from Chrome style prerelease manifest', () => {
|
|
extension.runtime.getManifest.mockReturnValue({
|
|
version: '1.2.3.0',
|
|
});
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
|
|
});
|
|
|
|
it('should throw error if version includes four parts in a Firefox style manifest', () => {
|
|
extension.runtime.getManifest.mockReturnValue({
|
|
version: '1.2.3.4',
|
|
});
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
expect(() => extensionPlatform.getVersion()).toThrow('Invalid version:');
|
|
});
|
|
|
|
it('should throw error if build version is missing from Firefox style prerelease manifest', () => {
|
|
extension.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', () => {
|
|
extension.runtime.getManifest.mockReturnValue({
|
|
version: '1.2.beta0',
|
|
});
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
expect(() => extensionPlatform.getVersion()).toThrow(
|
|
'Version contains invalid prerelease:',
|
|
);
|
|
});
|
|
});
|
|
});
|