jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 215 forks source link

Support for window.fetch #185

Closed billiegoose closed 6 years ago

billiegoose commented 6 years ago

I'm starting to work on issue #182 . It's very basic right now. , and I haven't tested to see if it works. I also can't get npm test to run on my machine so I'm relying on Travis for feedback.

TODOs

billiegoose commented 6 years ago

Oh what fun: your Travis is running on precise and mine is running on trusty - your Firefox 30 didn't have "fetch" and the tests failed, my Firefox 50 does have fetch but failed for some other reason. This is really great for testing!

jvilk commented 6 years ago

@wmhilton isn't it, though? 😄 That's why I have it all configured!

Why isn't npm test running? It should run on all major operating systems (Mac/Linux/Windows). That should be filed as a bug!

jvilk commented 6 years ago

I added some things to your TODOs. For the purpose of testing, we should have an option to explicitly disable fetch that defaults to whether or not fetch is available (e.g. !!global.fetch). You should modify the xhr_factory in the test folder to create variants with this option on and off.

That means the selection of which helper to use from xhr.ts will be decided by the file system, and not at initialization time like it is now. To avoid redundant conditionals (e.g. if (shouldFetch) all over the code), you can add private fields to the file system that save a reference to the chosen method of fetching / getting the size of files at file system construction time.

billiegoose commented 6 years ago

Newly refactored code:

billiegoose commented 6 years ago

New changes:

jvilk commented 6 years ago

(I added two more super picky comments that you don't have to address.)

billiegoose commented 6 years ago

I'm sure this is just my lack of familiarity with karma, but I can't figure out what/where/how to modify the tests to add a "preferXHR: false" variant. Any chance you could add that? Also, what do you think of the current code? I think I addressed all your feedback points, but you might still find ways to improve it.

jvilk commented 6 years ago

It's not in Karma! There are TypeScript files that create multiple variants of each file system for testing (hence, they are 'factories').

The following is the one for XHRFS, which currently has two variants (listing URL passed to Create() which is async, listing URL passed to constructor which is sync but will be removed in next major revision):

https://github.com/jvilk/BrowserFS/blob/master/test/harness/factories/xhrfs_factory.ts#L4

I'd like you to modify the test so that:

Make sense?

That's my last request!

jvilk commented 6 years ago

@wmhilton I just did the big 2.0 merge. I promise that's the last churn on this pull request!

This feature will go into the first 2.0 release.

Let me know if you've given up on the final few changes, and I will solve the merge conflicts and add the needed test changes.

billiegoose commented 6 years ago

Let me know if you've given up on the final few changes, and I will solve the merge conflicts and add the needed test changes.

Could you? I keep squinting at the code in xhrfs_factory.ts and I see how there are branches (the if statements) but I don't actually see how that turns into two test variants. Wait, unless... is the cb being used to append a test to the end of a hidden queue rather than being a continuation? 🤔

Um... I'm sorry @jvilk I just don't have enough experience for it to click. If you add the test, and then I look at the diff, I'm sure I'll slap my head and say "doh!" but right now I'd just be shooting in the dark.

jvilk commented 6 years ago

@wmhilton All merged! You can check out the changes I made if you want. I'll get on the other tasks before the 2.0 release (e.g. the rename, maintaining backwards compat, etc).