github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/packages/pyroscope-flamegraph/src/FlameGraph/normalize.spec.ts (about)

     1  import { normalize } from './normalize';
     2  import { Flamebearer, Profile } from '@pyroscope/models/src';
     3  
     4  describe('normalize', () => {
     5    it('accepts a flamebearer', () => {
     6      const flame: Flamebearer = {
     7        format: 'single',
     8        names: ['foo'],
     9        units: 'unknown',
    10        levels: [[99]],
    11        spyName: 'unknown',
    12        numTicks: 10,
    13        sampleRate: 100,
    14        maxSelf: 1,
    15      };
    16  
    17      expect(normalize({ flamebearer: flame })).toStrictEqual(flame);
    18    });
    19  
    20    it('accepts a profile', () => {
    21      const input: { profile: Profile } = {
    22        profile: {
    23          metadata: {
    24            spyName: 'unknown',
    25            format: 'single',
    26            sampleRate: 100,
    27            units: 'unknown',
    28          },
    29          flamebearer: {
    30            levels: [
    31              [0, 609, 0, 0],
    32              [0, 606, 0, 13, 0, 3, 0, 1],
    33            ],
    34            maxSelf: 1,
    35            names: ['total', 'foo'],
    36            numTicks: 10,
    37          },
    38        },
    39      };
    40      const snapshot = JSON.parse(JSON.stringify(input));
    41  
    42      const flame = normalize(input);
    43  
    44      expect(flame).toStrictEqual({
    45        format: 'single',
    46        names: ['total', 'foo'],
    47        units: 'unknown',
    48        levels: [
    49          [0, 609, 0, 0],
    50          [0, 606, 0, 13, 606, 3, 0, 1],
    51        ],
    52        spyName: 'unknown',
    53        numTicks: 10,
    54        sampleRate: 100,
    55        maxSelf: 1,
    56      });
    57  
    58      // It should not modify the original object
    59      // Since it's stored in the redux store
    60      expect(input).toStrictEqual(snapshot);
    61    });
    62  
    63    it('accepts nothing', () => {
    64      const flame = normalize({});
    65      expect(flame).toStrictEqual({
    66        format: 'single',
    67        names: [],
    68        units: 'unknown',
    69        levels: [[]],
    70        spyName: 'unknown',
    71        numTicks: 0,
    72        sampleRate: 0,
    73        maxSelf: 0,
    74      });
    75    });
    76  });