Skip to content

Commit d77d528

Browse files
committed
test: jest setup and unit tests
1 parent 64d8242 commit d77d528

File tree

14 files changed

+1498
-22
lines changed

14 files changed

+1498
-22
lines changed

dist/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21055,7 +21055,6 @@ class WebClient extends methods_1.Methods {
2105521055
adapter: adapter ? (config) => adapter(Object.assign(Object.assign({}, config), { adapter: undefined })) : undefined,
2105621056
timeout,
2105721057
baseURL: slackApiUrl,
21058-
allowAbsoluteUrls,
2105921058
headers: (0, is_electron_1.default)() ? headers : Object.assign({ 'User-Agent': (0, instrument_1.getUserAgent)() }, headers),
2106021059
httpAgent: agent,
2106121060
httpsAgent: agent,
@@ -21098,7 +21097,8 @@ class WebClient extends methods_1.Methods {
2109821097
const headers = {};
2109921098
if (options.token)
2110021099
headers.Authorization = `Bearer ${options.token}`;
21101-
const response = yield this.makeRequest(method, Object.assign({ team_id: this.teamId }, options), headers);
21100+
const url = this.deriveRequestUrl(method);
21101+
const response = yield this.makeRequest(url, Object.assign({ team_id: this.teamId }, options), headers);
2110221102
const result = yield this.buildResult(response);
2110321103
this.logger.debug(`http request result: ${JSON.stringify(result)}`);
2110421104
// log warnings in response metadata
@@ -21328,7 +21328,6 @@ class WebClient extends methods_1.Methods {
2132821328
return __awaiter(this, void 0, void 0, function* () {
2132921329
// TODO: better input types - remove any
2133021330
const task = () => this.requestQueue.add(() => __awaiter(this, void 0, void 0, function* () {
21331-
const requestURL = this.deriveRequestUrl(url);
2133221331
try {
2133321332
// biome-ignore lint/suspicious/noExplicitAny: TODO: type this
2133421333
const config = Object.assign({ headers }, this.tlsConfig);
@@ -21342,7 +21341,7 @@ class WebClient extends methods_1.Methods {
2134221341
if (url.endsWith('apps.event.authorizations.list')) {
2134321342
body.token = undefined;
2134421343
}
21345-
this.logger.debug(`http request url: ${requestURL}`);
21344+
this.logger.debug(`http request url: ${url}`);
2134621345
this.logger.debug(`http request body: ${JSON.stringify(redact(body))}`);
2134721346
// compile all headers - some set by default under the hood by axios - that will be sent along
2134821347
let allHeaders = Object.keys(this.axios.defaults.headers).reduce((acc, cur) => {
@@ -81376,6 +81375,7 @@ var PullState;
8137681375

8137781376
/**
8137881377
* Get an emoji based on the age of something.
81378+
*
8137981379
* @param {number} hoursAgo - The number of hours ago since something happened.
8138081380
* @returns {string}
8138181381
*/
@@ -81390,6 +81390,7 @@ function getAgeBasedEmoji(hoursAgo) {
8139081390
}
8139181391
/**
8139281392
* Get the relative human readable age of something.
81393+
*
8139381394
* @param {number} hoursAgo - The number of hours ago since something happened.
8139481395
* @param {boolean} [withAgo=true] - Whether to include the ' ago' suffix when appropriate.
8139581396
* @returns {string}
@@ -90330,7 +90331,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"@aws-sdk/nested-clients","ver
9033090331
/***/ 56734:
9033190332
/***/ ((module) => {
9033290333

90333-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@slack/web-api","version":"7.9.0","description":"Official library for using the Slack Platform\'s Web API","author":"Slack Technologies, LLC","license":"MIT","keywords":["slack","web-api","bot","client","http","api","proxy","rate-limiting","pagination"],"main":"dist/index.js","types":"./dist/index.d.ts","files":["dist/**/*"],"engines":{"node":">= 18","npm":">= 8.6.0"},"repository":"slackapi/node-slack-sdk","homepage":"https://tools.slack.dev/node-slack-sdk/web-api","publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"scripts":{"prepare":"npm run build","build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage","lint":"npx @biomejs/biome check .","lint:fix":"npx @biomejs/biome check --write .","mocha":"mocha --config ./test/.mocharc.json \\"./src/**/*.spec.ts\\"","test":"npm run lint && npm run test:types && npm run test:integration && npm run test:unit","test:integration":"npm run build && node test/integration/commonjs-project/index.js && node test/integration/esm-project/index.mjs && npm run test:integration:ts","test:integration:ts":"cd test/integration/ts-4.7-project && npm i && npm run build","test:unit":"npm run build && c8 --config ./test/.c8rc.json npm run mocha","test:types":"tsd","watch":"npx nodemon --watch \'src\' --ext \'ts\' --exec npm run build"},"dependencies":{"@slack/logger":"^4.0.0","@slack/types":"^2.9.0","@types/node":">=18.0.0","@types/retry":"0.12.0","axios":"^1.8.3","eventemitter3":"^5.0.1","form-data":"^4.0.0","is-electron":"2.2.2","is-stream":"^2","p-queue":"^6","p-retry":"^4","retry":"^0.13.1"},"devDependencies":{"@biomejs/biome":"^1.8.3","@tsconfig/recommended":"^1","@types/busboy":"^1.5.4","@types/chai":"^4","@types/mocha":"^10","@types/sinon":"^17","busboy":"^1","c8":"^10.1.2","chai":"^4","mocha":"^11","mocha-junit-reporter":"^2.2.1","mocha-multi-reporters":"^1.5.1","nock":"^13","shx":"^0.4.0","sinon":"^19","source-map-support":"^0.5.21","ts-node":"^10","tsd":"^0.31.1","typescript":"5.3.3"},"tsd":{"directory":"test/types"}}');
90334+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@slack/web-api","version":"7.9.1","description":"Official library for using the Slack Platform\'s Web API","author":"Slack Technologies, LLC","license":"MIT","keywords":["slack","web-api","bot","client","http","api","proxy","rate-limiting","pagination"],"main":"dist/index.js","types":"./dist/index.d.ts","files":["dist/**/*"],"engines":{"node":">= 18","npm":">= 8.6.0"},"repository":"slackapi/node-slack-sdk","homepage":"https://tools.slack.dev/node-slack-sdk/web-api","publishConfig":{"access":"public"},"bugs":{"url":"https://github.com/slackapi/node-slack-sdk/issues"},"scripts":{"prepare":"npm run build","build":"npm run build:clean && tsc","build:clean":"shx rm -rf ./dist ./coverage","lint":"npx @biomejs/biome check .","lint:fix":"npx @biomejs/biome check --write .","mocha":"mocha --config ./test/.mocharc.json \\"./src/**/*.spec.ts\\"","test":"npm run lint && npm run test:types && npm run test:integration && npm run test:unit","test:integration":"npm run build && node test/integration/commonjs-project/index.js && node test/integration/esm-project/index.mjs && npm run test:integration:ts","test:integration:ts":"cd test/integration/ts-4.7-project && npm i && npm run build","test:unit":"npm run build && c8 --config ./test/.c8rc.json npm run mocha","test:types":"tsd","watch":"npx nodemon --watch \'src\' --ext \'ts\' --exec npm run build"},"dependencies":{"@slack/logger":"^4.0.0","@slack/types":"^2.9.0","@types/node":">=18.0.0","@types/retry":"0.12.0","axios":"^1.8.3","eventemitter3":"^5.0.1","form-data":"^4.0.0","is-electron":"2.2.2","is-stream":"^2","p-queue":"^6","p-retry":"^4","retry":"^0.13.1"},"devDependencies":{"@biomejs/biome":"^1.8.3","@tsconfig/recommended":"^1","@types/busboy":"^1.5.4","@types/chai":"^4","@types/mocha":"^10","@types/sinon":"^17","busboy":"^1","c8":"^10.1.2","chai":"^4","mocha":"^11","mocha-junit-reporter":"^2.2.1","mocha-multi-reporters":"^1.5.1","nock":"^13","shx":"^0.4.0","sinon":"^20","source-map-support":"^0.5.21","ts-node":"^10","tsd":"^0.31.1","typescript":"5.3.3"},"tsd":{"directory":"test/types"}}');
9033490335

9033590336
/***/ }),
9033690337

@@ -90358,7 +90359,7 @@ module.exports = {"version":"3.17.0"};
9035890359
/***/ 8330:
9035990360
/***/ ((module) => {
9036090361

90361-
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"0.15.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
90362+
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.0.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
9036290363

9036390364
/***/ })
9036490365

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
/* eslint-disable @typescript-eslint/naming-convention */
3+
4+
export default {
5+
collectCoverage: true,
6+
coverageDirectory: 'coverage',
7+
coverageThreshold: {
8+
global: {
9+
branches: 60,
10+
functions: 60,
11+
lines: 60,
12+
statements: 60,
13+
},
14+
},
15+
preset: 'ts-jest/presets/default-esm',
16+
testEnvironment: 'node',
17+
extensionsToTreatAsEsm: ['.ts'],
18+
moduleNameMapper: {
19+
'^(\\.{1,2}/.*)\\.js$': '$1',
20+
},
21+
transform: {
22+
'^.+\\.tsx?$': [
23+
'ts-jest',
24+
{
25+
useESM: true,
26+
},
27+
],
28+
},
29+
testMatch: ['**/(test|tests)/**/*.test.{ts,tsx}'],
30+
}

package-lock.json

Lines changed: 57 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@krauters/github-notifier",
33
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
4-
"version": "0.15.0",
4+
"version": "1.0.0",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
77
"homepage": "https://buymeacoffee.com/coltenkrauter",
@@ -27,9 +27,13 @@
2727
"bundle:watch": "npm run bundle -- --watch",
2828
"bundle": "npx ncc build src/app.ts -o dist --source-map",
2929
"fix": "npm run lint -- --fix",
30-
"lint": "npx eslint src/**",
30+
"lint": "npx eslint src/** test/**",
3131
"prepare": "husky || true",
32-
"test": "npm run lint",
32+
"test": "npm run lint && npm run jest",
33+
"jest": "NODE_OPTIONS=--experimental-vm-modules jest",
34+
"jest:watch": "npm run jest -- --watch",
35+
"jest:coverage": "npm run jest -- --coverage",
36+
"jest:ci": "npm run jest -- --ci --coverage --reporters=default --reporters=jest-junit",
3337
"upgrade:all": "npx npm-check-updates -u && npm install"
3438
},
3539
"license": "ISC",
@@ -42,16 +46,17 @@
4246
"@krauters/utils": "^1.4.0",
4347
"@octokit/rest": "21.1.1",
4448
"@octokit/types": "13.10.0",
45-
"@slack/web-api": "7.9.0",
49+
"@slack/web-api": "7.9.1",
4650
"simple-git": "^3.27.0"
4751
},
4852
"devDependencies": {
4953
"@krauters/eslint-config": "^1.8.0",
5054
"@types/jest": "^29.5.14",
51-
"@types/node": "^22.13.13",
55+
"@types/node": "^22.13.14",
5256
"@vercel/ncc": "^0.38.3",
5357
"husky": "9.1.7",
5458
"jest": "^29.7.0",
59+
"jest-junit": "^16.0.0",
5560
"make-coverage-badge": "^1.2.0",
5661
"ts-jest": "^29.3.0",
5762
"ts-node": "^10.9.2",

src/utils/misc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { plural } from '@krauters/utils'
22

33
/**
44
* Get an emoji based on the age of something.
5+
*
56
* @param {number} hoursAgo - The number of hours ago since something happened.
67
* @returns {string}
78
*/
@@ -20,6 +21,7 @@ export function getAgeBasedEmoji(hoursAgo: number): string {
2021

2122
/**
2223
* Get the relative human readable age of something.
24+
*
2325
* @param {number} hoursAgo - The number of hours ago since something happened.
2426
* @param {boolean} [withAgo=true] - Whether to include the ' ago' suffix when appropriate.
2527
* @returns {string}

0 commit comments

Comments
 (0)