WIP esm - adapt sinon
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import test from 'ava';
|
||||
import {noop} from 'lodash';
|
||||
import {stub} from 'sinon';
|
||||
import sinon from 'sinon';
|
||||
import normalize from '../../lib/plugins/normalize.js';
|
||||
|
||||
const cwd = process.cwd();
|
||||
|
||||
test.beforeEach((t) => {
|
||||
// Stub the logger functions
|
||||
t.context.log = stub();
|
||||
t.context.error = stub();
|
||||
t.context.success = stub();
|
||||
t.context.stderr = {write: stub()};
|
||||
t.context.log = sinon.stub);
|
||||
t.context.error = sinon.stub);
|
||||
t.context.success = sinon.stub);
|
||||
t.context.stderr = {write: sinon.stub)};
|
||||
t.context.logger = {
|
||||
log: t.context.log,
|
||||
error: t.context.error,
|
||||
@@ -99,7 +99,7 @@ test('Normalize and load plugin that retuns multiple functions', (t) => {
|
||||
});
|
||||
|
||||
test('Wrap "analyzeCommits" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const analyzeCommits = stub().resolves(2);
|
||||
const analyzeCommits = sinon.stub).resolves(2);
|
||||
const plugin = normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'analyzeCommits',
|
||||
@@ -117,7 +117,7 @@ test('Wrap "analyzeCommits" plugin in a function that validate the output of the
|
||||
});
|
||||
|
||||
test('Wrap "generateNotes" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const generateNotes = stub().resolves(2);
|
||||
const generateNotes = sinon.stub).resolves(2);
|
||||
const plugin = normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'generateNotes',
|
||||
@@ -135,7 +135,7 @@ test('Wrap "generateNotes" plugin in a function that validate the output of the
|
||||
});
|
||||
|
||||
test('Wrap "publish" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const publish = stub().resolves(2);
|
||||
const publish = sinon.stub).resolves(2);
|
||||
const plugin = normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'publish',
|
||||
@@ -153,7 +153,7 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
||||
});
|
||||
|
||||
test('Wrap "addChannel" plugin in a function that validate the output of the plugin', async (t) => {
|
||||
const addChannel = stub().resolves(2);
|
||||
const addChannel = sinon.stub).resolves(2);
|
||||
const plugin = normalize(
|
||||
{cwd, options: {}, stderr: t.context.stderr, logger: t.context.logger},
|
||||
'addChannel',
|
||||
@@ -171,7 +171,7 @@ test('Wrap "addChannel" plugin in a function that validate the output of the plu
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (with object definition) and input', async (t) => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginFunction = sinon.stub).resolves();
|
||||
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
@@ -186,7 +186,7 @@ test('Plugin is called with "pluginConfig" (with object definition) and input',
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (with array definition) and input', async (t) => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginFunction = sinon.stub).resolves();
|
||||
const pluginConf = [pluginFunction, {conf: 'confValue'}];
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
@@ -201,7 +201,7 @@ test('Plugin is called with "pluginConfig" (with array definition) and input', a
|
||||
});
|
||||
|
||||
test('Prevent plugins to modify "pluginConfig"', async (t) => {
|
||||
const pluginFunction = stub().callsFake((pluginConfig) => {
|
||||
const pluginFunction = sinon.stub).callsFake((pluginConfig) => {
|
||||
pluginConfig.conf.subConf = 'otherConf';
|
||||
});
|
||||
const pluginConf = {path: pluginFunction, conf: {subConf: 'originalConf'}};
|
||||
@@ -214,7 +214,7 @@ test('Prevent plugins to modify "pluginConfig"', async (t) => {
|
||||
});
|
||||
|
||||
test('Prevent plugins to modify its input', async (t) => {
|
||||
const pluginFunction = stub().callsFake((pluginConfig, options) => {
|
||||
const pluginFunction = sinon.stub).callsFake((pluginConfig, options) => {
|
||||
options.param.subParam = 'otherParam';
|
||||
});
|
||||
const input = {param: {subParam: 'originalSubParam'}, options: {}};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import test from 'ava';
|
||||
import {stub} from 'sinon';
|
||||
import sinon from 'sinon';
|
||||
import AggregateError from 'aggregate-error';
|
||||
import pipeline from '../../lib/plugins/pipeline.js';
|
||||
|
||||
test('Execute each function in series passing the same input', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().resolves(2);
|
||||
const step3 = stub().resolves(3);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).resolves(2);
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
|
||||
const result = await pipeline([step1, step2, step3])(0);
|
||||
t.deepEqual(result, [1, 2, 3]);
|
||||
@@ -19,10 +19,10 @@ test('Execute each function in series passing the same input', async (t) => {
|
||||
});
|
||||
|
||||
test('Execute each function in series passing a transformed input from "getNextInput"', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().resolves(2);
|
||||
const step3 = stub().resolves(3);
|
||||
const step4 = stub().resolves(4);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).resolves(2);
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
const step4 = sinon.stub).resolves(4);
|
||||
const getNextInput = (lastResult, result) => lastResult + result;
|
||||
|
||||
const result = await pipeline([step1, step2, step3, step4], {settleAll: false, getNextInput})(0);
|
||||
@@ -38,11 +38,11 @@ test('Execute each function in series passing a transformed input from "getNextI
|
||||
});
|
||||
|
||||
test('Execute each function in series passing the "lastResult" and "result" to "getNextInput"', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().resolves(2);
|
||||
const step3 = stub().resolves(3);
|
||||
const step4 = stub().resolves(4);
|
||||
const getNextInput = stub().returnsArg(0);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).resolves(2);
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
const step4 = sinon.stub).resolves(4);
|
||||
const getNextInput = sinon.stub).returnsArg(0);
|
||||
|
||||
const result = await pipeline([step1, step2, step3, step4], {settleAll: false, getNextInput})(5);
|
||||
|
||||
@@ -56,12 +56,12 @@ test('Execute each function in series passing the "lastResult" and "result" to "
|
||||
});
|
||||
|
||||
test('Execute each function in series calling "transform" to modify the results', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().resolves(2);
|
||||
const step3 = stub().resolves(3);
|
||||
const step4 = stub().resolves(4);
|
||||
const getNextInput = stub().returnsArg(0);
|
||||
const transform = stub().callsFake((result) => result + 1);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).resolves(2);
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
const step4 = sinon.stub).resolves(4);
|
||||
const getNextInput = sinon.stub).returnsArg(0);
|
||||
const transform = sinon.stub).callsFake((result) => result + 1);
|
||||
|
||||
const result = await pipeline([step1, step2, step3, step4], {getNextInput, transform})(5);
|
||||
|
||||
@@ -75,12 +75,12 @@ test('Execute each function in series calling "transform" to modify the results'
|
||||
});
|
||||
|
||||
test('Execute each function in series calling "transform" to modify the results with "settleAll"', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().resolves(2);
|
||||
const step3 = stub().resolves(3);
|
||||
const step4 = stub().resolves(4);
|
||||
const getNextInput = stub().returnsArg(0);
|
||||
const transform = stub().callsFake((result) => result + 1);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).resolves(2);
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
const step4 = sinon.stub).resolves(4);
|
||||
const getNextInput = sinon.stub).returnsArg(0);
|
||||
const transform = sinon.stub).callsFake((result) => result + 1);
|
||||
|
||||
const result = await pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput, transform})(5);
|
||||
|
||||
@@ -94,9 +94,9 @@ test('Execute each function in series calling "transform" to modify the results
|
||||
});
|
||||
|
||||
test('Stop execution and throw error if a step rejects', async (t) => {
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().rejects(new Error('test error'));
|
||||
const step3 = stub().resolves(3);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).rejects(new Error('test error'));
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
|
||||
const error = await t.throwsAsync(pipeline([step1, step2, step3])(0), {
|
||||
instanceOf: Error,
|
||||
@@ -112,9 +112,9 @@ test('Throw all errors from the first step throwing an AggregateError', async (t
|
||||
const error1 = new Error('test error 1');
|
||||
const error2 = new Error('test error 2');
|
||||
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().rejects(new AggregateError([error1, error2]));
|
||||
const step3 = stub().resolves(3);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).rejects(new AggregateError([error1, error2]));
|
||||
const step3 = sinon.stub).resolves(3);
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3])(0));
|
||||
|
||||
@@ -127,9 +127,9 @@ test('Throw all errors from the first step throwing an AggregateError', async (t
|
||||
test('Execute all even if a Promise rejects', async (t) => {
|
||||
const error1 = new Error('test error 1');
|
||||
const error2 = new Error('test error 2');
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().rejects(error1);
|
||||
const step3 = stub().rejects(error2);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).rejects(error1);
|
||||
const step3 = sinon.stub).rejects(error2);
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3], {settleAll: true})(0));
|
||||
|
||||
@@ -144,8 +144,8 @@ test('Throw all errors from all steps throwing an AggregateError', async (t) =>
|
||||
const error2 = new Error('test error 2');
|
||||
const error3 = new Error('test error 3');
|
||||
const error4 = new Error('test error 4');
|
||||
const step1 = stub().rejects(new AggregateError([error1, error2]));
|
||||
const step2 = stub().rejects(new AggregateError([error3, error4]));
|
||||
const step1 = sinon.stub).rejects(new AggregateError([error1, error2]));
|
||||
const step2 = sinon.stub).rejects(new AggregateError([error3, error4]));
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2], {settleAll: true})(0));
|
||||
|
||||
@@ -157,10 +157,10 @@ test('Throw all errors from all steps throwing an AggregateError', async (t) =>
|
||||
test('Execute each function in series passing a transformed input even if a step rejects', async (t) => {
|
||||
const error2 = new Error('test error 2');
|
||||
const error3 = new Error('test error 3');
|
||||
const step1 = stub().resolves(1);
|
||||
const step2 = stub().rejects(error2);
|
||||
const step3 = stub().rejects(error3);
|
||||
const step4 = stub().resolves(4);
|
||||
const step1 = sinon.stub).resolves(1);
|
||||
const step2 = sinon.stub).rejects(error2);
|
||||
const step3 = sinon.stub).rejects(error3);
|
||||
const step4 = sinon.stub).resolves(4);
|
||||
const getNextInput = (previousResult, result) => previousResult + result;
|
||||
|
||||
const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from 'path';
|
||||
import test from 'ava';
|
||||
import {copy, outputFile} from 'fs-extra';
|
||||
import {stub} from 'sinon';
|
||||
import sinon from 'sinon';
|
||||
import tempy from 'tempy';
|
||||
import getPlugins from '../../lib/plugins';
|
||||
|
||||
@@ -10,8 +10,8 @@ const cwd = process.cwd();
|
||||
|
||||
test.beforeEach((t) => {
|
||||
// Stub the logger functions
|
||||
t.context.log = stub();
|
||||
t.context.success = stub();
|
||||
t.context.log = sinon.stub);
|
||||
t.context.success = sinon.stub);
|
||||
t.context.logger = {log: t.context.log, success: t.context.success, scope: () => t.context.logger};
|
||||
});
|
||||
|
||||
@@ -56,8 +56,8 @@ test('Export plugins based on steps config', (t) => {
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (array)', async (t) => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugin2 = {verifyConditions: stub(), verifyRelease: stub()};
|
||||
const plugin1 = {verifyConditions: sinon.stub), publish: sinon.stub)};
|
||||
const plugin2 = {verifyConditions: sinon.stub), verifyRelease: sinon.stub)};
|
||||
const plugins = getPlugins(
|
||||
{cwd, logger: t.context.logger, options: {plugins: [plugin1, [plugin2, {}]], verifyRelease: () => {}}},
|
||||
{}
|
||||
@@ -85,7 +85,7 @@ test('Export plugins based on "plugins" config (array)', async (t) => {
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (single definition)', async (t) => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugin1 = {verifyConditions: sinon.stub), publish: sinon.stub)};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: plugin1}}, {});
|
||||
|
||||
await plugins.verifyConditions({options: {}});
|
||||
@@ -106,8 +106,8 @@ test('Export plugins based on "plugins" config (single definition)', async (t) =
|
||||
});
|
||||
|
||||
test('Merge global options, "plugins" options and step options', async (t) => {
|
||||
const plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}];
|
||||
const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}];
|
||||
const plugin1 = [{verifyConditions: sinon.stub), publish: sinon.stub)}, {pluginOpt1: 'plugin1'}];
|
||||
const plugin2 = [{verifyConditions: sinon.stub)}, {pluginOpt2: 'plugin2'}];
|
||||
const plugin3 = [stub(), {pluginOpt3: 'plugin3'}];
|
||||
const plugins = getPlugins(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user