File tree 2 files changed +60
-0
lines changed
2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* index.test.js - Benchmark tests for React store context hooks functionality.
2
+ * Copyright (c) 2019 - 2021 Richard Huang <rickypc@users.noreply.github.com>
3
+ *
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7
+
8
+ import proxyquire from 'proxyquire' ;
9
+ import run from './runner.js' ;
10
+
11
+ const Component = ( ) => null ;
12
+ const context = {
13
+ get ( ) { } ,
14
+ remove ( ) { } ,
15
+ set ( ) { } ,
16
+ sets ( ) { } ,
17
+ } ;
18
+
19
+ const {
20
+ isEmpty,
21
+ useStore,
22
+ useStores,
23
+ withStore,
24
+ } = proxyquire ( '../src/index.js' , {
25
+ react : {
26
+ createContext : ( ) => context ,
27
+ useCallback : ( cb ) => cb ,
28
+ useContext : ( ) => context ,
29
+ useState ( ) { } ,
30
+ } ,
31
+ } ) ;
32
+
33
+ ( async ( ) => {
34
+ await run ( 'isEmpty' , ( ) => isEmpty ( false ) ) ;
35
+ await run ( 'useStore' , ( ) => useStore ( 'key' , 'default' ) ) ;
36
+ await run ( 'useStores' , ( ) => useStores ( { key1 : 'value1' } ) ) ;
37
+ await run ( 'withStore' , ( ) => withStore ( Component ) ) ;
38
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ /* runner.js - Benchmark test runner for React store context hooks.
2
+ * Copyright (c) 2019 - 2021 Richard Huang <rickypc@users.noreply.github.com>
3
+ *
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7
+
8
+ import Benchmark from 'benchmark' ;
9
+
10
+ Benchmark . options . maxTime = 0 ;
11
+ Benchmark . options . minSamples = 5 ;
12
+
13
+ export default ( name , fn ) => new Promise ( ( resolve ) => ( ( new Benchmark ( name ,
14
+ { defer : true , fn : async ( d ) => d . resolve ( await fn ( ) ) } ) )
15
+ . on ( 'complete' , ( evt ) => {
16
+ process . stdout . write ( `${ evt . target } \n` ) ;
17
+ resolve ( ) ;
18
+ } )
19
+ . on ( 'error' , ( evt ) => {
20
+ throw evt . target . error ;
21
+ } )
22
+ . run ( { async : true } ) ) ) ;
You can’t perform that action at this time.
0 commit comments