/
Instrumenter.test.ts
155 lines (140 loc) · 5.46 KB
/
Instrumenter.test.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as path from 'path';
import { App } from '../../src/App';
import { readFileSync, readSync } from 'fs';
test('Instrumentation: JS that was constructed from TS', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'plain-ts-main.js')],
in_place: false,
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('translated', 1);
});
test('Instrumentation: React App', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-index.js')],
in_place: false,
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('translated', 1);
});
test('Instrumentation: React App. Vendor.js', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('translated', 1);
});
test('Instrumentation: React App. Vendor.js. Skip its instrumentation based on pattern.', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
exclude_bundle: ['**/*-vendor.js'],
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('excluded', 1);
});
test('Instrumentation: React App. Vendor.js. Skip its instrumentation based on a quoted pattern.', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
exclude_bundle: ['"**/*-vendor.js"'],
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('excluded', 1);
});
test('Instrumentation: React App. Vendor.js. Skip its instrumentation based on a multiply quoted pattern.', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
exclude_bundle: ['""\'**/*-vendor.js\'""'],
collector: 'localhost:54321',
to: outputDir
})
).resolves.toHaveProperty('excluded', 1);
});
test('Instrumentation: React App. Vendor.js; single quoted collector config; TS-33372', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
collector: '\'localhost:54321\'',
to: outputDir
})
).resolves.toHaveProperty('translated', 1);
});
test('Instrumentation: React App. Vendor.js; double quoted collector config; TS-33372', () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
return expect(
App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'vite-react-vendor.js')],
in_place: false,
collector: '"localhost:54321"',
to: outputDir
})
).resolves.toHaveProperty('translated', 1);
});
test('Instrumentation: Angular App', async () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
const result = await App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'angular-hero-main-es5.js')],
in_place: false,
collector: 'localhost:54321',
to: outputDir
});
const matchStats = result.task?.originSourcePattern.retrieveMatchingFiles();
expect(matchStats?.excludePatterns.length).toStrictEqual(0);
expect(matchStats?.neitherExcludedNorIncluded.length).toStrictEqual(19);
expect(matchStats?.neitherExcludedNorIncluded).toContain("src/app/app.component.ts")
expect(result).toHaveProperty('translated', 1);
});
test('Instrumentation: Polyfill', async () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
const result = await App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'polyfills.js')],
exclude_origin: ['node_modules/**/*.*'],
in_place: false,
collector: 'localhost:54321',
to: outputDir
});
const matchStats = result.task?.originSourcePattern.retrieveMatchingFiles();
expect(matchStats?.excludePatterns).toContain("node_modules/**/*.*")
expect(matchStats?.excludeMatches).toContain("node_modules/zone.js/fesm2015/zone.js")
expect(result).toHaveProperty('translated', 1);
});
test('Instrumented code must contain collector specification', async () => {
const outputDir = path.join(__dirname, '..', '..', 'outputs');
const result = await App.runForConfigArguments({
inputs: [path.join(__dirname, 'inputs', 'plain-ts-main.js')],
exclude_origin: ['node_modules/**/*.*'],
in_place: false,
collector: "ws://not-used-since-pattern-is-also-given",
relative_collector: "replace-in-host:foo bar,port:1234,scheme:wss",
to: outputDir
});
const matchStats = result.task?.originSourcePattern.retrieveMatchingFiles();
expect(result).toHaveProperty('translated', 1);
expect(result.task).toBeTruthy();
const instrumentedFile = result.task!.elements[0].toFile;
const instrumentedCode = readFileSync(instrumentedFile).toString();
expect(instrumentedCode).not.toContain("$COLLECTOR_SPECIFIER")
expect(instrumentedCode).toContain(`{"type":"relative","hostReplace":{"search":"foo","replace":"bar"},"port":1234,"scheme":"wss"}`)
});