1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {getRootUrl} from 'common/url_utils'; 18 19/** 20 * Get a fixture file from the fixtures directory. 21 * 22 * @param srcFilename The name of the fixture file in the fixtures directory. 23 * @param dstFilename The name of the file to save the fixture as. Defaults to 24 * the same name as the source file. 25 * @return A promise that resolves to the File object. 26 */ 27export async function getFixtureFile( 28 srcFilename: string, 29 dstFilename: string = srcFilename, 30): Promise<File> { 31 const url = getRootUrl() + 'base/src/test/fixtures/' + srcFilename; 32 const response = await fetch(url); 33 expect(response.ok).toBeTrue(); 34 const blob = await response.blob(); 35 const file = new File([blob], dstFilename); 36 return file; 37} 38