Commit graph

38 commits

Author SHA1 Message Date
MiroslavDionisiev
41816e448c fix: fix failing specs 2025-01-06 17:40:07 +02:00
Georgi Angelov
4bb2a15b74 chore: fix a test referencing the old default export 2024-10-23 12:56:25 +03:00
Georgi Angelov
453266c604 chore: add types 2024-10-10 17:47:08 +03:00
Georgi Angelov
3d0b429526 feat!: upgrade webpack to 5 and add TS support
Breaking flag is because it may have some differences in the way the library is exported -
`module.exports = ` vs `module.exports.default = `. That would depend on the Webpack config,
so it should continue working, but just to be safe.
2024-10-10 11:45:50 +03:00
Christopher Willis-Ford
dff5d46217 test: verify default asset sizes
This checks for things like accidentally using the filename as the file
content, etc.
2023-10-05 14:45:31 -07:00
Christopher Willis-Ford
e896ce4759 test: add '?scratchMetadata=1' in metadata test 2023-09-29 14:09:20 -07:00
Christopher Willis-Ford
322ae0b166 test: fix transformer for backslashes
Injecting the path into the "code" was causing the backslashes to be
interpreted as escape characters instead of path separators. I could
have escaped them, but this approach is more similar to what Webpack
does with `arraybuffer-loader` and (IMO) easier to read.
2023-05-02 14:57:36 -07:00
Christopher Willis-Ford
a7999828b5 test: mock cross-fetch for download-known-assets, too 2023-05-02 13:41:17 -07:00
Christopher Willis-Ford
f6a263d8c1 test: convert all tests from node-tap to jest 2023-05-02 09:09:23 -07:00
Christopher Willis-Ford
d4385b2fd1 test: wait for checkAsset in load-default-assets tests 2023-05-01 16:19:55 -07:00
Christopher Willis-Ford
c593eec408 test: add test for case sensitivity in metadata keys 2023-03-30 11:27:57 -07:00
Christopher Willis-Ford
3e6bc844e7 refactor: turn mockFetch into a full module mock
This should make it harder to make a mistake mocking `cross-fetch` again
2023-03-30 09:29:52 -07:00
Christopher Willis-Ford
64b3b713ba test: mock cross-fetch more completely
Also emphasize that the `Headers` class used in `scratchFetch.js` comes
from `cross-fetch`
2023-03-30 09:09:19 -07:00
Christopher Willis-Ford
8dd89a6a98 feat: allow removing request metadata 2023-03-09 14:23:11 -08:00
Christopher Willis-Ford
2a4c4892c4 feat: allow adding metadata to scratchFetch 2023-03-09 13:39:24 -08:00
Christopher Willis-Ford
3283740a04 chore: insert scratchFetch into FetchTool's pipeline 2023-03-09 13:39:24 -08:00
Christopher Willis-Ford
fd6f3a166a refactor: use cross-fetch instead of node-fetch
Previously, we had Webpack's ProvidePlugin injecting `node-fetch` as a
polyfill into Node builds, and web builds just relied on the `fetch`
built into the browser (if it's there).

Now, we use `cross-fetch` everywhere, and as a ponyfill instead of a
polyfill. This broke the unit tests in `fetch-tool.js` because they were
overriding `global.fetch` to mock `node-fetch`. Now, those tests use
`tap.mock` to mock `cross-fetch`. Of course, `tap.mock` didn't exist in
the old version of `node-tap`, so I also upgraded that.
2023-03-09 13:39:24 -08:00
Christopher Willis-Ford
27d73b6888 test: stop using deprecated methods 2023-03-02 13:32:50 -08:00
Christopher Willis-Ford
c183e7da53 test: fix and modernize tests 2023-03-02 13:30:35 -08:00
Karishma Chadha
975f2fa022 test(fetchtool): update tests to handle promise reject and resolve 2022-05-18 16:02:14 -04:00
Karishma Chadha
81679aa533 fix(fetchtool): create Uint8Array on promise result instead of promise
We were previously calling new Uint8Array on a promise instead of the result of the promise
2022-05-17 16:05:28 -04:00
Karishma Chadha
d551cf2c6e test(fetchtool): test handling 404 response to get request
Add a test that FetchTool.get resolves null when it encounters a 404 for the get request
2022-05-17 15:12:38 -04:00
Andrey Nikitin
0e52c4a2a4 fix(fetchtool): catch fetch exception on get resource 2022-05-16 10:57:25 -04:00
Christopher Willis-Ford
479641625e fix(tests): remove 'fetch' workaround
This workaround was making the tests pass even when `fetch` was
undefined. That made sense if you assume that the only Node-based
clients of `scratch-storage` are its own tests, but it doesn't help (for
example) Node-based tests in `scratch-vm`. Since we now ensure that
`fetch` is polyfilled for Node, this workaround is no longer necessary.
2022-05-09 08:53:38 -07:00
Ben Wheeler
21469a59ad chore: update promise reject parameter to avoid lint error 2020-12-18 21:18:09 -05:00
adroitwhiz
a4a5f10deb
Merge pull request from adroitwhiz/node-fetch
Remove NetsTool and nets dependency
2020-06-02 15:51:16 -04:00
adroitwhiz
7f62d2303a refactor: remove NetsTool 2019-11-11 18:20:24 -05:00
Paul Kaplan
90c711be04 fix: return status code from fetch send failures like the nets tool
fix 
2019-08-22 11:33:50 -04:00
Paul Kaplan
22af3bb898 fix: set a "clean" flag on assets 2018-12-21 12:51:15 -05:00
Christopher Willis-Ford
c7bba01e0e test: refine addHelper tests
These changes break the `addHelper` tests into several phases which don't share state, and hopefully
improve readability of the tests.
2018-10-31 14:27:59 -07:00
Christopher Willis-Ford
90a1510822 test: add tests for addHelper priority values
This new test verifies that helpers are used in the correct order, corresponding to the priority
value provided to `addHelper`.
2018-10-24 11:38:40 -07:00
Ray Schamp
b60847cc99 chore(lint): lint 2018-10-24 10:58:37 +01:00
Paul Kaplan
cbd4634c3e fix(dependencies): Replace crypto with js-md5 package 2017-10-13 12:22:19 -04:00
Christopher Willis-Ford
19f4699ac4 feat(load): Allow caller to specify data format for an asset fetch
When calling `load`, you may now explicitly state a data format / file extension. If you don't
specify one, the default for that asset type will be used.

Resolves 
2017-05-24 16:31:53 -07:00
Christopher Willis-Ford
b570ff9a39 Fix tests for no-loop-func lint rule 2017-04-21 09:25:51 -07:00
Christopher Willis-Ford
c742a74a52 Add Asset and AssetType to storage instance
Actually, to the prototype. This allows consumers of this module to
access `Asset` and `AssetType` without having to `require` the storage
module itself.
2017-04-20 16:13:40 -07:00
Christopher Willis-Ford
d0a957098a Build for Node.js 4.x, make tests compatible 2017-03-17 15:13:53 -07:00
Christopher Willis-Ford
2b28f27049 Add tests, fix problems found by those tests
Changes include:
- Use `bin-loader` instead of `arraybuffer-loader` since the latter is
  only compatible with browsers, not with Node itself.
- Use `got` instead of `xhr` since `xhr` only works in browsers and
  `got` is nicer anyway.
- Add `json-loader` to Webpack config since `got` requires it.
- Use lower-case values in `DataFormat` to match canonical file names.
- Update `ScratchStorage.addWebSource` to match `WebHelper`'s new API.
- Fix an error in the web helper which was causing an infinite loop on
  error.
2016-12-08 16:45:56 -08:00