1/* 2 * Copyright (C) 2022 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 16// @ts-ignore 17import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js'; 18// @ts-ignore 19import { SpCpuChart } from '../../../../dist/trace/component/chart/SpCpuChart.js'; 20// @ts-ignore 21import { HeapNode } from '../../../../dist/js-heap/model/DatabaseStruct.js'; 22 23const sqlit = require('../../../../dist/trace/database/SqlLite.js'); 24jest.mock('../../../../dist/trace/database/SqlLite.js'); 25 26window.ResizeObserver = 27 window.ResizeObserver || 28 jest.fn().mockImplementation(() => ({ 29 disconnect: jest.fn(), 30 observe: jest.fn(), 31 unobserve: jest.fn(), 32 })); 33 34jest.mock('../../../../dist/js-heap/utils/Utils.js', () => { 35 return { 36 HeapNodeToConstructorItem: (node: HeapNode) => {}, 37 }; 38}); 39describe('SpCpuChart Test', () => { 40 let MockqueryCpuMax = sqlit.queryCpuMax; 41 MockqueryCpuMax.mockResolvedValue([{ cpu: 1 }]); 42 43 let mockCpuSlice = sqlit.queryCpuSchedSlice; 44 mockCpuSlice.mockResolvedValue([]); 45 let queryCpuData = sqlit.queryCpuDataCount; 46 queryCpuData.mockResolvedValue([ 47 { 48 count: 2, 49 cpu: 3, 50 }, 51 ]); 52 let ss = new SpChartManager(); 53 let trace = new SpCpuChart(ss); 54 it('SpMpsChart01', async function () { 55 await trace.init(); 56 expect(trace).toBeDefined(); 57 }); 58}); 59