Skip to content

Commit b4b2fdf

Browse files
committed
Fix tests
1 parent 10d9db6 commit b4b2fdf

File tree

3 files changed

+62
-61
lines changed

3 files changed

+62
-61
lines changed

packages/storage/src/implementation/request.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ class NetworkRequest<T> implements Request<T> {
136136
xhr
137137
.send(self.url_, self.method_, self.body_, self.headers_)
138138
.then((xhr: XhrIo) => {
139-
console.log('response');
140-
console.log(xhr);
141139
if (self.progressCallback_ !== null) {
142140
xhr.removeUploadProgressListener(progressListener);
143141
}

packages/storage/test/unit/reference.exp.test.ts

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ function makeStorage(url: string): Reference {
5555
return new Reference(service, url);
5656
}
5757

58+
function withFakeSend(
59+
testFn: (text: string) => void,
60+
resolveFn: () => void
61+
): Reference {
62+
function newSend(
63+
xhrio: TestingXhrIo,
64+
url: string,
65+
method: string,
66+
body?: ArrayBufferView | Blob | string | null,
67+
headers?: Headers
68+
): void {
69+
(body as Blob).text().then(text => {
70+
testFn(text);
71+
xhrio.abort();
72+
resolveFn();
73+
});
74+
}
75+
const service = makeFakeService(
76+
testShared.fakeApp,
77+
testShared.fakeAuthProvider,
78+
newSend
79+
);
80+
return ref(service, 'gs://test-bucket');
81+
}
82+
5883
describe('Firebase Storage > Reference', () => {
5984
const root = makeStorage('gs://test-bucket/');
6085
const child = makeStorage('gs://test-bucket/hello');
@@ -227,55 +252,44 @@ describe('Firebase Storage > Reference', () => {
227252
});
228253

229254
describe('uploadString', () => {
230-
it('Uses metadata.contentType for RAW format', async () => {
255+
it('Uses metadata.contentType for RAW format', done => {
231256
// Regression test for b/30989476
232-
const snapshot = await uploadString(child, 'hello', StringFormat.RAW, {
257+
const root = withFakeSend((text: string) => {
258+
expect(text).to.include('"contentType":"lol/wut"');
259+
}, done);
260+
uploadString(ref(root, 'test'), 'hello', StringFormat.RAW, {
233261
contentType: 'lol/wut'
234262
} as Metadata);
235-
expect(snapshot.metadata.contentType).to.equal('lol/wut');
236-
});
237-
// it('Uses embedded content type in DATA_URL format', async () => {
238-
// const snapshot = await uploadString(
239-
// child,
240-
// 'data:lol/wat;base64,aaaa',
241-
// StringFormat.DATA_URL
242-
// );
243-
// expect(snapshot.metadata.contentType).to.equal('lol/wat');
244-
// });
245-
// it('Lets metadata.contentType override embedded content type in DATA_URL format', async () => {
246-
// const snapshot = await uploadString(
247-
// child,
248-
// 'data:ignore/me;base64,aaaa',
249-
// StringFormat.DATA_URL,
250-
// { contentType: 'tomato/soup' } as Metadata
251-
// );
252-
// expect(snapshot.metadata.contentType).to.equal('tomato/soup');
253-
// });
263+
});
264+
it('Uses embedded content type in DATA_URL format', done => {
265+
const root = withFakeSend((text: string) => {
266+
expect(text).to.include('"contentType":"lol/wat"');
267+
}, done);
268+
uploadString(
269+
ref(root, 'test'),
270+
'data:lol/wat;base64,aaaa',
271+
StringFormat.DATA_URL
272+
);
273+
});
274+
it('Lets metadata.contentType override embedded content type in DATA_URL format', done => {
275+
const root = withFakeSend((text: string) => {
276+
expect(text).to.include('"contentType":"tomato/soup"');
277+
}, done);
278+
uploadString(
279+
ref(root, 'test'),
280+
'data:ignore/me;base64,aaaa',
281+
StringFormat.DATA_URL,
282+
{ contentType: 'tomato/soup' } as Metadata
283+
);
284+
});
254285
});
255286

256-
describe.only('uploadBytes', () => {
257-
it('Uses metadata.contentType', async () => {
258-
function newSend(
259-
xhrio: TestingXhrIo,
260-
url: string,
261-
method: string,
262-
body?: ArrayBufferView | Blob | string | null,
263-
headers?: Headers
264-
): void {
265-
console.log(body);
266-
expect(headers).to.not.be.undefined;
267-
expect(headers!['Authorization']).to.equal(
268-
'Firebase ' + testShared.authToken
269-
);
270-
}
271-
const service = makeFakeService(
272-
testShared.fakeApp,
273-
testShared.fakeAuthProvider,
274-
newSend
275-
);
276-
const reference = ref(service, 'gs://test-bucket');
277-
// Regression test for b/30989476
278-
await uploadBytes(ref(reference, 'hello'), new Blob(), {
287+
describe('uploadBytes', () => {
288+
it('Uses metadata.contentType', done => {
289+
const root = withFakeSend((text: string) => {
290+
expect(text).to.include('"contentType":"lol/wut"');
291+
}, done);
292+
uploadBytes(ref(root, 'hello'), new Blob(), {
279293
contentType: 'lol/wut'
280294
} as Metadata);
281295
});
@@ -303,13 +317,13 @@ describe('Firebase Storage > Reference', () => {
303317
'storage/invalid-root-operation'
304318
);
305319
});
306-
it('uploadString throws', () => {
307-
expect(() =>
320+
it('uploadString throws', async () => {
321+
await expect(
308322
uploadString(root, 'raw', StringFormat.RAW)
309323
).to.be.rejectedWith('storage/invalid-root-operation');
310324
});
311-
it('uploadBytes throws', () => {
312-
expect(() => uploadBytes(root, new Blob(['a']))).to.be.rejectedWith(
325+
it('uploadBytes throws', async () => {
326+
await expect(uploadBytes(root, new Blob(['a']))).to.be.rejectedWith(
313327
'storage/invalid-root-operation'
314328
);
315329
});

yarn.lock

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13703,17 +13703,6 @@ [email protected]:
1370313703
serialize-javascript "^4.0.0"
1370413704
terser "^5.0.0"
1370513705

13706-
13707-
version "0.27.3"
13708-
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.3.tgz#cd9455ac026d325b20c5728d2cc54a08a771b68b"
13709-
integrity sha512-gmYPIFmALj9D3Ga1ZbTZAKTXq1JKlTQBtj299DXhqYz9cL3g/AQfUvbb2UhH+Nf++cCq941W2Mv7UcrcgLzJJg==
13710-
dependencies:
13711-
"@rollup/pluginutils" "^3.1.0"
13712-
find-cache-dir "^3.3.1"
13713-
fs-extra "8.1.0"
13714-
resolve "1.17.0"
13715-
tslib "2.0.1"
13716-
1371713706
1371813707
version "0.29.0"
1371913708
resolved "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.29.0.tgz#b7ad83f5241dbc5bdf1e98d9c3fca005ffe39e1a"

0 commit comments

Comments
 (0)