-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(server): add stdin for API #2106
Closed
Closed
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
abcdf20
feat(server): add stdin for api
knagaitsev aa26a3b
test(server): change cli test to see if time out without stdin
knagaitsev 821a75a
test(client): check for fail instead of timedOut
knagaitsev e7b4d36
test(client): loosen failure restriction on cli with no stdin
knagaitsev 98ccd7b
test(server): update execa
knagaitsev b93bdeb
test(server): switch from waiting for time out to killing child process
knagaitsev f32cfe1
test(server): downgrade execa
knagaitsev 8c23ede
test(cli): temporarily remove stdin cli tests
knagaitsev c95ba88
test(cli): switch to spawn for stdin test
knagaitsev 33ff4f6
test(server): changed env for cli tests
knagaitsev 87bf035
test(cli): switch waiting for close to exit event
knagaitsev c93b1f9
test(cli): added error event listener for debugging
knagaitsev fcca53e
test(cli): remove sigterm test
knagaitsev 6bf64de
test(cli): disable stdin cli tests temporarily
knagaitsev 404f983
test(options): remove stdin options test temporarily
knagaitsev 93fca66
test(options): add stdin end emit
knagaitsev 948a724
test(options): move stdin end emit to right after server creation
knagaitsev 02567e3
test(cli): remove stdin cli tests temporarily again
knagaitsev 5a38b8f
test(options): remove stdin option test again temporarily
knagaitsev 33fb577
test(options): remove end emit
knagaitsev ff5d730
test(server): remove some stdin end emits
knagaitsev 5cbc2a4
test(server): add stdin pause next to end emit
knagaitsev d849568
test(cli): switch back to execa from spawn
knagaitsev d182b07
test(cli): upgrade execa
knagaitsev 17fddfc
test(cli): switch back to spawn
knagaitsev d670177
test(cli): downgrade execa again
knagaitsev 2bc9387
test(server): forcefully remove stdin end listeners
knagaitsev 0c9f4bb
fix(package): fix package lock
knagaitsev ddc12d3
fix(package): fix package lock again
knagaitsev 48a40b4
test(server): skip new stdin tests
knagaitsev fcef89d
test(server): removed stdin tests entirely
knagaitsev 2634594
test(server): remove cli test
knagaitsev 5db844a
test(server): remove options test
knagaitsev b3b3299
test(server): add back stdin files
knagaitsev 959c0ed
test(server): only cli stdin
knagaitsev 66cd1df
test(server): add handle stdin helper only
knagaitsev bf90582
test(server): add stdin option test only
knagaitsev 28a7073
test(server): only handle stdin
knagaitsev ec41502
test(server): move stdin pause after a delay following stdin resume
knagaitsev b35e8ac
test(options): removed exit mock
knagaitsev 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
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
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,16 @@ | ||
'use strict'; | ||
|
||
function handleStdin(options) { | ||
if (options.stdin) { | ||
// listening for this event only once makes testing easier, | ||
// since it prevents event listeners from hanging open | ||
process.stdin.once('end', () => { | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(0); | ||
}); | ||
|
||
process.stdin.resume(); | ||
} | ||
} | ||
|
||
module.exports = handleStdin; |
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
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
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,65 @@ | ||
'use strict'; | ||
|
||
const config = require('../fixtures/simple-config/webpack.config'); | ||
const testServer = require('../helpers/test-server'); | ||
const port = require('../ports-map')['stdin-option']; | ||
|
||
describe('stdin', () => { | ||
// eslint-disable-next-line no-unused-vars | ||
let server; | ||
let exitSpy; | ||
|
||
beforeAll(() => { | ||
exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach((done) => { | ||
server = null; | ||
exitSpy.mockReset(); | ||
process.stdin.removeAllListeners('end'); | ||
testServer.close(done); | ||
}); | ||
|
||
describe('enabled', () => { | ||
beforeAll((done) => { | ||
server = testServer.start( | ||
config, | ||
{ | ||
port, | ||
stdin: true, | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should exit process', (done) => { | ||
process.stdin.emit('end'); | ||
setTimeout(() => { | ||
process.stdin.pause(); | ||
expect(exitSpy.mock.calls[0]).toEqual([0]); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
|
||
describe('disabled (default)', () => { | ||
beforeAll((done) => { | ||
server = testServer.start( | ||
config, | ||
{ | ||
port, | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should not exit process', (done) => { | ||
process.stdin.emit('end'); | ||
setTimeout(() => { | ||
process.stdin.pause(); | ||
expect(exitSpy.mock.calls.length).toEqual(0); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); |
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,42 @@ | ||
'use strict'; | ||
|
||
const handleStdin = require('../../../lib/utils/handleStdin'); | ||
|
||
describe('handleStdin', () => { | ||
let exitSpy; | ||
|
||
beforeAll(() => { | ||
exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
process.stdin.removeAllListeners('end'); | ||
exitSpy.mockReset(); | ||
}); | ||
|
||
describe('enabled', () => { | ||
it('should exit process', (done) => { | ||
handleStdin({ | ||
stdin: true, | ||
}); | ||
process.stdin.emit('end'); | ||
setTimeout(() => { | ||
process.stdin.pause(); | ||
expect(exitSpy.mock.calls[0]).toEqual([0]); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
|
||
describe('disabled (default)', () => { | ||
it('should not exit process', (done) => { | ||
handleStdin({}); | ||
process.stdin.emit('end'); | ||
setTimeout(() => { | ||
process.stdin.pause(); | ||
expect(exitSpy.mock.calls.length).toEqual(0); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); |
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.
hm, why we need it here?
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.
@evilebottnawi Do you think no helper would be better? I just thought having helper would be cleaner
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 think we need this inside server file, it is logic for CLI only