UNPKG

1.85 kBJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3
4var helper = require('./helper');
5
6var assert = helper.assert;
7
8describe('different-repo', function() {
9 var fixture, repo;
10
11 before(function(done) {
12 this.timeout(3000);
13 helper.buildFixture('different-repo', function(error, dir) {
14 fixture = dir;
15 repo = path.join(fixture, '.grunt/grunt-gh-pages/gh-pages/src');
16 done(error);
17 });
18 });
19
20 after(function(done) {
21 helper.afterFixture(fixture, done);
22 });
23
24 it('creates .grunt/grunt-gh-pages/gh-pages/src directory', function(done) {
25 fs.stat(repo, function(error, stats) {
26 assert.isTrue(!error, 'no error');
27 assert.isTrue(stats.isDirectory(), 'directory');
28 done(error);
29 });
30 });
31
32 it('creates a gh-pages branch', function(done) {
33 var branch;
34 helper.git(['rev-parse', '--abbrev-ref', 'HEAD'], repo)
35 .progress(function(chunk) {
36 branch = String(chunk);
37 })
38 .then(function() {
39 assert.strictEqual(branch, 'gh-pages\n', 'branch created');
40 done();
41 })
42 .fail(done);
43 });
44
45 it('copies source files', function(done) {
46 fs.exists(path.join(repo, 'hello.txt'), function(exists) {
47 if (!exists) {
48 done(new Error('Failed to find "hello.txt" in repo: ') + repo);
49 } else {
50 done();
51 }
52 });
53 });
54
55 it('copies correct source files', function(done) {
56 fs.readFile(path.join(repo, 'hello.txt'), function(err, data) {
57 if (err) {
58 done(err);
59 } else {
60 assert.strictEqual(String(data), 'hello\n');
61 done();
62 }
63 });
64 });
65
66 it('pushes the gh-pages branch to remote', function(done) {
67 helper.git(['ls-remote', '--exit-code', '.', 'origin/gh-pages'], repo)
68 .then(function() {
69 done();
70 })
71 .fail(done);
72 });
73
74});