forked from forgejo/forgejo
Unregister non-matching serviceworkers (#15834)
* Unregister non-matching serviceworkers With the addition of the /assets url, users who visited a previous version of the site now may have two active service workers, one with the old scope `/` and one with scope `/assets`. This check for serviceworkers that do not match the current script path and unregisters them. Also included is a small refactor to publicpath.js which was simplified because AssetUrlPrefix is always present now. Also it makes use of the new joinPaths helper too. Fixes: https://github.com/go-gitea/gitea/pull/15823
This commit is contained in:
parent
b61092bcb0
commit
8ab815ae93
5 changed files with 81 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
basename, extname, isObject, uniq, stripTags,
|
||||
basename, extname, isObject, uniq, stripTags, joinPaths,
|
||||
} from './utils.js';
|
||||
|
||||
test('basename', () => {
|
||||
|
@ -15,6 +15,45 @@ test('extname', () => {
|
|||
expect(extname('file.js')).toEqual('.js');
|
||||
});
|
||||
|
||||
test('joinPaths', () => {
|
||||
expect(joinPaths('', '')).toEqual('');
|
||||
expect(joinPaths('', 'b')).toEqual('b');
|
||||
expect(joinPaths('', '/b')).toEqual('/b');
|
||||
expect(joinPaths('', '/b/')).toEqual('/b/');
|
||||
expect(joinPaths('a', '')).toEqual('a');
|
||||
expect(joinPaths('/a', '')).toEqual('/a');
|
||||
expect(joinPaths('/a/', '')).toEqual('/a/');
|
||||
expect(joinPaths('a', 'b')).toEqual('a/b');
|
||||
expect(joinPaths('a', '/b')).toEqual('a/b');
|
||||
expect(joinPaths('/a', '/b')).toEqual('/a/b');
|
||||
expect(joinPaths('/a', '/b')).toEqual('/a/b');
|
||||
expect(joinPaths('/a/', '/b')).toEqual('/a/b');
|
||||
expect(joinPaths('/a', '/b/')).toEqual('/a/b/');
|
||||
expect(joinPaths('/a/', '/b/')).toEqual('/a/b/');
|
||||
|
||||
expect(joinPaths('', '', '')).toEqual('');
|
||||
expect(joinPaths('', 'b', '')).toEqual('b');
|
||||
expect(joinPaths('', 'b', 'c')).toEqual('b/c');
|
||||
expect(joinPaths('', '', 'c')).toEqual('c');
|
||||
expect(joinPaths('', '/b', '/c')).toEqual('/b/c');
|
||||
expect(joinPaths('/a', '', '/c')).toEqual('/a/c');
|
||||
expect(joinPaths('/a', '/b', '')).toEqual('/a/b');
|
||||
|
||||
expect(joinPaths('', '/')).toEqual('/');
|
||||
expect(joinPaths('a', '/')).toEqual('a/');
|
||||
expect(joinPaths('', '/', '/')).toEqual('/');
|
||||
expect(joinPaths('/', '/')).toEqual('/');
|
||||
expect(joinPaths('/', '')).toEqual('/');
|
||||
expect(joinPaths('/', 'b')).toEqual('/b');
|
||||
expect(joinPaths('/', 'b/')).toEqual('/b/');
|
||||
expect(joinPaths('/', '', '/')).toEqual('/');
|
||||
expect(joinPaths('/', 'b', '/')).toEqual('/b/');
|
||||
expect(joinPaths('/', 'b/', '/')).toEqual('/b/');
|
||||
expect(joinPaths('a', '/', '/')).toEqual('a/');
|
||||
expect(joinPaths('/', '/', 'c')).toEqual('/c');
|
||||
expect(joinPaths('/', '/', 'c/')).toEqual('/c/');
|
||||
});
|
||||
|
||||
test('isObject', () => {
|
||||
expect(isObject({})).toBeTrue();
|
||||
expect(isObject([])).toBeFalse();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue