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 16const { expect } = require('chai'); 17const { ApiDiffPlugin } = require('../../src/index'); 18const path = require('path'); 19const fs = require('fs'); 20 21describe('diffSingleFile', function () { 22 const testCasesDir = path.join(__dirname, '..', '/ut'); 23 const testCasesFileNames = fs.readdirSync(testCasesDir); 24 const expectFileDir = path.join(__dirname, '..', '/expect'); 25 const outputFilePath = path.join(__dirname, '..', 'output'); 26 if (!fs.existsSync(outputFilePath)) { 27 fs.mkdirSync(outputFilePath); 28 } 29 testCasesFileNames.forEach(fileName => { 30 const oldFileDir = path.join(testCasesDir, fileName, 'old'); 31 const newFileDir = path.join(testCasesDir, fileName, 'new'); 32 const expectFilePath = path.resolve(expectFileDir, `${fileName}.json`); 33 it(`testDiff# ${fileName}`, function () { 34 let argumentObject = { 35 "old": oldFileDir, 36 "new": newFileDir, 37 "oldVersion": fileName, 38 "newVersion": fileName, 39 "output": outputFilePath 40 }; 41 ApiDiffPlugin.start(argumentObject); 42 const resultFileName = `diff(${argumentObject.oldVersion}_${argumentObject.newVersion}).json` 43 const resultFilePath = path.resolve(argumentObject.output, resultFileName); 44 const resultFileContent = fs.readFileSync(resultFilePath, 'utf-8').replace(/\n|\r|\s/g, ''); 45 const expectContent = fs.readFileSync(expectFilePath, 'utf-8').replace(/\n|\r|\s/g, ''); 46 expect(resultFileContent).to.be.equal(expectContent); 47 48 }); 49 }); 50}); 51