-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathmod.test.ts
More file actions
129 lines (104 loc) · 3.55 KB
/
mod.test.ts
File metadata and controls
129 lines (104 loc) · 3.55 KB
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
import type { Envelope, Event } from '@sentry/core';
import { createStackParser, forEachEnvelopeItem, nodeStackLineParser } from '@sentry/core';
import { assertEquals } from 'https://deno.land/std@0.202.0/assert/assert_equals.ts';
import { assertSnapshot } from 'https://deno.land/std@0.202.0/testing/snapshot.ts';
import { DenoClient, getCurrentScope, getDefaultIntegrations, metrics, Scope } from '../build/esm/index.js';
import { getNormalizedEvent } from './normalize.ts';
import { makeTestTransport } from './transport.ts';
function getTestClient(callback: (event?: Event) => void): DenoClient {
const client = new DenoClient({
dsn: 'https://233a45e5efe34c47a3536797ce15dafa@nothing.here/5650507',
debug: true,
integrations: getDefaultIntegrations({}),
stackParser: createStackParser(nodeStackLineParser()),
transport: makeTestTransport(envelope => {
callback(getNormalizedEvent(envelope));
}),
});
client.init();
getCurrentScope().setClient(client);
return client;
}
function delay(time: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, time);
});
}
Deno.test('captureException', async t => {
let ev: Event | undefined;
const client = getTestClient(event => {
ev = event;
});
function something() {
return new Error('Some unhandled error');
}
client.captureException(something());
await delay(200);
await assertSnapshot(t, ev);
});
Deno.test('captureMessage', async t => {
let ev: Event | undefined;
const client = getTestClient(event => {
ev = event;
});
client.captureMessage('Some error message');
await delay(200);
await assertSnapshot(t, ev);
});
Deno.test('captureMessage twice', async t => {
let ev: Event | undefined;
const client = getTestClient(event => {
ev = event;
});
client.captureMessage('Some error message');
await delay(200);
await assertSnapshot(t, ev);
client.captureMessage('Another error message');
await delay(200);
await assertSnapshot(t, ev);
});
Deno.test('metrics.count captures a counter metric', async () => {
const envelopes: Array<Envelope> = [];
const client = new DenoClient({
dsn: 'https://233a45e5efe34c47a3536797ce15dafa@nothing.here/5650507',
integrations: getDefaultIntegrations({}),
stackParser: createStackParser(nodeStackLineParser()),
transport: makeTestTransport(envelope => {
envelopes.push(envelope);
}),
});
client.init();
const scope = new Scope();
scope.setClient(client);
metrics.count('test.counter', 5, { scope });
await client.flush(2000);
// deno-lint-ignore no-explicit-any
let metricItem: any = undefined;
for (const envelope of envelopes) {
forEachEnvelopeItem(envelope, item => {
const [headers, body] = item;
if (headers.type === 'trace_metric') {
metricItem = body;
}
});
}
assertEquals(metricItem !== undefined, true);
assertEquals(metricItem.items.length, 1);
assertEquals(metricItem.items[0].name, 'test.counter');
assertEquals(metricItem.items[0].type, 'counter');
assertEquals(metricItem.items[0].value, 5);
});
Deno.test('App runs without errors', async _ => {
const cmd = new Deno.Command('deno', {
args: ['run', '--allow-net=some-domain.com', './test/example.ts'],
stdout: 'piped',
stderr: 'piped',
});
const output = await cmd.output();
assertEquals(output.success, true);
const td = new TextDecoder();
const outString = td.decode(output.stdout);
const errString = td.decode(output.stderr);
assertEquals(outString, 'App has started\n');
assertEquals(errString, '');
});