-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
They are useful for other plugins to tap into certain points of the build process. In this case a `devServerRunning` hook is introduced, which would allow a 3rd party plugin to, for example, display a QR code with the address the app is running on once the dev server started.
- Loading branch information
1 parent
0d59077
commit 1e7a999
Showing
4 changed files
with
41 additions
and
0 deletions.
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,5 @@ | ||
const SyncHook = require('tapable').SyncHook; | ||
|
||
module.exports = { | ||
devServerRunning: new SyncHook(), | ||
}; |
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,32 @@ | ||
const { create, watch } = require('./lib/cli'); | ||
const { hooks } = require('./lib/utils'); | ||
|
||
describe('preact', () => { | ||
let intervalId; | ||
|
||
afterEach(() => { | ||
clearInterval(intervalId); | ||
intervalId = null; | ||
}); | ||
|
||
it('should emit a devServerRunning event after the server starts', (done) => { | ||
let hookCalled; | ||
hooks.devServerRunning.tap('TestPlugin', () => { | ||
hookCalled = true; | ||
}); | ||
|
||
create('default').then((app) => { | ||
watch(app, 8083).then((server) => { | ||
// We need to wait not only for the server to start but also for the | ||
// stats to be printed to stdout. | ||
intervalId = setInterval(() => { | ||
if (hookCalled) { | ||
expect(hookCalled).toBe(true); | ||
server.close(); | ||
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