Skip to content

Commit 7bf6540

Browse files
authored
fix(tests): Fix node integration test linting and type errors (#5070)
This fixes a number of linting and type errors in our node integration tests. Included changes: - Fix eslint config so it's clear which tsconfig file applies to which code files - Use ESM import for `path`. - Create `TestAPIResponse` type. - Remove redundant `await` on returned promise. - Use `unknown` in place of `any`.
1 parent 8c185db commit 7bf6540

File tree

9 files changed

+30
-13
lines changed

9 files changed

+30
-13
lines changed

packages/node-integration-tests/.eslintrc.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ module.exports = {
44
jest: true,
55
},
66
extends: ['../../.eslintrc.js'],
7-
parserOptions: {
8-
sourceType: 'module',
9-
},
7+
overrides: [
8+
{
9+
files: ['utils/**/*.ts'],
10+
parserOptions: {
11+
project: ['tsconfig.json'],
12+
sourceType: 'module',
13+
},
14+
},
15+
{
16+
files: ['suites/**/*.ts'],
17+
parserOptions: {
18+
project: ['tsconfig.test.json'],
19+
sourceType: 'module',
20+
},
21+
},
22+
],
1023
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const baseConfig = require('../../jest/jest.config.js');
22

33
module.exports = {
4-
globalSetup: '<rootDir>/setup-tests.ts',
4+
globalSetup: '<rootDir>/utils/setup-tests.ts',
55
...baseConfig,
66
testMatch: ['**/test.ts'],
77
};

packages/node-integration-tests/suites/express/sentry-trace/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import http from 'http';
66

77
const app = express();
88

9+
export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string } };
10+
911
Sentry.init({
1012
dsn: 'https://public@dsn.ingest.sentry.io/1337',
1113
release: '1.0',

packages/node-integration-tests/suites/express/sentry-trace/trace-header-assign/test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { TRACEPARENT_REGEXP } from '@sentry/utils';
2+
import * as path from 'path';
23

34
import { getAPIResponse, runServer } from '../../../../utils/index';
4-
import path = require('path');
5+
import { TestAPIResponse } from '../server';
56

67
test('Should assign `sentry-trace` header which sets parent trace id of an outgoing request.', async () => {
78
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
89

9-
const response = await getAPIResponse(new URL(`${url}/express`), {
10+
const response = (await getAPIResponse(new URL(`${url}/express`), {
1011
'sentry-trace': '12312012123120121231201212312012-1121201211212012-0',
11-
});
12+
})) as TestAPIResponse;
1213

1314
expect(response).toBeDefined();
1415
expect(response).toMatchObject({

packages/node-integration-tests/suites/express/sentry-trace/trace-header-out/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { TRACEPARENT_REGEXP } from '@sentry/utils';
2+
import * as path from 'path';
23

34
import { getAPIResponse, runServer } from '../../../../utils/index';
4-
import path = require('path');
5+
import { TestAPIResponse } from '../server';
56

67
test('should attach a `sentry-trace` header to an outgoing request.', async () => {
78
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
89

9-
const response = await getAPIResponse(new URL(`${url}/express`));
10+
const response = (await getAPIResponse(new URL(`${url}/express`))) as TestAPIResponse;
1011

1112
expect(response).toBeDefined();
1213
expect(response).toMatchObject({

packages/node-integration-tests/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33

4-
"include": ["**/*.ts"],
4+
"include": ["utils/**/*.ts"],
55

66
"compilerOptions": {
77
// package-specific options

packages/node-integration-tests/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33

4-
"include": ["**/*.ts"],
4+
"include": ["suites/**/*.ts"],
55

66
"compilerOptions": {
77
// should include all types from `./tsconfig.json` plus types for all test frameworks used

packages/node-integration-tests/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export const getMultipleEnvelopeRequest = async (url: string, count: number): Pr
103103
* @param {Record<string, string>} [headers]
104104
* @return {*} {Promise<any>}
105105
*/
106-
export const getAPIResponse = async (url: URL, headers?: Record<string, string>): Promise<any> => {
107-
return await new Promise(resolve => {
106+
export const getAPIResponse = async (url: URL, headers?: Record<string, string>): Promise<unknown> => {
107+
return new Promise(resolve => {
108108
http.get(
109109
headers
110110
? ({

0 commit comments

Comments
 (0)