Skip to content

Commit

Permalink
Set 'development' as the default environment
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Jan 19, 2017
1 parent 617187b commit 1ddc6c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
11 changes: 10 additions & 1 deletion src/util/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
export function getEnv(): string {
if (typeof process !== 'undefined' && process.env.NODE_ENV) {
return process.env.NODE_ENV;
}

// default environment
return 'development';
}

export function isEnv(env: string): boolean {
return typeof process !== 'undefined' && process.env.NODE_ENV === env;
return getEnv() === env;
}

export function isProduction(): boolean {
Expand Down
28 changes: 12 additions & 16 deletions test/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@ describe('environment', () => {
});
});

it(`should return false if there's no value`, () => {
process.env.NODE_ENV = undefined;
assert.isFalse(isEnv('production'));
});

it(`should return false if there's no process`, () => {
const keepProcess = process;

process = undefined;
assert.isFalse(isEnv('production'));

process = keepProcess;
it(`should treat no proces.env.NODE_ENV as it'd be in development`, () => {
delete process.env.NODE_ENV;
assert.isTrue(isEnv('development'));
});
});

Expand All @@ -51,7 +42,7 @@ describe('environment', () => {

it('should return false if not in production', () => {
process.env.NODE_ENV = 'test';
assert.isFalse(isProduction());
assert.isTrue(!isProduction());
});
});

Expand All @@ -63,7 +54,7 @@ describe('environment', () => {

it('should return true if not in test', () => {
process.env.NODE_ENV = 'development';
assert.isFalse(isTest());
assert.isTrue(!isTest());
});
});

Expand All @@ -73,9 +64,14 @@ describe('environment', () => {
assert.isTrue(isDevelopment());
});

it('should return true if not in development', () => {
it('should return true if not in development and environment is defined', () => {
process.env.NODE_ENV = 'test';
assert.isFalse(isDevelopment());
assert.isTrue(!isDevelopment());
});

it('should make development as the default environment', () => {
delete process.env.NODE_ENV;
assert.isTrue(isDevelopment());
});
});
});

0 comments on commit 1ddc6c3

Please sign in to comment.