Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13576 from StateFarmIns/async-hmr-handlers
Allow HMR status handlers to return a Promise
- Loading branch information
Showing
5 changed files
with
104 additions
and
66 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
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,3 @@ | ||
module.exports = 1; | ||
--- | ||
module.exports = 2; |
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,27 @@ | ||
var value = require("./file"); | ||
|
||
it("should wait until promises returned by status handlers are fulfilled", (done) => { | ||
var handler = jest.fn(status => { | ||
var test = jest.fn(() => { | ||
expect(module.hot.status()).toBe(status == "dispose" ? "apply" : status); | ||
}); | ||
|
||
var promise = Promise.resolve().then(test); | ||
promise.test = test; | ||
|
||
return promise; | ||
}); | ||
module.hot.addStatusHandler(handler); | ||
module.hot.accept("./file", () => { | ||
value = require("./file"); | ||
}); | ||
NEXT(require("../../update")(done, undefined, () => { | ||
expect(handler.mock.calls).toStrictEqual([['check'], ['prepare'], ['dispose'], ['apply'], ['idle']]); | ||
for (let result of handler.mock.results) | ||
expect(result.value.test).toHaveBeenCalledTimes(1); | ||
|
||
expect(module.hot.status()).toBe("idle"); | ||
|
||
done(); | ||
})); | ||
}); |