Skip to content

Commit 5c2405a

Browse files
committed
Add initial setup for ResourceLoader.js tests
- Created package.json with dependencies for testing - Added vitest and jsdom for testing environment - Implemented tests for ResourceLoader.js including resource loading, error handling, and JSON fetching
1 parent f1dcec0 commit 5c2405a

7 files changed

Lines changed: 3010 additions & 578 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ ResourceLoader.include(['https://example.com/script.js'], {
135135
- `crossorigin`: Set cross-origin for JS/CSS resources.
136136
- `attributes`: Additional attributes to set on the element (e.g., integrity).
137137

138+
Returns a Promise that resolves with an array of per-resource results when all resources succeed:
139+
140+
```javascript
141+
[
142+
{ status: 'fulfilled', value: 'https://example.com/script.js' },
143+
];
144+
```
145+
146+
If any resource fails, the Promise rejects with an aggregate error:
147+
148+
```javascript
149+
{
150+
type: 'aggregate',
151+
message: 'One or more resources failed to load.',
152+
results: [
153+
{ status: 'fulfilled', value: 'https://example.com/good.css' },
154+
{ status: 'rejected', reason: { type: 'network', message: '...' }, url: 'https://example.com/bad.css' }
155+
]
156+
}
157+
```
158+
138159
### `unloadResource(url)`
139160

140161
Unloads a resource from the page.
@@ -171,3 +192,12 @@ console.log(state); // "loaded"
171192
## License
172193

173194
This project is licensed under the MIT License.
195+
196+
## Testing
197+
198+
Run tests from the repository root:
199+
200+
```bash
201+
npm install
202+
npm test
203+
```

0 commit comments

Comments
 (0)