-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstats.spec.ts
93 lines (78 loc) · 2.98 KB
/
stats.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import path from 'path';
import StatsCommand from '../../../src/cmds/stats/stats';
import { withStubbedTelemetry } from '../../helper';
import { EventInfo } from '../../../src/cmds/stats/accumulateEvents';
const fixtureDir = path.join(__dirname, '../', 'fixtures', 'stats');
const mapPath = path.join('Microposts_interface_micropost_interface.appmap.json');
const relativeMapPath = path.join('appmap', 'Microposts_interface_micropost_interface.appmap.json');
const originalDir = process.cwd();
describe('stats subcommand', () => {
withStubbedTelemetry();
afterEach(() => process.chdir(originalDir));
const commonArgs = {
_: ['stats'],
$0: 'src/cli.ts',
directory: fixtureDir,
appmapDir: 'appmap',
};
it('analyzes a directory', async () => {
const argv = { ...commonArgs };
const ret = await StatsCommand.handler(argv);
if (!ret) throw Error();
const [biggestAppMapSizes, slowestExecutionTimes] = ret;
expect(biggestAppMapSizes[0].size).toEqual(1747637);
expect(slowestExecutionTimes[0].elapsed_instrumentation_time_total).toEqual(0.020088);
expect(slowestExecutionTimes[0].num_calls).toEqual(449);
expect(slowestExecutionTimes[0].name).toEqual('function:logger/Logger::LogDevice#write');
});
it('analyzes an appmap absolute path', async () => {
let argv = {
...commonArgs,
appmapFile: path.resolve(fixtureDir, relativeMapPath),
limit: 10,
};
const ret = await StatsCommand.handler(argv);
if (!ret) throw Error();
expect(ret.length).toEqual(argv.limit);
const { function: fn, count, size } = ret[0] as EventInfo;
expect(fn).toEqual('function:logger/Logger::LogDevice#write');
expect(count).toEqual(319);
expect(size).toEqual(172419);
});
it('analyzes a file in the current working directory', async () => {
const argv = {
...commonArgs,
directory: path.join(fixtureDir, 'appmap'),
appmapFile: mapPath,
};
const ret = await StatsCommand.handler(argv);
if (!ret) throw Error();
expect(ret.length).toEqual(75);
const { function: fn, count, size } = ret[0] as EventInfo;
expect(fn).toEqual('function:logger/Logger::LogDevice#write');
expect(count).toEqual(319);
expect(size).toEqual(172419);
});
it('handles and analyzes relative file paths correctly', async () => {
const argv = {
...commonArgs,
appmapFile: relativeMapPath,
};
const ret = await StatsCommand.handler(argv);
if (!ret) throw Error();
expect(ret.length).toEqual(75);
const { function: fn, count, size } = ret[0] as EventInfo;
expect(fn).toEqual('function:logger/Logger::LogDevice#write');
expect(count).toEqual(319);
expect(size).toEqual(172419);
});
it('does not analyze a file in a child directory when only a file name is passed', async () => {
const argv = {
...commonArgs,
directory: originalDir,
appmapFile: mapPath,
};
const ret = await StatsCommand.handler(argv);
expect(ret).toBeUndefined();
});
});