mirror of https://github.com/Seich/Beau.git
Added a warning when module version and beau.yml version differ.
This commit is contained in:
parent
7aed5f0085
commit
cf56f4b2e4
|
|
@ -1,23 +1,23 @@
|
||||||
const ListCommand = require('../commands/list');
|
const ListCommand = require('../commands/list');
|
||||||
|
|
||||||
|
jest.mock('../../../src/shared');
|
||||||
|
|
||||||
jest.mock('../utils');
|
jest.mock('../utils');
|
||||||
|
|
||||||
describe('List Command', () => {
|
describe('List Command', () => {
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
result = [];
|
result = [];
|
||||||
jest
|
jest.spyOn(process.stdout, 'write').mockImplementation(val =>
|
||||||
.spyOn(process.stdout, 'write')
|
result.push(require('strip-ansi')(val.toString('utf8')))
|
||||||
.mockImplementation(val =>
|
);
|
||||||
result.push(require('strip-ansi')(val.toString('utf8')))
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => jest.restoreAllMocks());
|
afterEach(() => jest.restoreAllMocks());
|
||||||
|
|
||||||
test.each([[], ['--no-format']])('with flags:', async (...args) => {
|
test.each([[], ['--no-format']])('with flags:', async (...args) => {
|
||||||
await ListCommand.run(args);
|
await ListCommand.run(args);
|
||||||
expect(result).toMatchSnapshot();
|
expect(result).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
const RequestCommand = require('../commands/request');
|
const RequestCommand = require('../commands/request');
|
||||||
const requestPromiseNativeMock = require('request-promise-native');
|
const requestPromiseNativeMock = require('request-promise-native');
|
||||||
|
|
||||||
|
jest.mock('../../../src/shared');
|
||||||
|
|
||||||
jest.mock('../utils');
|
jest.mock('../utils');
|
||||||
|
|
||||||
describe('Request Command', () => {
|
describe('Request Command', () => {
|
||||||
|
|
@ -9,11 +11,9 @@ describe('Request Command', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
requestPromiseNativeMock.fail = false;
|
requestPromiseNativeMock.fail = false;
|
||||||
result = [];
|
result = [];
|
||||||
jest
|
jest.spyOn(process.stdout, 'write').mockImplementation(val =>
|
||||||
.spyOn(process.stdout, 'write')
|
result.push(require('strip-ansi')(val.toString('utf8')))
|
||||||
.mockImplementation(val =>
|
);
|
||||||
result.push(require('strip-ansi')(val.toString('utf8')))
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => jest.restoreAllMocks());
|
afterEach(() => jest.restoreAllMocks());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
const utils = require('../utils.js');
|
const utils = require('../utils.js');
|
||||||
|
|
||||||
|
jest.mock('../../../src/shared');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
|
|
||||||
describe('utils', () => {
|
describe('utils', () => {
|
||||||
|
|
|
||||||
|
|
@ -3,27 +3,25 @@ const ValidateCommand = require('../commands/validate');
|
||||||
jest.mock('../utils');
|
jest.mock('../utils');
|
||||||
|
|
||||||
describe('Validate Command', () => {
|
describe('Validate Command', () => {
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
result = [];
|
result = [];
|
||||||
jest
|
jest.spyOn(process.stdout, 'write').mockImplementation(val =>
|
||||||
.spyOn(process.stdout, 'write')
|
result.push(require('strip-ansi')(val.toString('utf8')))
|
||||||
.mockImplementation(val =>
|
);
|
||||||
result.push(require('strip-ansi')(val.toString('utf8')))
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => jest.restoreAllMocks());
|
afterEach(() => jest.restoreAllMocks());
|
||||||
|
|
||||||
it('should validate the configuration file', async () => {
|
it('should validate the configuration file', async () => {
|
||||||
await ValidateCommand.run([]);
|
await ValidateCommand.run([]);
|
||||||
expect(result).toMatchSnapshot();
|
expect(result).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show schema errors', async () => {
|
it('should show schema errors', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
ValidateCommand.run(['invalid-conf.yml'])
|
ValidateCommand.run(['invalid-conf.yml'])
|
||||||
).rejects.toThrow();
|
).rejects.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = {
|
||||||
|
...require.requireActual('../shared'),
|
||||||
|
moduleVersion: jest.fn().mockReturnValue(1)
|
||||||
|
};
|
||||||
|
|
@ -7,7 +7,7 @@ Object {
|
||||||
"body": Object {
|
"body": Object {
|
||||||
"username": "seich",
|
"username": "seich",
|
||||||
},
|
},
|
||||||
"endpoint": "http://martianwabbit.com/user",
|
"endpoint": "http://example.com/user",
|
||||||
"headers": Object {
|
"headers": Object {
|
||||||
"authentication": "BEARER abc123",
|
"authentication": "BEARER abc123",
|
||||||
},
|
},
|
||||||
|
|
@ -25,7 +25,7 @@ Object {
|
||||||
"body": "{\\"hello\\": \\"world\\"}",
|
"body": "{\\"hello\\": \\"world\\"}",
|
||||||
"request": Object {
|
"request": Object {
|
||||||
"body": undefined,
|
"body": undefined,
|
||||||
"endpoint": "http://martianwabbit.com/user",
|
"endpoint": "http://example.com/user",
|
||||||
"headers": undefined,
|
"headers": undefined,
|
||||||
},
|
},
|
||||||
"response": Object {
|
"response": Object {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const Beau = require('../beau');
|
const Beau = require('../beau');
|
||||||
|
const { moduleVersion } = require('../shared');
|
||||||
|
|
||||||
|
jest.mock('../shared');
|
||||||
|
|
||||||
const requireg = require('requireg');
|
const requireg = require('requireg');
|
||||||
requireg.resolving = false;
|
requireg.resolving = false;
|
||||||
|
|
||||||
describe(`Beau's config Loader.`, () => {
|
describe(`Beau's config Loader.`, () => {
|
||||||
it('should create a request list', () => {
|
it('should create a request list', () => {
|
||||||
|
moduleVersion.mockReturnValue(1);
|
||||||
|
|
||||||
const doc = yaml.safeLoad(`
|
const doc = yaml.safeLoad(`
|
||||||
version: 1
|
version: 1
|
||||||
endpoint: 'http://jsonplaceholder.typicode.com'
|
endpoint: 'http://jsonplaceholder.typicode.com'
|
||||||
|
|
@ -23,7 +28,21 @@ describe(`Beau's config Loader.`, () => {
|
||||||
|
|
||||||
const beau = new Beau(doc);
|
const beau = new Beau(doc);
|
||||||
|
|
||||||
expect(beau.requests).toBeDefined();
|
|
||||||
expect(beau).toMatchSnapshot();
|
expect(beau).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display a warning if the module version and the beau file version are different', () => {
|
||||||
|
let stdout;
|
||||||
|
let spy = jest
|
||||||
|
.spyOn(console, 'warn')
|
||||||
|
.mockImplementation(val => (stdout = val));
|
||||||
|
|
||||||
|
moduleVersion.mockReturnValue(2);
|
||||||
|
|
||||||
|
const beau = new Beau({ version: 1 });
|
||||||
|
expect(stdout).toEqual('This Beau file expects v1. You are using v2.');
|
||||||
|
|
||||||
|
spy.mockReset();
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ describe('Request', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
validRequestConfig = {
|
validRequestConfig = {
|
||||||
request: 'POST /user',
|
request: 'POST /user',
|
||||||
endpoint: 'http://martianwabbit.com',
|
endpoint: 'http://example.com',
|
||||||
alias: 'update',
|
alias: 'update',
|
||||||
params: {
|
params: {
|
||||||
userId: '$profile.UserId'
|
userId: '$profile.UserId'
|
||||||
|
|
@ -27,7 +27,7 @@ describe('Request', () => {
|
||||||
|
|
||||||
invalidRequestConfig = {
|
invalidRequestConfig = {
|
||||||
request: `POST /session`,
|
request: `POST /session`,
|
||||||
endpoint: 'http://martianwabbit.com'
|
endpoint: 'http://example.com'
|
||||||
};
|
};
|
||||||
|
|
||||||
cache = new RequestCache();
|
cache = new RequestCache();
|
||||||
|
|
@ -36,7 +36,7 @@ describe('Request', () => {
|
||||||
|
|
||||||
request = new Request(validRequestConfig);
|
request = new Request(validRequestConfig);
|
||||||
requestWithoutDependencies = new Request({
|
requestWithoutDependencies = new Request({
|
||||||
endpoint: 'http://martianwabbit.com',
|
endpoint: 'http://example.com',
|
||||||
request: 'GET /user',
|
request: 'GET /user',
|
||||||
alias: 'show'
|
alias: 'show'
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
const RequestList = require('./requestList');
|
const RequestList = require('./requestList');
|
||||||
const Config = require('./config');
|
const Config = require('./config');
|
||||||
|
const { moduleVersion } = require('./shared');
|
||||||
|
|
||||||
class Beau {
|
class Beau {
|
||||||
constructor(doc, env = {}) {
|
constructor(doc, env = {}) {
|
||||||
this.config = new Config(doc, env);
|
this.config = new Config(doc, env);
|
||||||
this.requests = new RequestList(this.config);
|
this.requests = new RequestList(this.config);
|
||||||
|
|
||||||
|
if (this.config.VERSION !== moduleVersion()) {
|
||||||
|
console.warn(
|
||||||
|
`This Beau file expects v${
|
||||||
|
this.config.VERSION
|
||||||
|
}. You are using v${moduleVersion()}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
const deepMerge = require('deepmerge');
|
const deepMerge = require('deepmerge');
|
||||||
const { requestRegex, UpperCaseKeys } = require('./shared');
|
const { requestRegex, UpperCaseKeys, moduleVersion } = require('./shared');
|
||||||
const Plugins = require('./plugins');
|
const Plugins = require('./plugins');
|
||||||
const version = parseInt(require('../package.json').version, 10);
|
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
constructor(doc, env = {}) {
|
constructor(doc, env = {}) {
|
||||||
const defaultConfigValues = {
|
const defaultConfigValues = {
|
||||||
VERSION: version,
|
VERSION: moduleVersion(),
|
||||||
ENDPOINT: '',
|
ENDPOINT: '',
|
||||||
PLUGINS: [],
|
PLUGINS: [],
|
||||||
DEFAULTS: {},
|
DEFAULTS: {},
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,8 @@ const replaceInObject = function(obj, fn) {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const moduleVersion = () => parseInt(require('../package.json').version, 10);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
requestRegex,
|
requestRegex,
|
||||||
replacementRegex,
|
replacementRegex,
|
||||||
|
|
@ -74,5 +76,6 @@ module.exports = {
|
||||||
UpperCaseKeys,
|
UpperCaseKeys,
|
||||||
removeOptionalKeys,
|
removeOptionalKeys,
|
||||||
toKebabCase,
|
toKebabCase,
|
||||||
replaceInObject
|
replaceInObject,
|
||||||
|
moduleVersion
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue