2022-03-18 20:07:05 +01:00
|
|
|
import browser from 'webextension-polyfill';
|
2021-10-14 23:20:14 +02:00
|
|
|
import ExtensionPlatform from './extension';
|
|
|
|
|
2022-03-18 20:07:05 +01:00
|
|
|
jest.mock('webextension-polyfill', () => {
|
2021-10-14 23:20:14 +02:00
|
|
|
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', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({ version: '1.2.3' });
|
2021-10-14 23:20:14 +02:00
|
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
|
|
|
|
const version = extensionPlatform.getVersion();
|
|
|
|
|
|
|
|
expect(version).toBe('1.2.3');
|
|
|
|
});
|
|
|
|
|
2022-05-03 18:48:36 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2021-10-14 23:20:14 +02:00
|
|
|
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({
|
2021-10-14 23:20:14 +02:00
|
|
|
version: '1.2.3.0',
|
2022-01-03 15:00:13 +01:00
|
|
|
version_name: '1.2.3-beta.0',
|
2021-10-14 23:20:14 +02:00
|
|
|
});
|
|
|
|
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', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({
|
2022-01-03 17:18:10 +01:00
|
|
|
version: '1.2.3beta0',
|
2021-10-14 23:20:14 +02:00
|
|
|
});
|
|
|
|
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', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({
|
2021-10-14 23:20:14 +02:00
|
|
|
version: '1.2.3',
|
2022-01-03 15:00:13 +01:00
|
|
|
version_name: '1.2.3-beta.0',
|
2021-10-14 23:20:14 +02:00
|
|
|
});
|
|
|
|
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', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({
|
2022-01-03 17:18:10 +01:00
|
|
|
version: '1.2.3beta',
|
2021-10-14 23:20:14 +02:00
|
|
|
});
|
|
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
|
|
|
|
expect(() => extensionPlatform.getVersion()).toThrow(
|
|
|
|
'Version contains invalid prerelease:',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-03 17:18:10 +01:00
|
|
|
it('should throw error if patch is missing from Firefox style prerelease manifest', () => {
|
2022-03-18 20:07:05 +01:00
|
|
|
browser.runtime.getManifest.mockReturnValue({
|
2022-01-03 17:18:10 +01:00
|
|
|
version: '1.2.beta0',
|
2021-10-14 23:20:14 +02:00
|
|
|
});
|
|
|
|
const extensionPlatform = new ExtensionPlatform();
|
|
|
|
|
|
|
|
expect(() => extensionPlatform.getVersion()).toThrow(
|
|
|
|
'Version contains invalid prerelease:',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|