Skip to content

Commit

Permalink
test: Add a test suite with 100% [brag] code coverage to AWSLambda ha…
Browse files Browse the repository at this point in the history
…ndler (#2891)

* test: Add a test suite with 100% [brag] code coverage to AWSLambda handler
  • Loading branch information
kamilogorek authored Sep 15, 2020
1 parent 263c880 commit daae471
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/serverless/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ module.exports = {
project: './tsconfig.json',
},
},
{
files: ['test/**'],
rules: {
'no-empty': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
rules: {
'@typescript-eslint/no-var-requires': 'off',
Expand Down
27 changes: 24 additions & 3 deletions packages/serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
"@sentry/node": "5.23.0",
"@sentry/types": "5.23.0",
"@sentry/utils": "5.23.0",
"@types/aws-lambda": "^8.10.62",
"@types/node": "^14.6.4",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "5.23.0",
"@types/aws-lambda": "^8.10.62",
"@types/node": "^14.6.4",
"eslint": "7.6.0",
"jest": "^24.7.1",
"npm-run-all": "^4.1.2",
"prettier": "1.19.0",
"rimraf": "^2.6.3",
Expand All @@ -51,5 +52,25 @@
"test:watch": "jest --watch --passWithNoTests",
"pack": "npm pack"
},
"sideEffects": false
"sideEffects": false,
"jest": {
"collectCoverage": true,
"transform": {
"^.+\\.ts$": "ts-jest"
},
"moduleFileExtensions": [
"js",
"ts"
],
"testEnvironment": "node",
"testMatch": [
"**/*.test.ts"
],
"globals": {
"ts-jest": {
"tsConfig": "./tsconfig.json",
"diagnostics": false
}
}
}
}
5 changes: 1 addition & 4 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ export const wrapHandler = <TEvent = any, TResult = any>(
if (args[0] === null || args[0] === undefined) {
resolve(callback(...args));
} else {
captureExceptionAsync(args[0], context, options).then(
() => reject(callback(...args)),
() => reject(callback(...args)),
);
captureExceptionAsync(args[0], context, options).finally(() => reject(callback(...args)));
}
};
};
Expand Down
Empty file removed packages/serverless/test/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions packages/serverless/test/__mocks__/@sentry/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const SDK_VERSION = '6.6.6';
export const Severity = {
Warning: 'warning',
};
export const fakeScope = {
addEventProcessor: jest.fn(),
setTransactionName: jest.fn(),
setTag: jest.fn(),
setContext: jest.fn(),
};
export const captureException = jest.fn();
export const captureMessage = jest.fn();
export const withScope = jest.fn(cb => cb(fakeScope));
export const flush = jest.fn(() => Promise.resolve());

export const resetMocks = (): void => {
fakeScope.addEventProcessor.mockClear();
fakeScope.setTransactionName.mockClear();
fakeScope.setTag.mockClear();
fakeScope.setContext.mockClear();

captureException.mockClear();
captureMessage.mockClear();
withScope.mockClear();
flush.mockClear();
};
Loading

0 comments on commit daae471

Please sign in to comment.