File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ export function createStorage<T extends StorageValue>(
231
231
async setItems ( items , commonOptions ) {
232
232
await runBatch ( items , commonOptions , async ( batch ) => {
233
233
if ( batch . driver . setItems ) {
234
- await asyncCall (
234
+ return asyncCall (
235
235
batch . driver . setItems ,
236
236
batch . items . map ( ( item ) => ( {
237
237
key : item . relativeKey ,
Original file line number Diff line number Diff line change @@ -160,3 +160,33 @@ describe("utils", () => {
160
160
expect ( async ( ) => await storage . setItem ( "foo" , [ ] ) ) . not . toThrow ( ) ;
161
161
} ) ;
162
162
} ) ;
163
+
164
+ describe ( "Regression" , ( ) => {
165
+ it ( "setItems doeesn't upload twice" , async ( ) => {
166
+ /**
167
+ * https://github.com/unjs/unstorage/pull/392
168
+ */
169
+
170
+ const setItem = vi . fn ( ) ;
171
+ const setItems = vi . fn ( ) ;
172
+
173
+ const driver = memory ( ) ;
174
+ const storage = createStorage ( {
175
+ driver : {
176
+ ...driver ,
177
+ setItem : ( ...args ) => {
178
+ setItem ( ...args ) ;
179
+ return driver . setItem ?.( ...args ) ;
180
+ } ,
181
+ setItems : ( ...args ) => {
182
+ setItems ( ...args ) ;
183
+ return driver . setItems ?.( ...args ) ;
184
+ } ,
185
+ } ,
186
+ } ) ;
187
+
188
+ await storage . setItems ( [ { key : "foo.txt" , value : "bar" } ] ) ;
189
+ expect ( setItem ) . toHaveBeenCalledTimes ( 0 ) ;
190
+ expect ( setItems ) . toHaveBeenCalledTimes ( 1 ) ;
191
+ } ) ;
192
+ } ) ;
You can’t perform that action at this time.
0 commit comments