1 | var fs = require('fs');
|
2 | var path = require('path');
|
3 |
|
4 | var helper = require('./helper');
|
5 |
|
6 | var assert = helper.assert;
|
7 |
|
8 | describe('add', function() {
|
9 | var fixture, repo1, repo2;
|
10 |
|
11 | before(function(done) {
|
12 | this.timeout(3000);
|
13 | helper.buildFixture('add', function(error, dir) {
|
14 | fixture = dir;
|
15 | repo1 = path.join(fixture, '.grunt/grunt-gh-pages/gh-pages/first');
|
16 | repo2 = path.join(fixture, '.grunt/grunt-gh-pages/gh-pages/second');
|
17 | done(error);
|
18 | });
|
19 | });
|
20 |
|
21 | after(function(done) {
|
22 | helper.afterFixture(fixture, done);
|
23 | });
|
24 |
|
25 | |
26 |
|
27 |
|
28 | it('creates .grunt/grunt-gh-pages/gh-pages/first directory', function(done) {
|
29 | fs.stat(repo1, function(error, stats) {
|
30 | assert.isTrue(!error, 'no error');
|
31 | assert.isTrue(stats.isDirectory(), 'directory');
|
32 | done(error);
|
33 | });
|
34 | });
|
35 |
|
36 | it('creates a gh-pages branch', function(done) {
|
37 | var branch;
|
38 | helper.git(['rev-parse', '--abbrev-ref', 'HEAD'], repo1)
|
39 | .progress(function(chunk) {
|
40 | branch = String(chunk);
|
41 | })
|
42 | .then(function() {
|
43 | assert.strictEqual(branch, 'gh-pages\n', 'branch created');
|
44 | done();
|
45 | })
|
46 | .fail(done);
|
47 | });
|
48 |
|
49 | it('copies source files relative to the base', function() {
|
50 | assert.strictEqual(fs.readFileSync(path.join(repo1, 'first.txt'), 'utf8'),
|
51 | 'first');
|
52 | assert.strictEqual(fs.readFileSync(path.join(repo1, 'sub', 'sub.txt'),
|
53 | 'utf8'), 'first');
|
54 | });
|
55 |
|
56 | it('pushes the gh-pages branch to remote', function(done) {
|
57 | helper.git(['ls-remote', '--exit-code', '.', 'origin/gh-pages'], repo1)
|
58 | .then(function() {
|
59 | done();
|
60 | })
|
61 | .fail(done);
|
62 | });
|
63 |
|
64 | |
65 |
|
66 |
|
67 |
|
68 | it('creates .grunt/grunt-gh-pages/gh-pages/second directory', function(done) {
|
69 | fs.stat(repo2, function(error, stats) {
|
70 | assert.isTrue(!error, 'no error');
|
71 | assert.isTrue(stats.isDirectory(), 'directory');
|
72 | done(error);
|
73 | });
|
74 | });
|
75 |
|
76 | it('creates a gh-pages branch', function(done) {
|
77 | var branch;
|
78 | helper.git(['rev-parse', '--abbrev-ref', 'HEAD'], repo2)
|
79 | .progress(function(chunk) {
|
80 | branch = String(chunk);
|
81 | })
|
82 | .then(function() {
|
83 | assert.strictEqual(branch, 'gh-pages\n', 'branch created');
|
84 | done();
|
85 | })
|
86 | .fail(done);
|
87 | });
|
88 |
|
89 | it('overwrites, but does not remove existing', function() {
|
90 | assert.strictEqual(fs.readFileSync(path.join(repo2, 'first.txt'), 'utf8'),
|
91 | 'first');
|
92 | assert.strictEqual(fs.readFileSync(path.join(repo2, 'second.txt'), 'utf8'),
|
93 | 'second');
|
94 | assert.strictEqual(fs.readFileSync(path.join(repo2, 'sub', 'sub.txt'),
|
95 | 'utf8'), 'second');
|
96 | });
|
97 |
|
98 | it('pushes the gh-pages branch to remote', function(done) {
|
99 | helper.git(['ls-remote', '--exit-code', '.', 'origin/gh-pages'], repo2)
|
100 | .then(function() {
|
101 | done();
|
102 | })
|
103 | .fail(done);
|
104 | });
|
105 |
|
106 | });
|