Problems with Karma and unit tests, and Dynamic loading and garbage-collecting BrowserFS
Hi - I have two "issues" - one or both could be a result of "I'm a newbie and I know it" and not a real issue.
First - This is a special use case:
- I want to load BrowserFS in order to load in configuration files
- After loading configuration files I want to release the module so garbage collection can reclain
In other words, after the initial loading of the configuration files, I never have further need of the file system.
Do I already get this behavior by releasing the local object I originally use for BrowserFS.install(<localObject>)? At first blush with a 2-minute scan of the core code, it looks like the answer is 'yes'. But I'm deferring to other's better understanding of the code due to my unfortunate lack of time.
If the answer to the above question is 'no', is this doable (without breaking the bank)?
Second:
I am having trouble getting BrowserFS loaded through Karma for unit-testing. I have the documented additions as specified for webpack as part of the webpack object in karma.config.js
It would greatly help if the documentation had a clear and simple example on how to use something like fs.readFileSync(...) in Javascript/Typescript when you're not using a
For example, in Typescript 3.1.6 - I'm trying:
import * as BrowserFS from 'browserfs';
Then in the constructor:
```BrowserFS.install(this.browserFS);
this.fs = require('fs');```
Getting:
on file for 'dropboxjs'.
20 11 2018 04:19:16.962:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(18,13): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.963:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(44,25): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.964:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(54,68): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.965:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(59,21): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.966:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(65,51): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.969:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Dropbox.d.ts(93,18): error TS2503: Cannot find namespace 'D
ropbox'.
20 11 2018 04:19:16.970:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Emscripten.d.ts(19,19): error TS2304: Cannot find name 'Nod
eBuffer'.
20 11 2018 04:19:16.971:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Emscripten.d.ts(20,23): error TS2304: Cannot find name 'Nod
eBuffer'.
20 11 2018 04:19:16.972:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Emscripten.d.ts(21,18): error TS2304: Cannot find name 'Nod
eBuffer'.
20 11 2018 04:19:16.973:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/Emscripten.d.ts(22,22): error TS2304: Cannot find name 'Nod
eBuffer'.
20 11 2018 04:19:16.974:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/HTML5FS.d.ts(1,23): error TS2688: Cannot find type definiti
on file for 'filesystem'.
20 11 2018 04:19:16.974:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/HTML5FS.d.ts(10,37): error TS2304: Cannot find name 'FileEn
try'.
20 11 2018 04:19:16.976:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/HTML5FS.d.ts(32,9): error TS2304: Cannot find name 'FileSys
tem'.
20 11 2018 04:19:16.977:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/backend/IndexedDB.d.ts(18,5): error TS2416: Property 'put' in type
'IndexedDBRWTransaction' is not assignable to the same property in base type 'AsyncKeyValueRWTransaction'.
Type '(key: string, data: Buffer, overwrite: boolean, cb: BFSCallback<boolean>) => void' is not assignable to type '(key: string, data: Buffer, overwrite: bo
olean, cb: (e: ApiError, committed?: boolean | undefined) => void) => void'.
Types of parameters 'cb' and 'cb' are incompatible.
Types of parameters 'e' and 'e' are incompatible.
Type 'ApiError | null | undefined' is not assignable to type 'ApiError'.
Type 'undefined' is not assignable to type 'ApiError'.
20 11 2018 04:19:16.978:ERROR [compiler.karma-typescript]: node_modules/browserfs/dist/node/core/node_fs_stats.d.ts(18,22): error TS2720: Class 'import("C:/pro
jects/datafences/node_modules/browserfs/dist/node/core/node_fs_stats").default' incorrectly implements class 'import("fs").Stats'. Did you mean to extend 'impo
rt("fs").Stats' and inherit its members as a subclass?
Property 'atimeMs' is missing in type 'Stats'.
I'm obviously missing something. What?
Do I already get this behavior by releasing the local object I originally use for BrowserFS.install()?
Since the installed file system is global, I believe you'll need to install an empty file system so that BrowserFS will release the one you installed previously. That's the only reference to your file system that BrowserFS retains.
It would greatly help if the documentation had a clear and simple example on how to use something like fs.readFileSync(...) in Javascript/Typescript when you're not using a
I think your logic works, but it looks like you're receiving a compilation error because Karma is trying to run the TypeScript compiler on BrowserFS's source. Can you use the compiled JS source instead? Or, if you're using 1.4.3, does 2.0 work for you?
Closing this as stale and invalid (since we are moving away from using karma)