Merge "Prepare for typescript upgrade" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0bf3266fca
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// This class is needed for testing because Node.js doesn't provide the Web API's File type
|
||||
import {Blob} from './blob';
|
||||
|
||||
class File extends Blob {
|
||||
constructor(buffer: ArrayBuffer, fileName: string) {
|
||||
super(buffer);
|
||||
this.name = fileName;
|
||||
}
|
||||
|
||||
readonly lastModified: number = 0;
|
||||
readonly name: string;
|
||||
readonly webkitRelativePath: string = '';
|
||||
}
|
||||
|
||||
export {File};
|
||||
@@ -14,16 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// This class is needed for testing because Node.js doesn't provide the Web API's Blob type
|
||||
class Blob {
|
||||
constructor(buffer: ArrayBuffer) {
|
||||
this.size = buffer.byteLength;
|
||||
this.type = 'application/octet-stream';
|
||||
// This class is needed for unit tests because Node.js doesn't provide
|
||||
// an implementation of the Web API's File type
|
||||
class FileImpl {
|
||||
readonly size: number;
|
||||
readonly type: string;
|
||||
readonly name: string;
|
||||
readonly lastModified: number = 0;
|
||||
readonly webkitRelativePath: string = '';
|
||||
private readonly buffer: ArrayBuffer;
|
||||
|
||||
constructor(buffer: ArrayBuffer, fileName: string) {
|
||||
this.buffer = buffer;
|
||||
this.size = this.buffer.byteLength;
|
||||
this.type = 'application/octet-stream';
|
||||
this.name = fileName;
|
||||
}
|
||||
|
||||
arrayBuffer(): Promise<ArrayBuffer> {
|
||||
return new Promise<ArrayBuffer>((resolve, reject) => {
|
||||
return new Promise<ArrayBuffer>((resolve) => {
|
||||
resolve(this.buffer);
|
||||
});
|
||||
}
|
||||
@@ -39,10 +48,6 @@ class Blob {
|
||||
text(): Promise<string> {
|
||||
throw new Error('Not implemented!');
|
||||
}
|
||||
|
||||
readonly size: number;
|
||||
readonly type: string;
|
||||
private readonly buffer: ArrayBuffer;
|
||||
}
|
||||
|
||||
export {Blob};
|
||||
export {FileImpl};
|
||||
@@ -15,14 +15,12 @@
|
||||
*/
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {Blob} from './blob';
|
||||
import {File} from './file';
|
||||
import {FileImpl} from './file_impl';
|
||||
|
||||
class CommonTestUtils {
|
||||
static async getFixtureFile(filename: string): Promise<File> {
|
||||
const buffer = CommonTestUtils.loadFixture(filename);
|
||||
const blob = new Blob(buffer);
|
||||
return new File(await blob.arrayBuffer(), filename);
|
||||
return new FileImpl(buffer, filename) as unknown as File;
|
||||
}
|
||||
|
||||
static loadFixture(filename: string): ArrayBuffer {
|
||||
|
||||
Reference in New Issue
Block a user