-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an example 'Hello, world' app with tests (#4)
* feat: add an example 'Hello, world' app with tests * Exclude examples dir
- Loading branch information
1 parent
2249936
commit 2d9b1c1
Showing
8 changed files
with
2,835 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Slack Testing Library: Hello World example | ||
|
||
> A simple Slack app that publishes "Hello, world!" to the App Home | ||
## Structure | ||
|
||
### `./server.ts` | ||
|
||
This is the simple HTTP server that powers this Slack app. | ||
|
||
### `./__tests__/app-home.test.ts` | ||
|
||
The example test that verifies the App Home displays the correct text, once the app home is opened. | ||
|
||
## Getting started | ||
|
||
1. Install dependencies | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
2. Run the HTTP server | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
3. Run the tests | ||
|
||
```bash | ||
yarn test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SlackTestingLibrary } from "../../../src/slack-testing-library"; | ||
// import { SlackTestingLibrary } from 'slack-testing-library'; | ||
|
||
const sl = new SlackTestingLibrary({ | ||
baseUrl: "http://localhost:3000", | ||
}); | ||
|
||
describe("App home", () => { | ||
beforeAll(async () => { | ||
await sl.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await sl.teardown(); | ||
}); | ||
|
||
it("should show the text 'Hello, world!' after opening", async () => { | ||
sl.actAs({ | ||
teamId: "T12345678", | ||
userId: "U12345678", | ||
}); | ||
|
||
await sl.openHome(); | ||
await sl.getByText("Hello, world!"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@slack-testing-library/hello-world-app-home-example", | ||
"version": "1.0.0", | ||
"main": "server.ts", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "ts-node server.ts", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@slack/types": "^2.2.0", | ||
"@slack/web-api": "^6.4.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^27.1.0", | ||
"ts-jest": "^27.0.5", | ||
"ts-node": "^10.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createServer } from "http"; | ||
import { WebClient } from "@slack/web-api"; | ||
|
||
const slackWebApi = new WebClient(process.env.SLACK_BOT_TOKEN, { | ||
slackApiUrl: "http://localhost:8123/slack/api", | ||
}); | ||
|
||
const server = createServer(async (_req, res) => { | ||
await slackWebApi.views.publish({ | ||
view: { | ||
type: "home", | ||
blocks: [ | ||
{ | ||
type: "section", | ||
text: { | ||
text: "Hello, world!", | ||
type: "plain_text", | ||
}, | ||
}, | ||
], | ||
}, | ||
user_id: "U12345678", | ||
}); | ||
|
||
res.end(); | ||
}); | ||
|
||
server.listen(3000, () => { | ||
console.log("Server listening on port 3000"); | ||
}); |
Oops, something went wrong.