File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 11const path = require ( 'path' ) ;
2- const { isProduction , PRODUCTION } = require ( '../src/lib' ) ;
2+ const { env , isProduction } = require ( '../src/lib' ) ;
33
44const root = path . resolve ( __dirname , '..' ) ;
55
66module . exports = {
7- mode : process . env . NODE_ENV || PRODUCTION ,
7+ mode : env ,
88 devtool : 'source-map' ,
99 entry : path . join ( root , 'index.js' ) ,
1010 target : 'node' ,
Original file line number Diff line number Diff line change 44 */
55const PRODUCTION = 'production' ;
66
7+ const env = process . env . NODE_ENV || PRODUCTION ;
8+
79module . exports = {
8- PRODUCTION ,
9- isProduction : ( ) => process . env . NODE_ENV || PRODUCTION ,
10+ env ,
11+ isProduction : ( environment = env ) => environment === PRODUCTION ,
1012 isUndefined : ( thing ) => [ null , undefined ] . includes ( thing )
1113} ;
Original file line number Diff line number Diff line change 1+ const lib = require ( '.' ) ;
2+
3+ describe ( 'Lib' , ( ) => {
4+ describe ( 'isProduction' , ( ) => {
5+
6+ it . each ( [
7+ 'something' ,
8+ 'dev'
9+ ] ) ( 'Returns falsy when env - (%p) is not production' , ( env ) => {
10+ expect ( lib . isProduction ( env ) ) . toBeFalsy ( ) ;
11+ } ) ;
12+
13+ it ( 'Returns truthy when running on production' , ( ) => {
14+ expect ( lib . isProduction ( 'production' ) ) . toBeTruthy ( ) ;
15+ } ) ;
16+ } ) ;
17+
18+ describe ( 'isUndefined' , ( ) => {
19+ it . each ( [
20+ 'String' ,
21+ false ,
22+ { } ,
23+ 1
24+ ] ) ( 'Returns falsy when given value is defined' , ( val ) => {
25+ expect ( lib . isUndefined ( val ) ) . toBeFalsy ( ) ;
26+ } ) ;
27+
28+ it . each ( [
29+ undefined ,
30+ null
31+ ] ) ( 'Returns truthy when value is undefined' , ( val ) => {
32+ expect ( lib . isUndefined ( val ) ) . toBeTruthy ( ) ;
33+ } ) ;
34+ } ) ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments