Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Add tests for the plugin version check

Gabe Kangas1a4cedadf27c
diff --git a/web/tests/pluginUpdateAvailable.test.ts b/web/tests/pluginUpdateAvailable.test.ts
new file mode 100644
index 0000000000..86ee6ff9bd
--- /dev/null
+++ b/web/tests/pluginUpdateAvailable.test.ts
@@ -0,0 +1,76 @@
+import { isPluginUpdateAvailable } from '../utils/apis';
+
+describe('isPluginUpdateAvailable', () => {
+ describe('an update is offered only when the registry version is strictly newer', () => {
+ test('newer patch in the registry', () => {
+ expect(isPluginUpdateAvailable('0.2.1', '0.2.2')).toBe(true);
+ });
+
+ test('newer minor in the registry', () => {
+ expect(isPluginUpdateAvailable('0.2.1', '0.3.0')).toBe(true);
+ });
+
+ test('newer major in the registry', () => {
+ expect(isPluginUpdateAvailable('0.2.1', '1.0.0')).toBe(true);
+ });
+
+ test('same version is not an update', () => {
+ expect(isPluginUpdateAvailable('0.2.1', '0.2.1')).toBe(false);
+ });
+ });
+
+ // The regression this guards: the UI used to flag any version *difference*
+ // as an update, so a newer local/dev build looked like it needed a
+ // "downgrade" to the registry version.
+ describe('a newer locally-installed (dev) build is NOT flagged as an update', () => {
+ test('installed 0.3.0 vs registry 0.2.1', () => {
+ expect(isPluginUpdateAvailable('0.3.0', '0.2.1')).toBe(false);
+ });
+
+ test('installed major ahead of registry', () => {
+ expect(isPluginUpdateAvailable('2.0.0', '1.9.9')).toBe(false);
+ });
+ });
+
+ describe('missing versions never offer an update', () => {
+ test('no installed version', () => {
+ expect(isPluginUpdateAvailable(undefined, '0.2.1')).toBe(false);
+ });
+
+ test('no registry version', () => {
+ expect(isPluginUpdateAvailable('0.2.1', undefined)).toBe(false);
+ });
+
+ test('neither version', () => {
+ expect(isPluginUpdateAvailable(undefined, undefined)).toBe(false);
+ });
+
+ test('empty strings', () => {
+ expect(isPluginUpdateAvailable('', '')).toBe(false);
+ });
+ });
+
+ describe('un-orderable (non-semver) versions are treated conservatively as no update', () => {
+ test('non-semver installed version', () => {
+ expect(isPluginUpdateAvailable('dev', '0.2.1')).toBe(false);
+ });
+
+ test('non-semver registry version', () => {
+ expect(isPluginUpdateAvailable('0.2.1', 'latest')).toBe(false);
+ });
+
+ test('both non-semver', () => {
+ expect(isPluginUpdateAvailable('foo', 'bar')).toBe(false);
+ });
+ });
+
+ describe('prerelease ordering follows semver', () => {
+ test('a prerelease is older than its release', () => {
+ expect(isPluginUpdateAvailable('1.0.0-rc.1', '1.0.0')).toBe(true);
+ });
+
+ test('a release is not "updated" by an older prerelease', () => {
+ expect(isPluginUpdateAvailable('1.0.0', '1.0.0-rc.1')).toBe(false);
+ });
+ });
+});