|
| 1 | +import { expectType, expectError } from 'tsd'; |
| 2 | +import { start, stop, defaultConfig, BlackfireConfiguration } from '.'; |
| 3 | + |
| 4 | +// start() accepts a valid configuration and returns boolean |
| 5 | +expectType<boolean>(start({ appName: 'my-app' })); |
| 6 | + |
| 7 | +// start() accepts all configuration options |
| 8 | +expectType<boolean>(start({ |
| 9 | + appName: 'my-app', |
| 10 | + agentSocket: 'tcp://127.0.0.1:8307', |
| 11 | + serverId: 'server-id', |
| 12 | + serverToken: 'server-token', |
| 13 | + labels: { env: 'production' }, |
| 14 | + uploadTimeoutMillis: 5000, |
| 15 | +})); |
| 16 | + |
| 17 | +// start() accepts empty config (all fields optional) |
| 18 | +expectType<boolean>(start({})); |
| 19 | + |
| 20 | +// stop() returns boolean |
| 21 | +expectType<boolean>(stop()); |
| 22 | + |
| 23 | +// defaultConfig has required fields |
| 24 | +expectType<string>(defaultConfig.appName); |
| 25 | +expectType<string>(defaultConfig.agentSocket); |
| 26 | +expectType<number>(defaultConfig.uploadTimeoutMillis); |
| 27 | + |
| 28 | +// defaultConfig.labels is always defined (not optional) |
| 29 | +expectType<Record<string, string>>(defaultConfig.labels); |
| 30 | + |
| 31 | +// start() rejects invalid types |
| 32 | +expectError(start({ appName: 123 })); |
| 33 | +expectError(start({ uploadTimeoutMillis: 'not-a-number' })); |
| 34 | +expectError(start({ labels: 'not-an-object' })); |
| 35 | + |
| 36 | +// start() rejects unknown properties |
| 37 | +expectError(start({ unknownProp: true })); |
0 commit comments