Skip to content

Commit

Permalink
fix(tests): adjust to Node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
harelmo-lumigo committed Dec 28, 2023
1 parent cb10f7c commit 27a6d85
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ module.exports = {
setupFilesAfterEnv: ['./testUtils/jest.setup.js'],
silent: true,
watchPathIgnorePatterns: ['globalConfig'],
runner: 'groups'
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
"scripts": {
"build": "rm -rf dist && tsc --build --force",
"check-types": "tsc --noEmit",
"jest": "jest",
"jest": "jest --group=-unhandled-rejection-expected",
"jest:unhandled-rejections": "node --unhandled-rejections=warn node_modules/.bin/jest --group=unhandled-rejection-expected",
"jest-detectOpenHandles": "jest --detectOpenHandles",
"jest-traces": "node --trace-deprecation --trace-warnings node_modules/.bin/jest",
"lint": "eslint ./src",
"prepublishOnly": "npm run lint && npm run prettier:fix && npm run test",
"prettier:ci": "prettier --list-different \"src/**/*.[jt]s\" --parser typescript",
"prettier:fix": "prettier --write \"./src/**/*.[jt]s\" --parser typescript",
"semantic-release": "semantic-release",
"test": "npm run build && npm run jest"
"test": "npm run build && npm run jest && npm run jest:unhandled-rejection"
},
"dependencies": {
"@lumigo/node-core": "1.13.0",
Expand Down Expand Up @@ -62,6 +63,7 @@
"jest": "^29.2.1",
"jest-each": "^29.2.1",
"jest-junit": "^14.0.1",
"jest-runner-groups": "^2.2.0",
"mockdate": "^2.0.5",
"mongo-mock": "^4.2.0",
"prettier": "2.7.1",
Expand All @@ -83,4 +85,4 @@
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
}
15 changes: 10 additions & 5 deletions src/extender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,18 @@ describe('extender', () => {
await p;
});

/*
@group unhandled-rejection-expected
*/
test('hookPromise -> catchHandler', async () => {
expect.assertions(1);

const p = Promise.reject(new Error('octopus'));

const catchHandler = (value) => {
expect(value).toEqual('octopus');
};
extender.hookPromise(p, { catchHandler: catchHandler });
await expect(p).rejects.toThrow();
extender.hookPromise(p, {
catchHandler: (value) => {
expect(value).toEqual('octopus');
},
});
});
});
3 changes: 3 additions & 0 deletions src/hooks/msSql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ describe('msSql', () => {
});
});

/**
* @group unhandled-rejection-expected
*/
test('hook -> query (text: string, callback: Function) -> failed', (done) => {
const client = createHookedClient({
error: {
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/neo4j.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ describe('neo4j', () => {
]);
});

/**
* @group unhandled-rejection-expected
*/
test('hook -> run (text: string, params: object) -> error', async () => {
const query = 'not-a-neo4j-query';
const params = {};
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ describe('redis', () => {
expect(spans).toEqual([expectedSpan]);
});

/**
* @group unhandled-rejection-expected
*/
test('hook ioredis -> rejects', async () => {
const connectionOptions = 'tracer-test-cluster.1meza6.ng.0001.usw1.cache.amazonaws.com';
hookRedis(Ioredis);
Expand Down
3 changes: 3 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ describe('index', () => {
]);
});

/**
* @group unhandled-rejection-expected
*/
test('trace => UnhandledPromiseRejection', async () => {
process.exit = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion testUtils/mongo4xMocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MongoClient {

connect(options: any, callback: Function) {
const self = this;
options = options || self.options;
options = options || self.options || {};
if (options.connectThrowsError) {
throw new Error('Connection failed: connectThrowsError');
}
Expand Down

0 comments on commit 27a6d85

Please sign in to comment.