Skip to content

Commit 3af9966

Browse files
committed
test: jest setup and unit tests
1 parent 71b91f8 commit 3af9966

File tree

12 files changed

+1658
-23
lines changed

12 files changed

+1658
-23
lines changed

dist/index.js

Lines changed: 5 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) => {
@@ -90330,7 +90329,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"@aws-sdk/nested-clients","ver
9033090329
/***/ 56734:
9033190330
/***/ ((module) => {
9033290331

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"}}');
90332+
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"}}');
9033490333

9033590334
/***/ }),
9033690335

@@ -90358,7 +90357,7 @@ module.exports = {"version":"3.17.0"};
9035890357
/***/ 8330:
9035990358
/***/ ((module) => {
9036090359

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

9036390362
/***/ })
9036490363

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",

test/utils/github/mock-data.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
import type { GitHubRepository } from '../../../src/utils/github/structures.js'
3+
4+
// This file contains mock data that mirrors GitHub API responses
5+
// We're using snake_case to match the API format
6+
export const mockRepository: GitHubRepository = {
7+
archive_url: 'https://api.github.com/repos/test-org/test-repo/{archive_format}{/ref}',
8+
archived: false,
9+
assignees_url: 'https://api.github.com/repos/test-org/test-repo/assignees{/user}',
10+
blobs_url: 'https://api.github.com/repos/test-org/test-repo/git/blobs{/sha}',
11+
branches_url: 'https://api.github.com/repos/test-org/test-repo/branches{/branch}',
12+
clone_url: 'https://github.com/test-org/test-repo.git',
13+
collaborators_url: 'https://api.github.com/repos/test-org/test-repo/collaborators{/collaborator}',
14+
comments_url: 'https://api.github.com/repos/test-org/test-repo/comments{/number}',
15+
commits_url: 'https://api.github.com/repos/test-org/test-repo/commits{/sha}',
16+
compare_url: 'https://api.github.com/repos/test-org/test-repo/compare/{base}...{head}',
17+
contents_url: 'https://api.github.com/repos/test-org/test-repo/contents/{+path}',
18+
contributors_url: 'https://api.github.com/repos/test-org/test-repo/contributors',
19+
created_at: new Date().toISOString(),
20+
default_branch: 'main',
21+
deployments_url: 'https://api.github.com/repos/test-org/test-repo/deployments',
22+
description: 'Test repository',
23+
disabled: false,
24+
downloads_url: 'https://api.github.com/repos/test-org/test-repo/downloads',
25+
events_url: 'https://api.github.com/repos/test-org/test-repo/events',
26+
fork: false,
27+
forks: 0,
28+
forks_count: 0,
29+
forks_url: 'https://api.github.com/repos/test-org/test-repo/forks',
30+
full_name: 'test-org/test-repo',
31+
git_commits_url: 'https://api.github.com/repos/test-org/test-repo/git/commits{/sha}',
32+
git_refs_url: 'https://api.github.com/repos/test-org/test-repo/git/refs{/sha}',
33+
git_tags_url: 'https://api.github.com/repos/test-org/test-repo/git/tags{/sha}',
34+
git_url: 'git:github.com/test-org/test-repo.git',
35+
has_downloads: true,
36+
has_issues: true,
37+
has_pages: false,
38+
has_projects: true,
39+
has_wiki: true,
40+
homepage: '',
41+
hooks_url: 'https://api.github.com/repos/test-org/test-repo/hooks',
42+
html_url: 'https://github.com/test-org/test-repo',
43+
id: 1,
44+
issue_comment_url: 'https://api.github.com/repos/test-org/test-repo/issues/comments{/number}',
45+
issue_events_url: 'https://api.github.com/repos/test-org/test-repo/issues/events{/number}',
46+
issues_url: 'https://api.github.com/repos/test-org/test-repo/issues{/number}',
47+
keys_url: 'https://api.github.com/repos/test-org/test-repo/keys{/key_id}',
48+
labels_url: 'https://api.github.com/repos/test-org/test-repo/labels{/name}',
49+
language: null,
50+
languages_url: 'https://api.github.com/repos/test-org/test-repo/languages',
51+
license: null,
52+
merges_url: 'https://api.github.com/repos/test-org/test-repo/merges',
53+
milestones_url: 'https://api.github.com/repos/test-org/test-repo/milestones{/number}',
54+
mirror_url: '',
55+
name: 'test-repo',
56+
network_count: 0,
57+
node_id: 'node1',
58+
notifications_url: 'https://api.github.com/repos/test-org/test-repo/notifications{?since,all,participating}',
59+
open_issues: 0,
60+
open_issues_count: 0,
61+
owner: {
62+
avatar_url: 'https://avatars.githubusercontent.com/u/1',
63+
events_url: 'https://api.github.com/users/test-org/events{/privacy}',
64+
followers_url: 'https://api.github.com/users/test-org/followers',
65+
following_url: 'https://api.github.com/users/test-org/following{/other_user}',
66+
gists_url: 'https://api.github.com/users/test-org/gists{/gist_id}',
67+
gravatar_id: '',
68+
html_url: 'https://github.com/test-org',
69+
id: 1,
70+
login: 'test-org',
71+
node_id: 'node1',
72+
organizations_url: 'https://api.github.com/users/test-org/orgs',
73+
received_events_url: 'https://api.github.com/users/test-org/received_events',
74+
repos_url: 'https://api.github.com/users/test-org/repos',
75+
site_admin: false,
76+
starred_url: 'https://api.github.com/users/test-org/starred{/owner}{/repo}',
77+
subscriptions_url: 'https://api.github.com/users/test-org/subscriptions',
78+
type: 'Organization',
79+
url: 'https://api.github.com/users/test-org',
80+
},
81+
permissions: {
82+
admin: true,
83+
pull: true,
84+
push: true,
85+
},
86+
private: true,
87+
pulls_url: 'https://api.github.com/repos/test-org/test-repo/pulls{/number}',
88+
pushed_at: new Date().toISOString(),
89+
releases_url: 'https://api.github.com/repos/test-org/test-repo/releases{/id}',
90+
size: 0,
91+
ssh_url: 'git@github.com:test-org/test-repo.git',
92+
stargazers_count: 0,
93+
stargazers_url: 'https://api.github.com/repos/test-org/test-repo/stargazers',
94+
statuses_url: 'https://api.github.com/repos/test-org/test-repo/statuses/{sha}',
95+
subscribers_count: 0,
96+
subscribers_url: 'https://api.github.com/repos/test-org/test-repo/subscribers',
97+
subscription_url: 'https://api.github.com/repos/test-org/test-repo/subscription',
98+
svn_url: 'https://github.com/test-org/test-repo',
99+
tags_url: 'https://api.github.com/repos/test-org/test-repo/tags',
100+
teams_url: 'https://api.github.com/repos/test-org/test-repo/teams',
101+
topics: [],
102+
trees_url: 'https://api.github.com/repos/test-org/test-repo/git/trees{/sha}',
103+
updated_at: new Date().toISOString(),
104+
url: 'https://api.github.com/repos/test-org/test-repo',
105+
visibility: 'private',
106+
watchers: 0,
107+
watchers_count: 0,
108+
}

0 commit comments

Comments
 (0)