Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies, switch Mocha tests from TS to JS #1318

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci --force
run: npm ci
- name: Run jaribu tests # These must be replaced before we can use Node v18 in CI
run: npm test
- name: Run mocha tests
Expand Down
9 changes: 0 additions & 9 deletions .mocharc.js

This file was deleted.

4,742 changes: 2,634 additions & 2,108 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"homepage": "https://remotestorage.io",
"scripts": {
"test": "tsc && bash scripts/test-all.sh",
"test:mocha": "mocha test/unit/*.test.ts",
"test:watch": "mocha test/unit/*.test.ts --watch --reporter dot",
"test:mocha": "mocha test/unit/*.test.mjs",
"test:watch": "mocha test/unit/*.test.mjs --watch --reporter dot",
"lint": "eslint --ext=ts src/",
"lint:quiet": "eslint --quiet --ext=ts src/",
"lint:specs": "eslint test/unit/*.ts",
"lint:specs:quiet": "eslint --quiet test/unit/*.ts",
"lint:specs": "eslint test/unit/*.mjs",
"lint:specs:quiet": "eslint --quiet test/unit/*.mjs",
"format": "esformatter --config esformatter-config.json -i src/sync.js",
"build:js": "tsc -d --declarationDir release/types --declarationMap",
"build:release": "NODE_ENV=production webpack --mode=production",
Expand All @@ -32,31 +32,28 @@
"docs:preview": "vitepress preview docs"
},
"devDependencies": {
"@babel/core": "^7.19.0",
"@babel/preset-env": "^7.19.0",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^9.1.1",
"@types/tv4": "^1.2.31",
"@babel/core": "^7.24.9",
"@babel/preset-env": "^7.24.8",
"@types/tv4": "^1.2.33",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"babel-loader": "^8.2.2",
"babel-loader": "^9.1.3",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"esformatter": "^0.11.3",
"eslint": "^8.23.1",
"fetch-mock": "^9.11.0",
"fetch-mock": "^10.1.1",
"jaribu": "^2.2.3",
"mocha": "^10.7.0",
"sinon": "^14.0.0",
"ts-loader": "^8.4.0",
"sinon": "^18.0.0",
"ts-node": "^10.9.2",
"typedoc": "^0.26.5",
"typedoc-plugin-markdown": "^4.2.2",
"typedoc-plugin-markdown": "^4.2.3",
"typedoc-vitepress-theme": "^1.0.1",
"typescript": "^5.4.5",
"typescript": "^5.5.4",
"vitepress": "^1.3.1",
"webpack": "^5.92.0",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = {
// default config
backgroundSyncInterval: 60000,
disableFeatures: [],
discoveryTimeout: 10000,
discoveryTimeout: 5000,
isBackground: false,
requestTimeout: 30000,
syncInterval: 10000
Expand Down
11 changes: 8 additions & 3 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import WebFinger from 'webfinger.js';
import type { StorageInfo } from './interfaces/storage_info';
import config from './config';
import log from './log';
import { globalContext, localStorageAvailable } from './util';

Expand All @@ -19,9 +20,9 @@ let cachedInfo = {};
* This function deals with the Webfinger lookup, discovering a connecting
* user's storage details.
*
* @param {string} userAddress - user@host or URL
DougReeder marked this conversation as resolved.
Show resolved Hide resolved
* @param userAddress - user@host or URL
*
* @returns {Promise} A promise for an object with the following properties.
* @returns A promise for an object with the following properties.
* href - Storage base URL,
* storageApi - RS protocol version,
* authUrl - OAuth URL,
Expand All @@ -38,9 +39,13 @@ const Discover = function Discover(userAddress: string): Promise<StorageInfo> {
const webFinger = new WebFinger({
tls_only: false,
uri_fallback: true,
request_timeout: 5000
request_timeout: config.discoveryTimeout
});

setTimeout(() => {
return reject(new Error('timed out'));
}, config.discoveryTimeout);

return webFinger.lookup(userAddress, function (err, response) {
if (err) {
return reject(err);
Expand Down
25 changes: 13 additions & 12 deletions src/remotestorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,14 @@ export class RemoteStorage {

if (hasLocalStorage) {
this.apiKeys = getJSONFromLocalStorage('remotestorage:api-keys') || {};
this.setBackend(localStorage.getItem('remotestorage:backend') || 'remotestorage');

const backendType = localStorage.getItem('remotestorage:backend');

if (backendType === 'dropbox' || backendType === 'googledrive') {
this.setBackend(backendType);
} else {
this.setBackend('remotestorage');
}
}

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

const discoveryTimeout = setTimeout((): void => {
this._emit('error', new RemoteStorage.DiscoveryError("No storage information found for this user address."));
}, config.discoveryTimeout);

Discover(userAddress).then((info: StorageInfo): void => {
clearTimeout(discoveryTimeout);
this._emit('authing');
info.userAddress = userAddress;
this.remote.configure(info);
Expand All @@ -599,7 +601,6 @@ export class RemoteStorage {
}
}
}, (/*err*/) => {
clearTimeout(discoveryTimeout);
this._emit('error', new RemoteStorage.DiscoveryError("No storage information found for this user address."));
});
}
Expand Down Expand Up @@ -669,14 +670,14 @@ export class RemoteStorage {
}

/**
* TODO: document
* @internal
*/
setBackend (what): void {
this.backend = what;
setBackend (backendType: 'remotestorage' | 'dropbox' | 'googledrive'): void {
this.backend = backendType;

if (hasLocalStorage) {
if (what) {
localStorage.setItem('remotestorage:backend', what);
if (typeof backendType !== 'undefined') {
localStorage.setItem('remotestorage:backend', backendType);
} else {
localStorage.removeItem('remotestorage:backend');
}
Expand Down
14 changes: 6 additions & 8 deletions test/helpers/location.ts → test/helpers/location.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

class MockLocation {
private _origin: string;
private _pathname: string;
private _search: string;
private _hash: string;

constructor(url) {
this.href = url;
this._origin = null;
this._pathname = null;
this._search = null;
this._hash = null;
}

toString() {
Expand Down Expand Up @@ -86,7 +84,7 @@ class MockLocation {

export default function locationFactory(url) {
if (!('document' in globalThis)) {
globalThis["document"] = {} as Document;
globalThis["document"] = {};
}
globalThis.document.location = new MockLocation(url) as unknown as Location;
globalThis.document.location = new MockLocation(url);
}
18 changes: 8 additions & 10 deletions test/helpers/memoryStorage.ts → test/helpers/memoryStorage.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {getGlobalContext} from "../../src/util";

class MemoryStorage {
protected map: Map<string, string>;
import { getGlobalContext } from "../../build/util.js";

export class MemoryStorage {
constructor() {
this.map = new Map();
}
Expand All @@ -11,7 +9,7 @@ class MemoryStorage {
return this.map.size;
}

key(index: number): string | null {
key(index) {
const a = Array.from(this.map.keys());
if (index < a.length) {
return a[index];
Expand All @@ -20,23 +18,23 @@ class MemoryStorage {
}
}

getItem(key: string): string | null {
getItem(key) {
if (this.map.has(key)) {
return this.map.get(key);
} else {
return null;
}
}

setItem(key: string, value: string): void {
setItem(key, value) {
this.map.set(key, value);
}

removeItem(key: string): void {
removeItem(key) {
this.map.delete(key);
}

clear(): void {
clear() {
this.map.clear();
}

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

export {localStorage, sessionStorage};
export { localStorage, sessionStorage };
Loading