11import test from 'ava' ;
22import { stub } from 'sinon' ;
3+ import { WritableStreamBuffer } from 'stream-buffers' ;
34import { verifyConditions } from '..' ;
45
5- // Disable logs during tests
6- stub ( process . stdout , 'write' ) ;
7- stub ( process . stderr , 'write' ) ;
8-
96test . beforeEach ( t => {
7+ t . context . stdout = new WritableStreamBuffer ( ) ;
8+ t . context . stderr = new WritableStreamBuffer ( ) ;
109 // Mock logger
1110 t . context . log = stub ( ) ;
1211 t . context . error = stub ( ) ;
@@ -15,14 +14,14 @@ test.beforeEach(t => {
1514
1615test ( 'Verify plugin config is an Object with a "cmd" property' , async t => {
1716 const pluginConfig = { cmd : './test/fixtures/echo-args.sh' } ;
18- const context = { logger : t . context . logger } ;
17+ const context = { stdout : t . context . stdout , stderr : t . context . stderr , logger : t . context . logger } ;
1918
2019 await t . notThrows ( verifyConditions ( pluginConfig , context ) ) ;
2120} ) ;
2221
2322test ( 'Throw "SemanticReleaseError" if "cmd" options is missing' , async t => {
2423 const pluginConfig = { } ;
25- const context = { logger : t . context . logger } ;
24+ const context = { stdout : t . context . stdout , stderr : t . context . stderr , logger : t . context . logger } ;
2625
2726 const error = await t . throws ( verifyConditions ( pluginConfig , context ) ) ;
2827
@@ -32,7 +31,7 @@ test('Throw "SemanticReleaseError" if "cmd" options is missing', async t => {
3231
3332test ( 'Throw "SemanticReleaseError" if "cmd" options is empty' , async t => {
3433 const pluginConfig = { cmd : ' ' } ;
35- const context = { logger : t . context . logger , options : { } } ;
34+ const context = { stdout : t . context . stdout , stderr : t . context . stderr , logger : t . context . logger , options : { } } ;
3635
3736 const error = await t . throws ( verifyConditions ( pluginConfig , context ) ) ;
3837
@@ -43,6 +42,8 @@ test('Throw "SemanticReleaseError" if "cmd" options is empty', async t => {
4342test ( 'Throw "SemanticReleaseError" if another exec plugin "cmd" options is missing' , async t => {
4443 const pluginConfig = { cmd : './test/fixtures/echo-args.sh' } ;
4544 const context = {
45+ stdout : t . context . stdout ,
46+ stderr : t . context . stderr ,
4647 logger : t . context . logger ,
4748 options : { publish : [ '@semantic-release/npm' , { path : '@semantic-release/exec' } ] } ,
4849 } ;
@@ -56,6 +57,8 @@ test('Throw "SemanticReleaseError" if another exec plugin "cmd" options is missi
5657test ( 'Throw "SemanticReleaseError" if another exec plugin "cmd" options is empty' , async t => {
5758 const pluginConfig = { cmd : './test/fixtures/echo-args.sh' } ;
5859 const context = {
60+ stdout : t . context . stdout ,
61+ stderr : t . context . stderr ,
5962 logger : t . context . logger ,
6063 options : {
6164 branch : 'master' ,
@@ -71,14 +74,14 @@ test('Throw "SemanticReleaseError" if another exec plugin "cmd" options is empty
7174
7275test ( 'Return if the verifyConditions script returns 0' , async t => {
7376 const pluginConfig = { cmd : 'exit 0' } ;
74- const context = { logger : t . context . logger , options : { } } ;
77+ const context = { stdout : t . context . stdout , stderr : t . context . stderr , logger : t . context . logger , options : { } } ;
7578
7679 await t . notThrows ( verifyConditions ( pluginConfig , context ) ) ;
7780} ) ;
7881
7982test ( 'Throw "SemanticReleaseError" if the verifyConditions script does not returns 0' , async t => {
8083 const pluginConfig = { cmd : 'exit 1' } ;
81- const context = { logger : t . context . logger , options : { } } ;
84+ const context = { stdout : t . context . stdout , stderr : t . context . stderr , logger : t . context . logger , options : { } } ;
8285
8386 const error = await t . throws ( verifyConditions ( pluginConfig , context ) ) ;
8487
0 commit comments