Skip to content

Commit cce3176

Browse files
author
Ognjen Jevremovic
committed
test(tests/commit.js): throw error if staging is empty
Extend upon the existing commit unit tests. Assert the error is thrown when running commitizen commit command with no files add to staging. "re commitizen#585"
1 parent 7e5e6da commit cce3176

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/tests/commit.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,73 @@ ${(os.platform === 'win32') ? '' : ' '}
311311
done();
312312
});
313313
});
314+
315+
it('should throw error if staging area is empty', function (done) {
316+
317+
this.timeout(config.maxTimeout); // this could take a while
318+
319+
// SETUP
320+
321+
let dummyCommitMessage = `one does not simply ignore the tests`;
322+
323+
// Describe a repo and some files to add and commit
324+
let repoConfig = {
325+
path: config.paths.endUserRepo,
326+
files: {
327+
dummyfile: {
328+
contents: `duck-duck-gray-duck`,
329+
filename: `mydummiestfile.txt`,
330+
},
331+
gitignore: {
332+
contents: `node_modules/`,
333+
filename: `.gitignore`,
334+
}
335+
}
336+
};
337+
338+
// Describe an adapter
339+
let adapterConfig = {
340+
path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'),
341+
npmName: 'cz-jira-smart-commit'
342+
};
343+
344+
// Quick setup the repos, adapter, and grab a simple prompter
345+
let prompter = quickPrompterSetup(repoConfig, adapterConfig, dummyCommitMessage);
346+
// TEST
347+
348+
// Make an initial commit
349+
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function (error) {
350+
// Should pass, as the files are added to the staging area
351+
expect(error).to.be.null;
352+
353+
log(repoConfig.path, function (logOutput) {
354+
expect(logOutput).to.have.string(dummyCommitMessage);
355+
});
356+
whatChanged(repoConfig.path, function (whatChangedOutput) {
357+
expect(whatChangedOutput).to.have.string('A\t' + repoConfig.files.dummyfile.filename);
358+
359+
// Make changes and don't add them to the staging area
360+
writeFilesToPath({
361+
dummymodified: {
362+
contents: repoConfig.files.dummyfile.contents + '-modified',
363+
filename: repoConfig.files.dummyfile.filename,
364+
add: false,
365+
}
366+
}, repoConfig.path);
367+
// Define a dummy prompter
368+
let prompter = function (cz, commit) {
369+
commit(`${dummyCommitMessage} #2`, {});
370+
};
371+
372+
commitizenCommit(inquirer, repoConfig.path, prompter, { disableAppendPaths: true, quiet: true, emitData: true }, function (error) {
373+
// Should fail, as staging are is empty
374+
expect(error).to.be.instanceOf(Error);
375+
done();
376+
});
377+
});
378+
});
379+
380+
});
314381
});
315382

316383
afterEach(function () {

0 commit comments

Comments
 (0)