Skip to content

Commit 56a31ce

Browse files
authored
Merge pull request #61 from cksource/t/60
Fix: The `status` command will now sort packages alphabetically. Closes #60.
2 parents 16d5650 + dce918a commit 56a31ce

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

lib/commands/status.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,18 @@ module.exports = {
7575
}
7676
} );
7777

78-
for ( const singleResponse of commandResponses.values() ) {
78+
const packagesResponses = Array.from( commandResponses.values() )
79+
.sort( ( a, b ) => {
80+
if ( a.packageName < b.packageName ) {
81+
return -1;
82+
} else if ( a.packageName > b.packageName ) {
83+
return 1;
84+
}
85+
86+
return 0;
87+
} );
88+
89+
for ( const singleResponse of packagesResponses ) {
7990
table.push( createSingleRow( singleResponse ) );
8091
}
8192

tests/commands/status.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,12 @@ describe( 'commands/status', () => {
272272
compact: true
273273
}
274274
} );
275+
275276
expect( stubs.table.push.firstCall.args[ 0 ] ).to.deep.equal(
276-
[ 'foo', 'master ↓2', 'abcd123', 'M1' ]
277+
[ 'bar', 't/1 ↑3', 'ef45678', '+1 ?1' ]
277278
);
278279
expect( stubs.table.push.secondCall.args[ 0 ] ).to.deep.equal(
279-
[ 'bar', 't/1 ↑3', 'ef45678', '+1 ?1' ]
280+
[ 'foo', 'master ↓2', 'abcd123', 'M1' ]
280281
);
281282

282283
expect( stubs.table.toString.calledOnce ).to.equal( true );
@@ -378,5 +379,47 @@ describe( 'commands/status', () => {
378379

379380
logStub.restore();
380381
} );
382+
383+
it( 'sorts packages by alphabetically', () => {
384+
const logStub = sandbox.stub( console, 'log' );
385+
386+
const processedPackages = new Set();
387+
const commandResponses = new Set();
388+
389+
processedPackages.add( '@ckeditor/ckeditor5-foo' );
390+
processedPackages.add( '@ckeditor/ckeditor5-bar' );
391+
processedPackages.add( '@ckeditor/ckeditor5-bom' );
392+
processedPackages.add( '@ckeditor/ckeditor5-aaa' );
393+
394+
commandResponses.add( getCommandResponse( 'foo', '1111111' ) );
395+
commandResponses.add( getCommandResponse( 'bar', '2222222' ) );
396+
commandResponses.add( getCommandResponse( 'bom', '3333333' ) );
397+
commandResponses.add( getCommandResponse( 'aaa', '4444444' ) );
398+
399+
statusCommand.afterExecute( processedPackages, commandResponses );
400+
401+
expect( stubs.table.push.getCall( 0 ).args[ 0 ][ 0 ], 1 ).to.equal( 'aaa' );
402+
expect( stubs.table.push.getCall( 1 ).args[ 0 ][ 0 ], 2 ).to.equal( 'bar' );
403+
expect( stubs.table.push.getCall( 2 ).args[ 0 ][ 0 ], 3 ).to.equal( 'bom' );
404+
expect( stubs.table.push.getCall( 3 ).args[ 0 ][ 0 ], 4 ).to.equal( 'foo' );
405+
406+
logStub.restore();
407+
408+
function getCommandResponse( packageName, commit ) {
409+
return {
410+
packageName,
411+
status: {
412+
branch: 'master',
413+
ahead: 0,
414+
behind: 0,
415+
staged: [],
416+
modified: [],
417+
untracked: [],
418+
},
419+
mgitBranch: 'master',
420+
commit
421+
};
422+
}
423+
} );
381424
} );
382425
} );

0 commit comments

Comments
 (0)