/
staging.js
131 lines (102 loc) · 3.78 KB
/
staging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { expect } from 'chai';
// Bootstrap our tester
import { bootstrap } from '../tester';
// Get our source files
import { init as gitInit, addPath as gitAdd } from '../../src/git';
import { staging } from '../../src/commitizen';
// Destructure some things for cleaner tests
let { config, repo, clean, files } = bootstrap();
let { writeFilesToPath } = files;
before(function () {
// Creates the temp path
clean.before(config.paths.tmp);
});
beforeEach(function () {
this.timeout(config.maxTimeout); // this could take a while
repo.createEndUser(config.paths.endUserRepo);
});
describe('staging', function () {
it('should determine if a repo is clean', function (done) {
this.timeout(config.maxTimeout); // this could take a while
// SETUP
// Describe a repo and some files to add and commit
let repoConfig = {
path: config.paths.endUserRepo,
files: {
dummyfile: {
contents: `duck-duck-goose`,
filename: `mydummyfile.txt`,
},
gitignore: {
contents: `node_modules/`,
filename: `.gitignore`
}
}
};
gitInit(repoConfig.path);
staging.isClean('./@this-actually-does-not-exist', function (stagingError) {
expect(stagingError).to.be.an.instanceof(Error);
staging.isClean(repoConfig.path, function (stagingIsCleanError, stagingIsClean) {
expect(stagingIsCleanError).to.be.null;
expect(stagingIsClean).to.be.true;
writeFilesToPath(repoConfig.files, repoConfig.path);
gitAdd(repoConfig.path);
staging.isClean(repoConfig.path, function (afterWriteStagingIsCleanError, afterWriteStagingIsClean) {
expect(afterWriteStagingIsCleanError).to.be.null;
expect(afterWriteStagingIsClean).to.be.false;
writeFilesToPath({
dummymodified: {
contents: repoConfig.files.dummyfile.contents + '-modified',
filename: repoConfig.files.dummyfile.filename,
}
}, repoConfig.path);
staging.isClean(repoConfig.path, function (afterWriteStagingIsCleanError, afterWriteStagingIsClean) {
expect(afterWriteStagingIsCleanError).to.be.null;
expect(afterWriteStagingIsClean).to.be.false;
done();
});
});
});
});
});
it('should determine if --all flag adds files to staging area', function (done) {
this.timeout(config.maxTimeout); // this could take a while
// SETUP
// Describe a repo and some files to add and commit
let repoConfig = {
path: config.paths.endUserRepo,
files: {
dummyfile: {
contents: `duck-duck-gray-duck`,
filename: `mydummiestfile.txt`,
},
gitignore: {
contents: `node_modules/`,
filename: `.gitignore`
}
}
};
gitInit(repoConfig.path);
staging.isClean(repoConfig.path, function (stagingIsCleanError, stagingIsClean) {
expect(stagingIsCleanError).to.be.null;
expect(stagingIsClean).to.be.true;
writeFilesToPath(repoConfig.files, repoConfig.path);
staging.isClean(repoConfig.path, function (afterWriteStagingIsCleanError, afterWriteStagingIsClean) {
expect(afterWriteStagingIsCleanError).to.be.null;
expect(afterWriteStagingIsClean).to.be.true;
done();
});
}, true);
});
});
afterEach(function () {
this.timeout(config.maxTimeout); // this could take a while
// All this should do is archive the tmp path to the artifacts
clean.afterEach(config.paths.tmp, config.preserve);
});
after(function () {
this.timeout(config.maxTimeout); // this could take a while
// Once everything is done, the artifacts should be cleaned up based on
// the preserve setting in the config
clean.after(config.paths.tmp, config.preserve);
});