执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
 
describe("As a module", function() {
 
    describe("current working directory should", function() {
        it("default to node's current working directory", function() {
            var sgf = require("../");
            sgf.cwd.should.equal(process.cwd());
        });
 
        it("be over writable", function() {
            var sgf = require("../");
            sgf.cwd = test_folder
            sgf.cwd.should.equal(test_folder);
        });
    });
 
    describe("getHead will return", function() {
 
        beforeEach(function(done) {
            setup(function(err) {
                if (err) {
                    done(err);
                } else {
                    newGit(function(err, stdout, stderr) {
                        if (err || stderr) {
                            done(err || new Error(stderr));
                        } else {
                            done();
                        }
                    });
                }
            });
        });
 
        it("firstHead in a repo without commits", function(done) {
            var sgf = newSGF();
            sgf.getHead(asyncCatch(done, function(head){
                head.should.equal('4b825dc642cb6eb9a060e54bf8d69288fbee4904');
            }));
        });
 
        it("some hash in a repo with commits", function(done) {
            addAndCommitFile(function(err, data) {
                if (err) {
                    done(err);
                } else {
                    var sgf = newSGF();
                    sgf.getHead(asyncCatch(done, function(head){
                        head.should.not.equal(sgf.firstHead);
                    }));
                }
            });
        });
    });
 
    describe("used in a directory with staged files", function() {
 
        beforeEach(function(done) {
            setup(function(err) {
                if (err) {
                    done(err);
                } else {
                    newGit(function(err, stdout, stderr) {
                        if (err || stderr) {
                            done(err || new Error(stderr));
                        } else {
                            addAndCommitFile(function(err){
                                done(err);
                            });
                        }
                    });
                }
            });
        });
 
        it("I, being the cli, should log the file paths and their git status", function(done) {
            addFiles(2, function(err, data) {
                if (err) return done(err);
 
                var sorter = function(a,b){
                    if(a.filename > b.filename){
                        return 1;
                    }
                    else if(a.filename < b.filename){
                        return -1;
                    }
                    else{
                        return 0;
                    }
                };
                data.sort(sorter);
 
                exec('../../bin/cli.js', {cwd: test_folder}, function(err, stdout, stderr) {
                    if (err) return done(err);
                    var results = stdout.trim().split('\n').map(function(line) {
                      var p = line.split(' ');
                      var status = p[0];
                      var filename = p.slice(1).join(' ');
                      return {
                        status: status,
                        filename: filename
                      };
                    });
                    results.sort(sorter);
                    for(var i=0; i<results.length; i++){
                        results[i].filename.should.equal(data[i].filename);
                        results[i].status.should.equal("Added");
                    }
                    done();
                });
            });
        });
 
        it("I should return the file paths and their git status", function(done) {
            this.timeout(1000000000);
            addFiles(1000, function(err, data) {
                if(err){
                    done(err);
                }
                else{
 
                    var sorter = function(a,b){
                        if(a.filename > b.filename){
                            return 1;
                        }
                        else if(a.filename < b.filename){
                            return -1;
                        }
                        else{
                            return 0;
                        }
                    };
 
                    data.sort(sorter);
 
                    var sgf = newSGF();
                    sgf(asyncCatch(done, function(results){
                        results.sort(sorter);
                        for(var i=0; i<results.length; i++){
                            results[i].filename.should.equal(data[i].filename);
                            results[i].status.should.equal("Added");
                        }
                    }));
                }
            });
        });
 
        it("I should find renames", function(done) {
            addAndCommitFile(function(err, data) {
                if (err) {
                    done(err);
                } else {
                    var newFileName = randomFileName([8, 3]);
 
                    moveFile({
                        oldFileName: data.filename,
                        newFileName: newFileName
                    }, function(err) {
                        var sgf = newSGF();
                        sgf(asyncCatch(done, function(results) {
                            results.length.should.equal(1);
                            results[0].filename.should.equal(newFileName);
                            results[0].status.should.equal("Renamed");
                        }));
                    });
                }
            });
        });
 
        it("if 'R' flag is not included I should not find renames", function(done) {
            addAndCommitFile(function(err, data) {
                if (err) {
                    done(err);
                } else {
                    var newFileName = randomFileName([8, 3]);
 
                    moveFile({
                        oldFileName: data.filename,
                        newFileName: newFileName
                    }, function(err) {
                        var sgf = newSGF();
                        sgf('A', asyncCatch(done, function(results) {
                            results.length.should.equal(1);
                            results[0].filename.should.equal(newFileName);
                            results[0].status.should.equal("Added");
                        }));
                    });
                }
            });
        });
 
        it("if includeContent is set to true I should return the file paths, their git status and the content", function(done) {
            addFile(function(err, data) {
                var sgf = newSGF();
                sgf.includeContent = true;
                sgf(asyncCatch(done, function(results){
                    results[0].filename.should.equal(data.filename);
                    results[0].status.should.equal("Added");
                    results[0].content.should.equal(data.content);
                }));
            });
        });
 
        it("readFile will aysnc read a file and return its content", function(done) {
            addFile(function(err, data) {
                var sgf = newSGF();
                sgf.readFile(data.filename, {
                    encoding: "utf8"
                }, function(err, content) {
                    content.should.equal(data.content);
                    done(err);
                });
            });
        });
 
        it("the staged filename contains chinese", function(done) {
            addAndCommitFile(function(err, data) {
                if (err) {
                    done(err);
                } else {
                    var newFileName = '你好世界';
                    moveFile({
                        oldFileName: data.filename,
                        newFileName: newFileName
                    }, function(err) {
                        var sgf = newSGF();
                        sgf(asyncCatch(done, function(results) {
                            results.length.should.equal(1);
                            results[0].filename.should.equal(newFileName);
                            results[0].status.should.equal("Renamed");
                        }));
                    });
                }
            });
        });
 
        after(function(done) {
            cleanUp(done);
        });
    });
});