Skip to content

Commit f1f71fa

Browse files
Fix tests
1 parent f5e6b70 commit f1f71fa

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

packages/storage/.run/All Tests.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
<test-pattern>test/{,!(browser)/**/}*.test.ts</test-pattern>
1717
<method v="2" />
1818
</configuration>
19-
</component>
19+
</component>

packages/storage/src/platform/base64.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ const platform = require(`./${process.env.TEST_PLATFORM ?? 'node'}/base64`);
2323
export function decodeBase64(encoded: string): string {
2424
return platform.decodeBase64(encoded);
2525
}
26+
27+
/** Converts a Uint8Array to a string. */
28+
export function decodeUint8Array(data: Uint8Array): string {
29+
return platform.decodeUint8Array(data);
30+
}

packages/storage/src/platform/browser/base64.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919
export function decodeBase64(encoded: string): string {
2020
return atob(encoded);
2121
}
22+
23+
export function decodeUint8Array(data: Uint8Array): string {
24+
return new TextDecoder().decode(data);
25+
}

packages/storage/src/platform/node/base64.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { TextDecoder } from 'util';
1819
import { invalidFormat } from '../../implementation/error';
1920

2021
/** Converts a Base64 encoded string to a binary string. */
@@ -24,5 +25,9 @@ export function decodeBase64(encoded: string): string {
2425
if (/[^-A-Za-z0-9+/=]/.test(encoded)) {
2526
throw invalidFormat('base64', 'Invalid character found');
2627
}
27-
return new Buffer(encoded, 'base64').toString('binary');
28+
return Buffer.from(encoded, 'base64').toString('binary');
29+
}
30+
31+
export function decodeUint8Array(data: Uint8Array): string {
32+
return new TextDecoder().decode(data);
2833
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
3838
import { Provider } from '@firebase/component';
3939
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
4040
import { fakeServerHandler, storageServiceWithHandler } from './testshared';
41+
import { decodeUint8Array } from '../../src/platform/base64';
4142

4243
/* eslint-disable @typescript-eslint/no-floating-promises */
4344
function makeFakeService(
@@ -77,7 +78,7 @@ function withFakeSend(
7778
): void {
7879
let text: Promise<string>;
7980
if (body instanceof Uint8Array) {
80-
text = Promise.resolve(new TextDecoder().decode(body));
81+
text = Promise.resolve(decodeUint8Array(body));
8182
} else {
8283
text = (body as Blob).text();
8384
}
@@ -269,11 +270,10 @@ describe('Firebase Storage > Reference', () => {
269270
getMetadata(ref(reference, 'foo'));
270271
});
271272

272-
describe('uploadString', () => {
273+
describe.only('uploadString', () => {
273274
it('Uses metadata.contentType for RAW format', done => {
274275
// Regression test for b/30989476
275276
const root = withFakeSend((text: string, headers?: Headers) => {
276-
console.log(headers);
277277
expect(text).to.include('"contentType":"lol/wut"');
278278
}, done);
279279
uploadString(ref(root, 'test'), 'hello', StringFormat.RAW, {

packages/storage/test/unit/requests.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
CONFIG_STORAGE_BUCKET_KEY
5252
} from '../../src/implementation/constants';
5353
import { FirebaseApp } from '@firebase/app-types';
54+
import { decodeUint8Array } from '../../src/platform/base64';
5455

5556
describe('Firebase Storage > Requests', () => {
5657
const normalBucket = 'b';
@@ -171,7 +172,7 @@ describe('Firebase Storage > Requests', () => {
171172
assert.equal(str, expectedStr);
172173
});
173174
} else if (body instanceof Uint8Array) {
174-
const str = new TextDecoder().decode(body);
175+
const str = decodeUint8Array(body);
175176
assert.equal(str, expectedStr);
176177
} else {
177178
assert.equal(body as string, expectedStr);

0 commit comments

Comments
 (0)