Skip to content

Commit c0e9596

Browse files
authored
Merge pull request #1318 from remotestorage/chore/upgrade_dependencies
Upgrade dependencies, switch Mocha tests from TS to JS
2 parents fceb3f4 + eba4d9a commit c0e9596

18 files changed

+3143
-2631
lines changed

.github/workflows/test-and-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
- name: Install dependencies
23-
run: npm ci --force
23+
run: npm ci
2424
- name: Run jaribu tests # These must be replaced before we can use Node v18 in CI
2525
run: npm test
2626
- name: Run mocha tests

.mocharc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

package-lock.json

Lines changed: 2634 additions & 2108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"homepage": "https://remotestorage.io",
1414
"scripts": {
1515
"test": "tsc && bash scripts/test-all.sh",
16-
"test:mocha": "mocha test/unit/*.test.ts",
17-
"test:watch": "mocha test/unit/*.test.ts --watch --reporter dot",
16+
"test:mocha": "mocha test/unit/*.test.mjs",
17+
"test:watch": "mocha test/unit/*.test.mjs --watch --reporter dot",
1818
"lint": "eslint --ext=ts src/",
1919
"lint:quiet": "eslint --quiet --ext=ts src/",
20-
"lint:specs": "eslint test/unit/*.ts",
21-
"lint:specs:quiet": "eslint --quiet test/unit/*.ts",
20+
"lint:specs": "eslint test/unit/*.mjs",
21+
"lint:specs:quiet": "eslint --quiet test/unit/*.mjs",
2222
"format": "esformatter --config esformatter-config.json -i src/sync.js",
2323
"build:js": "tsc -d --declarationDir release/types --declarationMap",
2424
"build:release": "NODE_ENV=production webpack --mode=production",
@@ -32,31 +32,28 @@
3232
"docs:preview": "vitepress preview docs"
3333
},
3434
"devDependencies": {
35-
"@babel/core": "^7.19.0",
36-
"@babel/preset-env": "^7.19.0",
37-
"@types/chai": "^4.3.3",
38-
"@types/chai-as-promised": "^7.1.5",
39-
"@types/mocha": "^9.1.1",
40-
"@types/tv4": "^1.2.31",
35+
"@babel/core": "^7.24.9",
36+
"@babel/preset-env": "^7.24.8",
37+
"@types/tv4": "^1.2.33",
4138
"@typescript-eslint/eslint-plugin": "^7.17.0",
4239
"@typescript-eslint/parser": "^7.17.0",
43-
"babel-loader": "^8.2.2",
40+
"babel-loader": "^9.1.3",
4441
"chai": "^4.3.6",
4542
"chai-as-promised": "^7.1.1",
4643
"esformatter": "^0.11.3",
4744
"eslint": "^8.23.1",
48-
"fetch-mock": "^9.11.0",
45+
"fetch-mock": "^10.1.1",
4946
"jaribu": "^2.2.3",
5047
"mocha": "^10.7.0",
51-
"sinon": "^14.0.0",
5248
"ts-loader": "^8.4.0",
49+
"sinon": "^18.0.0",
5350
"ts-node": "^10.9.2",
5451
"typedoc": "^0.26.5",
55-
"typedoc-plugin-markdown": "^4.2.2",
52+
"typedoc-plugin-markdown": "^4.2.3",
5653
"typedoc-vitepress-theme": "^1.0.1",
57-
"typescript": "^5.4.5",
54+
"typescript": "^5.5.4",
5855
"vitepress": "^1.3.1",
59-
"webpack": "^5.92.0",
56+
"webpack": "^5.93.0",
6057
"webpack-cli": "^5.1.4"
6158
},
6259
"dependencies": {

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = {
1717
// default config
1818
backgroundSyncInterval: 60000,
1919
disableFeatures: [],
20-
discoveryTimeout: 10000,
20+
discoveryTimeout: 5000,
2121
isBackground: false,
2222
requestTimeout: 30000,
2323
syncInterval: 10000

src/discover.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import WebFinger from 'webfinger.js';
44
import type { StorageInfo } from './interfaces/storage_info';
5+
import config from './config';
56
import log from './log';
67
import { globalContext, localStorageAvailable } from './util';
78

@@ -19,9 +20,9 @@ let cachedInfo = {};
1920
* This function deals with the Webfinger lookup, discovering a connecting
2021
* user's storage details.
2122
*
22-
* @param {string} userAddress - user@host or URL
23+
* @param userAddress - user@host or URL
2324
*
24-
* @returns {Promise} A promise for an object with the following properties.
25+
* @returns A promise for an object with the following properties.
2526
* href - Storage base URL,
2627
* storageApi - RS protocol version,
2728
* authUrl - OAuth URL,
@@ -38,9 +39,13 @@ const Discover = function Discover(userAddress: string): Promise<StorageInfo> {
3839
const webFinger = new WebFinger({
3940
tls_only: false,
4041
uri_fallback: true,
41-
request_timeout: 5000
42+
request_timeout: config.discoveryTimeout
4243
});
4344

45+
setTimeout(() => {
46+
return reject(new Error('timed out'));
47+
}, config.discoveryTimeout);
48+
4449
return webFinger.lookup(userAddress, function (err, response) {
4550
if (err) {
4651
return reject(err);

src/remotestorage.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,14 @@ export class RemoteStorage {
384384

385385
if (hasLocalStorage) {
386386
this.apiKeys = getJSONFromLocalStorage('remotestorage:api-keys') || {};
387-
this.setBackend(localStorage.getItem('remotestorage:backend') || 'remotestorage');
387+
388+
const backendType = localStorage.getItem('remotestorage:backend');
389+
390+
if (backendType === 'dropbox' || backendType === 'googledrive') {
391+
this.setBackend(backendType);
392+
} else {
393+
this.setBackend('remotestorage');
394+
}
388395
}
389396

390397
// Keep a reference to the orginal `on` function
@@ -568,12 +575,7 @@ export class RemoteStorage {
568575
});
569576
this._emit('connecting');
570577

571-
const discoveryTimeout = setTimeout((): void => {
572-
this._emit('error', new RemoteStorage.DiscoveryError("No storage information found for this user address."));
573-
}, config.discoveryTimeout);
574-
575578
Discover(userAddress).then((info: StorageInfo): void => {
576-
clearTimeout(discoveryTimeout);
577579
this._emit('authing');
578580
info.userAddress = userAddress;
579581
this.remote.configure(info);
@@ -599,7 +601,6 @@ export class RemoteStorage {
599601
}
600602
}
601603
}, (/*err*/) => {
602-
clearTimeout(discoveryTimeout);
603604
this._emit('error', new RemoteStorage.DiscoveryError("No storage information found for this user address."));
604605
});
605606
}
@@ -669,14 +670,14 @@ export class RemoteStorage {
669670
}
670671

671672
/**
672-
* TODO: document
673673
* @internal
674674
*/
675-
setBackend (what): void {
676-
this.backend = what;
675+
setBackend (backendType: 'remotestorage' | 'dropbox' | 'googledrive'): void {
676+
this.backend = backendType;
677+
677678
if (hasLocalStorage) {
678-
if (what) {
679-
localStorage.setItem('remotestorage:backend', what);
679+
if (typeof backendType !== 'undefined') {
680+
localStorage.setItem('remotestorage:backend', backendType);
680681
} else {
681682
localStorage.removeItem('remotestorage:backend');
682683
}

test/helpers/location.ts renamed to test/helpers/location.mjs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
21
class MockLocation {
3-
private _origin: string;
4-
private _pathname: string;
5-
private _search: string;
6-
private _hash: string;
7-
82
constructor(url) {
93
this.href = url;
4+
this._origin = null;
5+
this._pathname = null;
6+
this._search = null;
7+
this._hash = null;
108
}
119

1210
toString() {
@@ -86,7 +84,7 @@ class MockLocation {
8684

8785
export default function locationFactory(url) {
8886
if (!('document' in globalThis)) {
89-
globalThis["document"] = {} as Document;
87+
globalThis["document"] = {};
9088
}
91-
globalThis.document.location = new MockLocation(url) as unknown as Location;
89+
globalThis.document.location = new MockLocation(url);
9290
}

test/helpers/memoryStorage.ts renamed to test/helpers/memoryStorage.mjs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import {getGlobalContext} from "../../src/util";
2-
3-
class MemoryStorage {
4-
protected map: Map<string, string>;
1+
import { getGlobalContext } from "../../build/util.js";
52

3+
export class MemoryStorage {
64
constructor() {
75
this.map = new Map();
86
}
@@ -11,7 +9,7 @@ class MemoryStorage {
119
return this.map.size;
1210
}
1311

14-
key(index: number): string | null {
12+
key(index) {
1513
const a = Array.from(this.map.keys());
1614
if (index < a.length) {
1715
return a[index];
@@ -20,23 +18,23 @@ class MemoryStorage {
2018
}
2119
}
2220

23-
getItem(key: string): string | null {
21+
getItem(key) {
2422
if (this.map.has(key)) {
2523
return this.map.get(key);
2624
} else {
2725
return null;
2826
}
2927
}
3028

31-
setItem(key: string, value: string): void {
29+
setItem(key, value) {
3230
this.map.set(key, value);
3331
}
3432

35-
removeItem(key: string): void {
33+
removeItem(key) {
3634
this.map.delete(key);
3735
}
3836

39-
clear(): void {
37+
clear() {
4038
this.map.clear();
4139
}
4240

@@ -57,4 +55,4 @@ if (context.sessionStorage) {
5755
context.sessessionStorage = sessionStorage = new MemoryStorage();
5856
}
5957

60-
export {localStorage, sessionStorage};
58+
export { localStorage, sessionStorage };

0 commit comments

Comments
 (0)