|
| 1 | +import { describe, expect, it } from 'bun:test'; |
| 2 | + |
| 3 | +import Manifest from './manifest'; |
| 4 | + |
| 5 | +describe('manifest', () => { |
| 6 | + describe('Firefox', () => { |
| 7 | + it('should create manifest v2', async () => { |
| 8 | + const manifest = new Manifest( |
| 9 | + {}, |
| 10 | + { author: 'nilfalse.com', version: '1.0.0' }, |
| 11 | + ); |
| 12 | + |
| 13 | + expect(manifest.render('firefox').split('\n')).toStrictEqual([ |
| 14 | + '{', |
| 15 | + ' "manifest_version": 2,', |
| 16 | + ' "name": "__MSG_ext_name__",', |
| 17 | + ' "short_name": "__MSG_ext_short_name__",', |
| 18 | + ' "version": "1.0.0",', |
| 19 | + ' "default_locale": "en",', |
| 20 | + ' "description": "__MSG_ext_description__",', |
| 21 | + ' "icons": {', |
| 22 | + ' "32": "icons/icon_32px.png",', |
| 23 | + ' "48": "icons/icon_48px.png",', |
| 24 | + ' "128": "icons/icon_128px.png",', |
| 25 | + ' "256": "icons/icon_256px.png",', |
| 26 | + ' "512": "icons/icon_512px.png"', |
| 27 | + ' },', |
| 28 | + ' "page_action": {', |
| 29 | + ' "default_icon": {', |
| 30 | + ' "32": "icons/icon_32px.png",', |
| 31 | + ' "48": "icons/icon_48px.png",', |
| 32 | + ' "128": "icons/icon_128px.png",', |
| 33 | + ' "256": "icons/icon_256px.png",', |
| 34 | + ' "512": "icons/icon_512px.png"', |
| 35 | + ' },', |
| 36 | + ' "default_popup": "popup.html",', |
| 37 | + ' "show_matches": [', |
| 38 | + ' "<all_urls>"', |
| 39 | + ' ]', |
| 40 | + ' },', |
| 41 | + ' "background": {},', |
| 42 | + ' "permissions": [', |
| 43 | + ' "dns",', |
| 44 | + ' "webRequest",', |
| 45 | + ' "storage"', |
| 46 | + ' ],', |
| 47 | + ' "host_permissions": [', |
| 48 | + ' "<all_urls>"', |
| 49 | + ' ],', |
| 50 | + ' "author": "nilfalse.com",', |
| 51 | + ' "browser_specific_settings": {', |
| 52 | + ' "gecko": {', |
| 53 | + ' "id": "@ctf"', |
| 54 | + ' }', |
| 55 | + ' }', |
| 56 | + '}', |
| 57 | + ]); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should use commit hash for version when it is available', async () => { |
| 61 | + const manifest = new Manifest( |
| 62 | + { GITHUB_SHA: '666e666' }, |
| 63 | + { author: 'nilfalse.com', version: '1.0.0' }, |
| 64 | + ); |
| 65 | + |
| 66 | + expect(manifest.render('firefox').split('\n')).toStrictEqual([ |
| 67 | + '{', |
| 68 | + ' "manifest_version": 2,', |
| 69 | + ' "name": "__MSG_ext_name__",', |
| 70 | + ' "short_name": "__MSG_ext_short_name__",', |
| 71 | + ' "version": "1.0.0",', |
| 72 | + ' "version_name": "1.0.0 (666e666)",', |
| 73 | + ' "default_locale": "en",', |
| 74 | + ' "description": "__MSG_ext_description__",', |
| 75 | + ' "icons": {', |
| 76 | + ' "32": "icons/icon_32px.png",', |
| 77 | + ' "48": "icons/icon_48px.png",', |
| 78 | + ' "128": "icons/icon_128px.png",', |
| 79 | + ' "256": "icons/icon_256px.png",', |
| 80 | + ' "512": "icons/icon_512px.png"', |
| 81 | + ' },', |
| 82 | + ' "page_action": {', |
| 83 | + ' "default_icon": {', |
| 84 | + ' "32": "icons/icon_32px.png",', |
| 85 | + ' "48": "icons/icon_48px.png",', |
| 86 | + ' "128": "icons/icon_128px.png",', |
| 87 | + ' "256": "icons/icon_256px.png",', |
| 88 | + ' "512": "icons/icon_512px.png"', |
| 89 | + ' },', |
| 90 | + ' "default_popup": "popup.html",', |
| 91 | + ' "show_matches": [', |
| 92 | + ' "<all_urls>"', |
| 93 | + ' ]', |
| 94 | + ' },', |
| 95 | + ' "background": {},', |
| 96 | + ' "permissions": [', |
| 97 | + ' "dns",', |
| 98 | + ' "webRequest",', |
| 99 | + ' "storage"', |
| 100 | + ' ],', |
| 101 | + ' "host_permissions": [', |
| 102 | + ' "<all_urls>"', |
| 103 | + ' ],', |
| 104 | + ' "author": "nilfalse.com",', |
| 105 | + ' "browser_specific_settings": {', |
| 106 | + ' "gecko": {', |
| 107 | + ' "id": "@ctf"', |
| 108 | + ' }', |
| 109 | + ' }', |
| 110 | + '}', |
| 111 | + ]); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + describe('Chromium', () => { |
| 116 | + it('should create manifest v3', async () => { |
| 117 | + const manifest = new Manifest( |
| 118 | + { GITHUB_SHA: '666e666' }, |
| 119 | + { author: 'nilfalse.com', version: '1.0.0' }, |
| 120 | + ); |
| 121 | + |
| 122 | + expect(manifest.render('chromium').split('\n')).toStrictEqual([ |
| 123 | + '{', |
| 124 | + ' "manifest_version": 3,', |
| 125 | + ' "name": "__MSG_ext_name__",', |
| 126 | + ' "short_name": "__MSG_ext_short_name__",', |
| 127 | + ' "version": "1.0.0",', |
| 128 | + ' "version_name": "1.0.0 (666e666)",', |
| 129 | + ' "default_locale": "en",', |
| 130 | + ' "description": "__MSG_ext_description__",', |
| 131 | + ' "icons": {', |
| 132 | + ' "32": "icons/icon_32px.png",', |
| 133 | + ' "48": "icons/icon_48px.png",', |
| 134 | + ' "128": "icons/icon_128px.png",', |
| 135 | + ' "256": "icons/icon_256px.png",', |
| 136 | + ' "512": "icons/icon_512px.png"', |
| 137 | + ' },', |
| 138 | + ' "action": {', |
| 139 | + ' "default_icon": {', |
| 140 | + ' "32": "icons/icon_32px.png",', |
| 141 | + ' "48": "icons/icon_48px.png",', |
| 142 | + ' "128": "icons/icon_128px.png",', |
| 143 | + ' "256": "icons/icon_256px.png",', |
| 144 | + ' "512": "icons/icon_512px.png"', |
| 145 | + ' },', |
| 146 | + ' "default_popup": "popup.html",', |
| 147 | + ' "show_matches": [', |
| 148 | + ' "<all_urls>"', |
| 149 | + ' ]', |
| 150 | + ' },', |
| 151 | + ' "background": {', |
| 152 | + ' "service_worker": "service_worker.js"', |
| 153 | + ' },', |
| 154 | + ' "permissions": [', |
| 155 | + ' "webRequest",', |
| 156 | + ' "storage",', |
| 157 | + ' "offscreen"', |
| 158 | + ' ],', |
| 159 | + ' "host_permissions": [', |
| 160 | + ' "<all_urls>"', |
| 161 | + ' ],', |
| 162 | + ' "author": "nilfalse.com"', |
| 163 | + '}', |
| 164 | + ]); |
| 165 | + }); |
| 166 | + }); |
| 167 | +}); |
0 commit comments