Skip to content

Commit f4a3cbe

Browse files
committed
test: refactor failing test
1 parent bd2ecb2 commit f4a3cbe

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

test/processors/writePack.test.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ const { Action, Step } = require('../../src/proxy/actions');
66
chai.should();
77
const expect = chai.expect;
88

9-
describe('writePack', () => {
9+
describe.only('writePack', () => {
1010
let exec;
11+
let readdirSyncStub;
1112
let spawnSyncStub;
1213
let stepLogSpy;
1314
let stepSetContentSpy;
1415
let stepSetErrorSpy;
1516

1617
beforeEach(() => {
17-
spawnSyncStub = sinon.stub().returns({
18-
stdout: 'git receive-pack output',
19-
stderr: '',
20-
status: 0
21-
});
18+
spawnSyncStub = sinon.stub();
19+
readdirSyncStub = sinon.stub();
20+
21+
readdirSyncStub.onFirstCall().returns(['old1.idx']);
22+
readdirSyncStub.onSecondCall().returns(['old1.idx', 'new1.idx']);
2223

2324
stepLogSpy = sinon.spy(Step.prototype, 'log');
2425
stepSetContentSpy = sinon.spy(Step.prototype, 'setContent');
2526
stepSetErrorSpy = sinon.spy(Step.prototype, 'setError');
2627

2728
const writePack = proxyquire('../../src/proxy/processors/push-action/writePack', {
28-
'child_process': { spawnSync: spawnSyncStub }
29+
'child_process': { spawnSync: spawnSyncStub },
30+
'fs': { readdirSync: readdirSyncStub },
2931
});
3032

3133
exec = writePack.exec;
@@ -50,28 +52,34 @@ describe('writePack', () => {
5052
1234567890,
5153
'test/repo'
5254
);
53-
action.proxyGitPath = '/path/to/repo';
55+
action.proxyGitPath = '/path/to';
56+
action.repoName = 'repo';
5457
});
5558

5659
it('should execute git receive-pack with correct parameters', async () => {
60+
const dummySpawnOutput = { stdout: 'git receive-pack output', stderr: '', status: 0 };
61+
spawnSyncStub.returns(dummySpawnOutput);
62+
5763
const result = await exec(req, action);
5864

59-
expect(spawnSyncStub.calledOnce).to.be.true;
65+
expect(spawnSyncStub.callCount).to.equal(2);
6066
expect(spawnSyncStub.firstCall.args[0]).to.equal('git');
61-
expect(spawnSyncStub.firstCall.args[1]).to.deep.equal(['receive-pack', 'repo']);
62-
expect(spawnSyncStub.firstCall.args[2]).to.deep.equal({
63-
cwd: '/path/to/repo',
64-
input: 'pack data',
65-
encoding: 'utf-8'
67+
expect(spawnSyncStub.firstCall.args[1]).to.deep.equal(['config', 'receive.unpackLimit', '0']);
68+
expect(spawnSyncStub.firstCall.args[2]).to.include({ cwd: '/path/to/repo' });
69+
70+
expect(spawnSyncStub.secondCall.args[0]).to.equal('git');
71+
expect(spawnSyncStub.secondCall.args[1]).to.deep.equal(['receive-pack', 'repo']);
72+
expect(spawnSyncStub.secondCall.args[2]).to.include({
73+
cwd: '/path/to',
74+
input: 'pack data'
6675
});
6776

68-
expect(stepLogSpy.calledWith('executing git receive-pack repo')).to.be.true;
69-
expect(stepLogSpy.calledWith('git receive-pack output')).to.be.true;
70-
71-
expect(stepSetContentSpy.calledWith('git receive-pack output')).to.be.true;
77+
expect(stepLogSpy.calledWith('new idx files: new1.idx')).to.be.true;
78+
expect(stepSetContentSpy.calledWith(dummySpawnOutput)).to.be.true;
7279

7380
expect(result.steps).to.have.lengthOf(1);
7481
expect(result.steps[0].error).to.be.false;
82+
expect(result.newIdxFiles).to.deep.equal(['new1.idx']);
7583
});
7684

7785
it('should handle errors from git receive-pack', async () => {

0 commit comments

Comments
 (0)