-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: regorganize Context and Suite State (#413)
Use Context package
- Loading branch information
Showing
48 changed files
with
388 additions
and
681 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
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,58 +1,7 @@ | ||
import createStore from '../../lib/createStorage'; | ||
import { KEY_CANCELED, KEY_SUITES } from './constants'; | ||
|
||
export const { get, set, register } = (() => { | ||
const storage = { | ||
state: { | ||
[KEY_SUITES]: {}, | ||
[KEY_CANCELED]: {}, | ||
}, | ||
}; | ||
|
||
/** | ||
* Retrieves the state object or a portion of it. | ||
*/ | ||
const get = () => storage.state; | ||
|
||
/** | ||
* Updates the state with the value return from the setter callback. | ||
* @param {Function} setter setter function. | ||
* @returns {Object} updated state. | ||
*/ | ||
const set = setter => { | ||
storage.state = setter(get()); | ||
|
||
return get(); | ||
}; | ||
|
||
const register = () => | ||
set( | ||
state => | ||
state ?? { | ||
[KEY_SUITES]: {}, | ||
[KEY_CANCELED]: {}, | ||
} | ||
); | ||
|
||
register(); | ||
|
||
return { get, set, register }; | ||
})(); | ||
|
||
/** | ||
* Updates the state with the output of the setter callback. | ||
* @param {Function} setter | ||
* @returns {Object} all the suites in the state. | ||
*/ | ||
export const setSuites = setter => { | ||
set(state => { | ||
state[KEY_SUITES] = setter(state[KEY_SUITES]); | ||
return state; | ||
}); | ||
return get()[KEY_SUITES]; | ||
}; | ||
|
||
/** | ||
* @param {string} suiteId. | ||
* @returns {Object} Suite from state. | ||
*/ | ||
export const getSuite = suiteId => get()[KEY_SUITES][suiteId]; | ||
export default createStore(() => ({ | ||
[KEY_SUITES]: {}, | ||
[KEY_CANCELED]: {}, | ||
})); |
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,16 @@ | ||
import getState from '../getState'; | ||
import hasRemainingTests from '../hasRemainingTests'; | ||
import remove from '../remove'; | ||
import * as suiteState from '../suiteState'; | ||
/** | ||
* Removes completed "stateless" suite from state storage. | ||
* @param {string} suiteId | ||
*/ | ||
const cleanupCompleted = suiteId => { | ||
const state = getState(suiteId); | ||
const state = suiteState.getCurrentState(suiteId); | ||
|
||
if (hasRemainingTests(state)) { | ||
return; | ||
} | ||
remove(suiteId); | ||
suiteState.remove(suiteId); | ||
}; | ||
|
||
export default cleanupCompleted; |
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
Oops, something went wrong.