Skip to content

Commit e4fb562

Browse files
committed
specs.
1 parent a300265 commit e4fb562

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

configuration/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const path = require('path');
2-
const { isProduction, PRODUCTION} = require('../src/lib');
2+
const { env, isProduction } = require('../src/lib');
33

44
const root = path.resolve(__dirname, '..');
55

66
module.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',

src/lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
*/
55
const PRODUCTION = 'production';
66

7+
const env = process.env.NODE_ENV || PRODUCTION;
8+
79
module.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
};

src/lib/spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
});

0 commit comments

Comments
 (0)