Skip to content

Commit

Permalink
fix(tests): Fix node integration test linting and type errors (#5070)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
lobsterkatie authored and AbhiPrasad committed May 30, 2022
1 parent 23558f3 commit 7c0ce99
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 13 deletions.
19 changes: 16 additions & 3 deletions packages/node-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ module.exports = {
jest: true,
},
extends: ['../../.eslintrc.js'],
parserOptions: {
sourceType: 'module',
},
overrides: [
{
files: ['utils/**/*.ts'],
parserOptions: {
project: ['tsconfig.json'],
sourceType: 'module',
},
},
{
files: ['suites/**/*.ts'],
parserOptions: {
project: ['tsconfig.test.json'],
sourceType: 'module',
},
},
],
};
2 changes: 1 addition & 1 deletion packages/node-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const baseConfig = require('../../jest/jest.config.js');

module.exports = {
globalSetup: '<rootDir>/setup-tests.ts',
globalSetup: '<rootDir>/utils/setup-tests.ts',
...baseConfig,
testMatch: ['**/test.ts'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import http from 'http';

const app = express();

export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string } };

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { TRACEPARENT_REGEXP } from '@sentry/utils';
import * as path from 'path';

import { getAPIResponse, runServer } from '../../../../utils/index';
import path = require('path');
import { TestAPIResponse } from '../server';

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

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

expect(response).toBeDefined();
expect(response).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { TRACEPARENT_REGEXP } from '@sentry/utils';
import * as path from 'path';

import { getAPIResponse, runServer } from '../../../../utils/index';
import path = require('path');
import { TestAPIResponse } from '../server';

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

const response = await getAPIResponse(new URL(`${url}/express`));
const response = (await getAPIResponse(new URL(`${url}/express`))) as TestAPIResponse;

expect(response).toBeDefined();
expect(response).toMatchObject({
Expand Down
2 changes: 1 addition & 1 deletion packages/node-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",

"include": ["**/*.ts"],
"include": ["utils/**/*.ts"],

"compilerOptions": {
// package-specific options
Expand Down
2 changes: 1 addition & 1 deletion packages/node-integration-tests/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",

"include": ["**/*.ts"],
"include": ["suites/**/*.ts"],

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
Expand Down
4 changes: 2 additions & 2 deletions packages/node-integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export const getMultipleEnvelopeRequest = async (url: string, count: number): Pr
* @param {Record<string, string>} [headers]
* @return {*} {Promise<any>}
*/
export const getAPIResponse = async (url: URL, headers?: Record<string, string>): Promise<any> => {
return await new Promise(resolve => {
export const getAPIResponse = async (url: URL, headers?: Record<string, string>): Promise<unknown> => {
return new Promise(resolve => {
http.get(
headers
? ({
Expand Down

0 comments on commit 7c0ce99

Please sign in to comment.