1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { expect } from 'chai'; 17import path from 'path'; 18import fs from 'fs'; 19 20import { parse } from '../../src/core/entry'; 21 22describe('testSingleFile', function () { 23 const testFileDir = path.join(__dirname, '..', '/ut/'); 24 const outputFileDir = path.join(__dirname, '..', '/output/'); 25 const expectFileDir = path.join(__dirname, '..', '/expect/'); 26 const testFileNames = fs.readdirSync(testFileDir); 27 testFileNames.forEach((testFileName) => { 28 const baseName: string = path.basename(testFileName, '.d.ts'); 29 const testFilePath = path.join(testFileDir, testFileName); 30 const outputFilePath = path.join(outputFileDir, `${baseName}.json`); 31 const expectFilePath = path.join(expectFileDir, `${baseName}.json`); 32 it('testFile#' + testFilePath, function () { 33 if (fs.existsSync(outputFilePath)) { 34 fs.rmSync(outputFilePath); 35 } 36 if (!fs.existsSync(outputFileDir)) { 37 fs.mkdirSync(outputFileDir); 38 } 39 parse(testFilePath, outputFilePath); 40 const expectFileContent: string = fs.readFileSync(expectFilePath, 'utf-8').replace(/\r\n/g, '\n'); 41 const outputFileContent: string = fs.readFileSync(outputFilePath, 'utf-8').replace(/\r\n/g, '\n'); 42 expect(outputFileContent).eql(expectFileContent); 43 }); 44 }); 45});