@sprucelabs/spruce-file-utils 16.0.2 → 16.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,8 @@ import { UploadedFile } from '../files.types';
|
|
3
3
|
import { ChunkingUploader, ChunkingUploaderEventContract, UploadOptions } from './ChunkingUploader';
|
4
4
|
export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingUploaderEventContract> implements ChunkingUploader {
|
5
5
|
static instance?: MockChunkingUploader;
|
6
|
+
private nameToSlow?;
|
7
|
+
static setTimeout(cb: () => void, ms: number): void;
|
6
8
|
private lastUploadOptions?;
|
7
9
|
private lastUploadResponse?;
|
8
10
|
private fakedResponse?;
|
@@ -11,7 +13,8 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
|
|
11
13
|
constructor();
|
12
14
|
static assertWasCreated(): void;
|
13
15
|
assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
|
14
|
-
assertUploadOptionsEqual(options
|
16
|
+
assertUploadOptionsEqual(options?: UploadOptions): void;
|
17
|
+
simulateSlowUploadForFileNamed(name: string): void;
|
15
18
|
setUploadResponses(responses: UploadedFile[]): void;
|
16
19
|
setUploadResponse(options: UploadedFile): void;
|
17
20
|
upload(options: UploadOptions): Promise<{
|
@@ -12,6 +12,9 @@ import { assertOptions } from '@sprucelabs/schema';
|
|
12
12
|
import { assert, generateId } from '@sprucelabs/test-utils';
|
13
13
|
import { chunkingUploaderEventContract, } from './ChunkingUploader.js';
|
14
14
|
export default class MockChunkingUploader extends AbstractEventEmitter {
|
15
|
+
static setTimeout(cb, ms) {
|
16
|
+
setTimeout(cb, ms);
|
17
|
+
}
|
15
18
|
constructor() {
|
16
19
|
super(chunkingUploaderEventContract);
|
17
20
|
this.fakedResponses = [];
|
@@ -26,9 +29,11 @@ export default class MockChunkingUploader extends AbstractEventEmitter {
|
|
26
29
|
assert.isEqualDeep(file, this.lastUploadResponse, 'Files do not match');
|
27
30
|
}
|
28
31
|
assertUploadOptionsEqual(options) {
|
29
|
-
assertOptions(options, ['fileName', 'base64']);
|
30
32
|
assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
|
31
33
|
}
|
34
|
+
simulateSlowUploadForFileNamed(name) {
|
35
|
+
this.nameToSlow = name;
|
36
|
+
}
|
32
37
|
setUploadResponses(responses) {
|
33
38
|
assertOptions({ responses }, ['responses']);
|
34
39
|
this.fakedResponses = responses;
|
@@ -42,6 +47,11 @@ export default class MockChunkingUploader extends AbstractEventEmitter {
|
|
42
47
|
this.lastUploadOptions = options;
|
43
48
|
this.currentResponse++;
|
44
49
|
this.lastUploadResponse = this.getCurrentResponse();
|
50
|
+
if (this.nameToSlow === options.fileName) {
|
51
|
+
yield new Promise((r) => {
|
52
|
+
MockChunkingUploader.setTimeout(() => r(undefined), 25);
|
53
|
+
});
|
54
|
+
}
|
45
55
|
return {
|
46
56
|
file: this.lastUploadResponse,
|
47
57
|
};
|
@@ -3,6 +3,8 @@ import { UploadedFile } from '../files.types';
|
|
3
3
|
import { ChunkingUploader, ChunkingUploaderEventContract, UploadOptions } from './ChunkingUploader';
|
4
4
|
export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingUploaderEventContract> implements ChunkingUploader {
|
5
5
|
static instance?: MockChunkingUploader;
|
6
|
+
private nameToSlow?;
|
7
|
+
static setTimeout(cb: () => void, ms: number): void;
|
6
8
|
private lastUploadOptions?;
|
7
9
|
private lastUploadResponse?;
|
8
10
|
private fakedResponse?;
|
@@ -11,7 +13,8 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
|
|
11
13
|
constructor();
|
12
14
|
static assertWasCreated(): void;
|
13
15
|
assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
|
14
|
-
assertUploadOptionsEqual(options
|
16
|
+
assertUploadOptionsEqual(options?: UploadOptions): void;
|
17
|
+
simulateSlowUploadForFileNamed(name: string): void;
|
15
18
|
setUploadResponses(responses: UploadedFile[]): void;
|
16
19
|
setUploadResponse(options: UploadedFile): void;
|
17
20
|
upload(options: UploadOptions): Promise<{
|
@@ -5,6 +5,9 @@ const schema_1 = require("@sprucelabs/schema");
|
|
5
5
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
6
6
|
const ChunkingUploader_1 = require("./ChunkingUploader");
|
7
7
|
class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter {
|
8
|
+
static setTimeout(cb, ms) {
|
9
|
+
setTimeout(cb, ms);
|
10
|
+
}
|
8
11
|
constructor() {
|
9
12
|
super(ChunkingUploader_1.chunkingUploaderEventContract);
|
10
13
|
this.fakedResponses = [];
|
@@ -19,9 +22,11 @@ class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter
|
|
19
22
|
test_utils_1.assert.isEqualDeep(file, this.lastUploadResponse, 'Files do not match');
|
20
23
|
}
|
21
24
|
assertUploadOptionsEqual(options) {
|
22
|
-
(0, schema_1.assertOptions)(options, ['fileName', 'base64']);
|
23
25
|
test_utils_1.assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
|
24
26
|
}
|
27
|
+
simulateSlowUploadForFileNamed(name) {
|
28
|
+
this.nameToSlow = name;
|
29
|
+
}
|
25
30
|
setUploadResponses(responses) {
|
26
31
|
(0, schema_1.assertOptions)({ responses }, ['responses']);
|
27
32
|
this.fakedResponses = responses;
|
@@ -34,6 +39,11 @@ class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter
|
|
34
39
|
this.lastUploadOptions = options;
|
35
40
|
this.currentResponse++;
|
36
41
|
this.lastUploadResponse = this.getCurrentResponse();
|
42
|
+
if (this.nameToSlow === options.fileName) {
|
43
|
+
await new Promise((r) => {
|
44
|
+
MockChunkingUploader.setTimeout(() => r(undefined), 25);
|
45
|
+
});
|
46
|
+
}
|
37
47
|
return {
|
38
48
|
file: this.lastUploadResponse,
|
39
49
|
};
|