mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-20 14:17:29 -04:00
Return 'dev' as the version if running in development (#2462)
This commit is contained in:
@@ -5,6 +5,7 @@ import { lintSpecification } from '../commands/lint-specification';
|
||||
import { runInsomniaTests } from '../commands/run-tests';
|
||||
import { exportSpecification } from '../commands/export-specification';
|
||||
import { parseArgsStringToArgv } from 'string-argv';
|
||||
import * as packageJson from '../../package.json';
|
||||
|
||||
jest.mock('../commands/generate-config');
|
||||
jest.mock('../commands/lint-specification');
|
||||
@@ -43,6 +44,20 @@ describe('cli', () => {
|
||||
it('should throw error if working dir argument is missing', () => {
|
||||
expect(() => inso('-w')).toThrowError();
|
||||
});
|
||||
|
||||
it.each(['-v', '--version'])('inso %s should print version from package.json', args => {
|
||||
jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
expect(() => inso(args)).toThrowError(packageJson.version);
|
||||
});
|
||||
|
||||
it.each(['-v', '--version'])('inso %s should print "dev" if running in development', args => {
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
expect(() => inso(args)).toThrowError('dev');
|
||||
|
||||
process.env.NODE_ENV = oldNodeEnv;
|
||||
});
|
||||
});
|
||||
|
||||
describe('generate config', () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// @flow
|
||||
import execa from 'execa';
|
||||
import { getBinPathSync } from 'get-bin-path';
|
||||
import * as packageJson from '../../package.json';
|
||||
|
||||
// MAKE SURE YOU BUILD THE PROJECT BEFORE RUNNING THESE TESTS.
|
||||
// These tests use the executable /bin/inso, which relies on /dist.
|
||||
@@ -28,14 +27,3 @@ describe('Snapshot for', () => {
|
||||
30000,
|
||||
);
|
||||
});
|
||||
|
||||
describe('Inso version', () => {
|
||||
it.each(['-v', '--version'])(
|
||||
'inso %s should print version from package.json',
|
||||
async args => {
|
||||
const { stdout } = await execa(getBinPathSync(), args.split(' '));
|
||||
expect(stdout).toBe(packageJson.version);
|
||||
},
|
||||
30000,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import { exit, logErrorExit1, getDefaultAppDataDir } from '../util';
|
||||
import { exit, logErrorExit1, getDefaultAppDataDir, getVersion, isDevelopment } from '../util';
|
||||
import * as packageJson from '../../package.json';
|
||||
|
||||
describe('exit()', () => {
|
||||
it('should exit 0 if successful result', async () => {
|
||||
@@ -68,3 +69,40 @@ describe('getDefaultAppDataDir()', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getVersion()', () => {
|
||||
it('should return version from packageJson', () => {
|
||||
expect(getVersion()).toBe(packageJson.version);
|
||||
});
|
||||
|
||||
it('should return dev if running in development', () => {
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
expect(getVersion()).toBe('dev');
|
||||
|
||||
process.env.NODE_ENV = oldNodeEnv;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isDevelopment()', () => {
|
||||
it('should return true if NODE_ENV is development', () => {
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
expect(isDevelopment()).toBe(true);
|
||||
|
||||
process.env.NODE_ENV = oldNodeEnv;
|
||||
});
|
||||
|
||||
it('should return false if NODE_ENV is not development', () => {
|
||||
const oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = 'production';
|
||||
expect(isDevelopment()).toBe(false);
|
||||
|
||||
process.env.NODE_ENV = oldNodeEnv;
|
||||
});
|
||||
|
||||
it('should return dev if running in development', () => {});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
import * as packageJson from '../package.json';
|
||||
|
||||
export function getVersion() {
|
||||
return packageJson.version;
|
||||
return isDevelopment() ? 'dev' : packageJson.version;
|
||||
}
|
||||
|
||||
export function isDevelopment() {
|
||||
return process.env.NODE_ENV === 'development';
|
||||
}
|
||||
|
||||
export function logErrorExit1(err: Error) {
|
||||
|
||||
Reference in New Issue
Block a user