-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improved type resolution for action method #349
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
227421b
improved type resolution for action method
stevengill 5ae4ba5
added dtslint tests to integration folder
stevengill fee10f9
fixed up launch.json
stevengill a35d315
updated PR based on feedback
stevengill 8bb6838
added integration tests to top level npm test command
stevengill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@ | ||
# node / npm stuff | ||
/node_modules | ||
/package-lock.json |
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,53 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Integration Type Checker", | ||
"program": "${workspaceFolder}/node_modules/dtslint/bin/index.js", | ||
"args": [ | ||
"types" | ||
], | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "npm test", | ||
"cwd": "${workspaceFolder}", | ||
"runtimeExecutable": "npm", | ||
"runtimeArgs": [ | ||
"run-script", "test" | ||
], | ||
"port": 9229 | ||
|
||
}, | ||
] | ||
} | ||
|
||
/* | ||
[ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Integration Type Checker", | ||
"program": "${workspaceFolder}/node_modules/dtslint/bin/index.js", | ||
"args": [ | ||
"types" | ||
], | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
] | ||
*/ |
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,22 @@ | ||
## Integration tests | ||
|
||
This directory contains a minimal project used as an environment in which to run integration tests. | ||
|
||
It's important to isolate this test project from the overall project where the package is built in order to eliminate | ||
assumptions. Specifically, the `package.json` and other configuration files in this directory are meant to include | ||
the minimum requirements and nothing more. Here are a few ways this is set up: | ||
|
||
* The `@types/node` dependency is set to a version that corresponds to the lowest supported node version. This enforces | ||
that the distribution should work in projects who have chosen that particular version, since its the most likely to | ||
not have types that we accidentally depend on but shouldn't. | ||
|
||
* The `typescript` development dependency is set to the most modern version of typescript. It's not important to use the | ||
oldest supported version because the `dtslint` tool will run the typechecker result integration tests on each | ||
supported version of TypeScript. It reads the oldest supported version from `types/index.d.ts`. | ||
|
||
* The `tsconfig.json` file is specifically set to the most strict settings as well as the most minimal requirements. | ||
This is specifically chosen to verify that the requirements expressed in the documentation are sufficient and | ||
represent the least amount of configuration needed to get the package working. | ||
|
||
* In `package.json`, the `"private"` key must remain set to `true`. This enforces that this project doesn't get | ||
accidentally published. |
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/bolt-integration-tests", | ||
"private": true, | ||
"description": "Integration tests for Bolt", | ||
"author": "Slack Technologies, Inc.", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "npm run test:typechecker", | ||
"test:typechecker": "dtslint types" | ||
}, | ||
"dependencies": { | ||
"@slack/bolt": "file:..", | ||
"@types/node": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"dtslint": "^0.5.4", | ||
"typescript": "^3.7.3" | ||
} | ||
} |
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,64 @@ | ||
// import App, { ActionConstraints } from '../../src/App'; | ||
import { App, MessageAction } from '@slack/bolt'; | ||
|
||
const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' }); | ||
|
||
// calling action method with incorrect an type constraint value should not work | ||
// $ExpectError | ||
app.action({ type: 'Something wrong' }, ({ action }) => { | ||
return action; | ||
}); | ||
|
||
/* Not working | ||
// Should error because message_action doesn't have type action_id | ||
// $ Expect Error | ||
app.action({ type: 'message_action', action_id: 'dafasf' }, ({ action }) => { | ||
return action; | ||
}); | ||
*/ | ||
|
||
// Action in listner should be - MessageAction | ||
// $ExpectType void | ||
app.action({ type: 'message_action' }, ({ | ||
action, // $ExpectType MessageAction | ||
}) => { | ||
return action; | ||
}); | ||
|
||
// $ExpectType void | ||
app.action({ type: 'block_actions' }, ({ | ||
action, // $ExpectType BlockElementAction | ||
aoberoi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) => { | ||
return action; | ||
}); | ||
|
||
// $ExpectType void | ||
app.action({ type: 'interactive_message' }, ({ | ||
action, // $ExpectType InteractiveAction | ||
}) => { | ||
return action; | ||
}); | ||
|
||
// $ExpectType void | ||
app.action({ type: 'dialog_submission' }, ({ | ||
action, // $ExpectType DialogSubmitAction | ||
}) => { | ||
return action; | ||
}); | ||
|
||
// If action is parameterized with MessageAction, action argument in callback should be type MessageAction | ||
// $ExpectType void | ||
app.action<MessageAction>({}, ({ | ||
action // $ExpectType MessageAction | ||
}) => { | ||
return action; | ||
}); | ||
|
||
/* Not working | ||
// Should error because MessageAction doesn't have an action_id | ||
// $ Expect Error | ||
app.actiong<MessageAction>({ action_id: 'dafasf' }, ({ action }) => { | ||
// NOT WORKING | ||
return action; | ||
}); | ||
*/ |
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 @@ | ||
// tslint:disable:no-useless-files | ||
// TypeScript Version: 3.3 |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"lib": ["es5"] | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be the
npm test
script instead of directly trying to rundtslint
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that by following https://code.visualstudio.com/docs/nodejs/nodejs-debugging, but it seems very specific to the debug command. I've tried swapping it for
npm test
, but it just hangs.