UNPKG

3.69 kBJavaScriptView Raw
1'use strict';
2
3var expect = require('chai').expect;
4var helpers = require('./helpers');
5var shell = require('shelljs');
6var fs = require('fs');
7var chg = require('../');
8
9describe('chg', function(){
10 var tmpDirName;
11
12 before(function(){
13 tmpDirName = 'test-tmp-'+(new Date().getTime());
14 shell.mkdir('-p', tmpDirName);
15 shell.cd(tmpDirName);
16 });
17
18 after(function() {
19 shell.cd('..');
20 shell.rm('-rf', tmpDirName);
21 });
22
23
24 describe('#init()', function(){
25 var chgResult;
26
27 before(function() { chgResult = chg.init(); });
28
29 it('creates a new, empty CHANGELOG.md', function(){
30 expect(readChangelog()).to.equal(loadFixture('init.md'));
31 });
32
33 it('returns the new changelog filename', function() {
34 expect(chgResult).to.equal('CHANGELOG.md');
35 });
36 });
37
38 describe('#add()', function() {
39 var addResult;
40
41 before(function() { addResult = chg.add('Test add'); });
42
43 it('adds a new line to the changelog', function() {
44 expect(readChangelog()).to.equal(loadFixture('add.md'));
45 });
46
47 it('returns the newly added line', function() {
48 expect(addResult).to.equal('Test add');
49 });
50 });
51
52 describe('#release()', function() {
53 var releaseResult, releaseTitle, releaseDate;
54
55 before(function() {
56 releaseTitle = '0.0.1';
57 releaseDate = '12/12/12';
58 releaseResult = chg.release(releaseTitle, { date: releaseDate });
59 });
60
61 it('moves things under head to a new release block', function() {
62 expect(readChangelog()).to.equal(loadFixture('release.md'));
63 })
64
65 describe('return information', function() {
66 it('includes the title', function() {
67 expect(releaseResult.title).to.contain(releaseTitle);
68 });
69
70 it('includes the date in the title', function() {
71 expect(releaseResult.title).to.contain(releaseDate);
72 });
73
74 it('includes the changes', function() {
75 expect(releaseResult.changes).to.contain('Test add');
76 });
77
78 it('includes the entire changelog contents', function() {
79 expect(releaseResult.changelog).not.to.be.null;
80 });
81 });
82
83 describe('subsequent releases', function() {
84 it('adds new lines under HEAD', function() {
85 chg.add('Test add again');
86 chg.add('Test add with [link](http://heff.me)');
87 expect(readChangelog()).to.equal(loadFixture('add2.md'));
88 });
89
90 it('creates a release with the correct title above the previous release', function() {
91 chg.release('0.0.2', { date: '12/13/12' });
92 expect(readChangelog()).to.equal(loadFixture('release2.md'));
93 });
94 });
95 });
96
97 describe('#find()', function() {
98 var findTitle, findResult;
99
100 before(function() {
101 findTitle = '0.0.2';
102 findResult = chg.find(findTitle);
103 });
104
105 it('finds the section under the specified title', function() {
106 expect(findResult.title).to.contain(findTitle);
107 });
108
109 it('returns an array of the changes', function() {
110 expect(findResult.changes).to.be.instanceOf(Array);
111 expect(findResult.changes).to.include('* Test add again');
112 });
113
114 it('returns the contents under that title as raw text', function() {
115 expect(findResult.changesRaw).to.contain('Test add with');
116 expect(findResult.changesRaw).to.contain('Test add again');
117 });
118
119 it
120 });
121
122 describe('#delete()', function() {
123 before(function() {
124 chg.delete();
125 });
126
127 it('deletes the current CHANGELOG.md file', function() {
128 expect(fs.existsSync('./CHANGELOG.md')).to.be.false;
129 });
130 });
131});