-
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
Fix #248 by adding a new option deferInitialization #1303
Changes from 7 commits
9edef5b
0a67221
cd57645
e837905
fa695ae
3b7b6aa
f4d52c9
ebb7da2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ const app = new App({ | |
}, | ||
unhandledRequestTimeoutMillis: 2000, // the default is 3001 | ||
}), | ||
// This option enables developer to call #init() in async/await style | ||
deferInitialization: true, | ||
}); | ||
|
||
app.use(async ({ logger, context, next }) => { | ||
|
@@ -41,7 +43,12 @@ app.use(async ({ logger, context, next }) => { | |
|
||
(async () => { | ||
// Start your app | ||
await app.start(process.env.PORT || 3000); | ||
|
||
try { | ||
await app.init(); | ||
await app.start(process.env.PORT || 3000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't call
|
||
} catch (e) { | ||
console.error(e); | ||
process.exit(255); | ||
} | ||
console.log('⚡️ Bolt app is running!'); | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
"name": "bolt-js-custom-properties-app", | ||
"version": "1.0.0", | ||
"description": "Having custom request properties in ⚡️ Bolt for JavaScript", | ||
"main": "app.js", | ||
"main": "http.js", | ||
"scripts": { | ||
"ngrok": "ngrok http 3000", | ||
"start": "node app.js", | ||
"start": "node http.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been incorrect since I've renamed the source file. |
||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"license": "MIT", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,49 @@ describe('App', () => { | |
// Assert | ||
assert.instanceOf(app, MockApp); | ||
}); | ||
|
||
it('should fail in await App#init()', async () => { | ||
// Arrange | ||
const fakeConstructor = sinon.fake(); | ||
const overrides = mergeOverrides(withNoopAppMetadata(), { | ||
'@slack/web-api': { | ||
WebClient: class { | ||
public constructor() { | ||
fakeConstructor(...arguments); // eslint-disable-line prefer-rest-params | ||
} | ||
|
||
public auth = { | ||
test: () => { | ||
throw new Error('Failing for init() test!'); | ||
}, | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
const MockApp = await importApp(overrides); | ||
const app = new MockApp({ | ||
token: 'xoxb-completely-invalid-token', | ||
signingSecret: 'invalid-one', | ||
deferInitialization: true, | ||
}); | ||
// Assert | ||
assert.instanceOf(app, MockApp); | ||
try { | ||
// call #start() before #init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this test pattern |
||
await app.start(); | ||
assert.fail('The start() method should fail before init() call'); | ||
} catch (err: any) { | ||
assert.equal(err.message, 'This App instance is not yet initialized. Call `await App#init()` before starting the app.'); | ||
} | ||
try { | ||
await app.init(); | ||
assert.fail('The init() method should fail here'); | ||
} catch (err: any) { | ||
assert.equal(err.message, 'Failing for init() test!'); | ||
} | ||
}); | ||
|
||
// TODO: tests for ignoreSelf option | ||
// TODO: tests for logger and logLevel option | ||
// TODO: tests for providing botId and botUserId options | ||
|
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.
Example error pattern: