Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(setupWorker): warn on multiple "worker.start" and "worker.stop" c…
…alls (#1238) * fix(setupWorker): print warning on multiple "worker.start()" calls * fix(setupWorker): print warning on multiple "worker.stop()" calls
- Loading branch information
1 parent
ac0406d
commit cfe0709
Showing
6 changed files
with
90 additions
and
22 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 |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import { devUtils } from '../../utils/internal/devUtils' | ||
import { SetupWorkerInternalContext, StopHandler } from '../glossary' | ||
import { printStopMessage } from './utils/printStopMessage' | ||
|
||
export const createStop = ( | ||
context: SetupWorkerInternalContext, | ||
): StopHandler => { | ||
return function stop() { | ||
// Warn developers calling "worker.stop()" more times than necessary. | ||
// This likely indicates a mistake in their code. | ||
if (!context.isMockingEnabled) { | ||
devUtils.warn( | ||
'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.', | ||
) | ||
return | ||
} | ||
|
||
/** | ||
* Signal the Service Worker to disable mocking for this client. | ||
* Use this an an explicit way to stop the mocking, while preserving | ||
* the worker-client relation. Does not affect the worker's lifecycle. | ||
*/ | ||
context.workerChannel.send('MOCK_DEACTIVATE') | ||
context.isMockingEnabled = false | ||
window.clearInterval(context.keepAliveInterval) | ||
|
||
printStopMessage({ quiet: context.startOptions?.quiet }) | ||
} | ||
} |
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