Skip to content

Commit e15e9da

Browse files
authored
test: add types testing (#9)
1 parent 70f208d commit e15e9da

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
/// <reference types="node" />
2+
import { Transform } from 'stream';
3+
import { LoggingOptions, Log, LogSync } from '@google-cloud/logging';
4+
5+
declare function CloudPine(options?: CloudPineOptions): Transform;
6+
7+
type CloudPineOptions = {
8+
logName?: string;
9+
cloudLoggingOptions: {
10+
googleCloudOptions?: LoggingOptions;
11+
resourceSettings?: {
12+
type?: string;
13+
labels: Record<string, string>;
14+
};
15+
defaultLabels?: Record<string, string>;
16+
skipInit?: boolean;
17+
sync?: boolean;
18+
logOptions?: ConstructorParameters<typeof Log> | ConstructorParameters<typeof LogSync>;
19+
};
20+
};
21+
22+
export default CloudPine;
23+
export { CloudPineOptions };

lib/cloud-logging.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class CloudLogging {
5252
this._resource.labels = labels
5353

5454
this._log = this._sync
55-
? this.logging.logSync(this.name)
56-
: this.logging.log(this.name)
55+
? this.logging.logSync(this.name, this._logOptions)
56+
: this.logging.log(this.name, this._logOptions)
5757

5858
return this._log
5959
}

test/index.test-d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Transform } from 'stream';
2+
import { expectAssignable, expectType } from 'tsd';
3+
4+
import Pino from 'pino';
5+
6+
import CloudPine, { CloudPineOptions } from '../';
7+
8+
9+
const options: CloudPineOptions = {
10+
logName: 'something',
11+
cloudLoggingOptions: {
12+
googleCloudOptions: {
13+
projectId: 'some-projectid',
14+
},
15+
skipInit: true,
16+
sync: false,
17+
},
18+
};
19+
20+
expectType<typeof CloudPine>(CloudPine);
21+
expectAssignable<CloudPineOptions>({
22+
logName: 'something',
23+
cloudLoggingOptions: {
24+
googleCloudOptions: {
25+
projectId: 'some-projectid',
26+
},
27+
skipInit: true,
28+
sync: false,
29+
},
30+
});
31+
expectType<Transform>(CloudPine(options));
32+
33+
Pino({
34+
transport: {
35+
options,
36+
target: 'cloud-pine',
37+
}
38+
})

0 commit comments

Comments
 (0)