This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
Expose shutDownSequence for better end-to-end testing #81
Open
jeffrey-xiao
wants to merge
3
commits into
airbnb:master
Choose a base branch
from
jeffrey-xiao:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,13 +1,55 @@ | ||
import { assert } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import hypernova from '../server'; | ||
|
||
describe('Hypernova server', () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
sandbox.stub(process, 'exit'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('blows up if hypernova does not get getComponent', () => { | ||
assert.throws(hypernova, TypeError); | ||
}); | ||
|
||
it('starts up the hypernova server without blowing up', () => { | ||
hypernova({ devMode: true, getComponent: () => {} }); | ||
it('starts up the hypernova server without blowing up', (done) => { | ||
hypernova({ | ||
devMode: true, | ||
getComponent: () => {}, | ||
plugins: [ | ||
{ | ||
shutDown: () => { | ||
done(); | ||
}, | ||
}, | ||
], | ||
getClose: (close) => { | ||
close(null, null, 0); | ||
}, | ||
}); | ||
}); | ||
|
||
it('starts up the hypernova server again without blowing up', (done) => { | ||
hypernova({ | ||
devMode: true, | ||
getComponent: () => {}, | ||
plugins: [ | ||
{ | ||
shutDown: () => { | ||
done(); | ||
}, | ||
}, | ||
], | ||
getClose: (close) => { | ||
close(null, null, 0); | ||
}, | ||
}); | ||
}); | ||
}); |
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.
I don't think we want to delegate the responsibility of closing down the server to a callback. We should close and then fire off a callback when it's done.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for the feedback!
Would be better to expose
close
orshutDownSequence
inworker
tohypernova
?One of the problems I had writing tests when exposing those was that sometimes I was trying to close the http server when it hasn't been initialised yet.
Also isn't a callback when the server is shutdown necessary when you can create a plugin for the
shutdown
lifecycle event?@goatslacker @ljharb
Uh oh!
There was an error while loading. Please reload this page.
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.
@goatslacker the intent here is to be able to close down the hypernova server (and transitively the express & http server) from the consuming application on demand.
This is to set us up to have better end to end testing - currently we can only spin up one instance of hypernova per process (i.e. per test run). (more context linked in the body of the PR)
Is there a better way than a callback in the hypernova object to expose this functionality?
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.
@goatslacker @ljharb
Any more thoughts on this?