forked from NathanWalker/nativescript-plugin-seed
-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathpostclone.tests.js
213 lines (180 loc) · 8.81 KB
/
postclone.tests.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
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
var exec = require('child_process').exec;
var fs = require('fs');
var glob = require("glob");
var testUtils = require("./tests.utils");
var constants = require("./tests.constants");
var path = require("path");
var _srcReadmeContent = "";
describe('postclone', function () {
// keep before 'should not init new git repo'
// in order to avoid getting new files in the git repo
it('should init new git repo', function (done) {
testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) {
if (err) {
done.fail(err);
}
testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "y", "n", "n", function (error) {
if (error) {
done.fail(error);
} else {
exec("cd " + constants.SEED_COPY_LOCATION + "/src && git config --get remote.origin.url", function (error, stdout, stderr) {
expect(stdout).toEqual("");
done();
});
}
});
});
});
it('should not init new git repo', function (done) {
testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) {
if (err) {
done.fail(err);
}
_srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md");
testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "n", "n", function (error, stdout) {
if (error) {
done.fail(error);
} else {
exec("cd " + constants.SEED_COPY_LOCATION + " && git config --get remote.origin.url", function (execError, stdout, stderr) {
expect(stdout).toContain("NativeScript/nativescript-plugin-seed.git");
done();
});
}
});
});
});
it('should crate only TypeScript app (demo)', function (done) {
testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) {
if (err) {
done.fail(err);
}
_srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md");
testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "y", "n", function (error, stdout) {
if (error) {
done.fail(error);
} else {
var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION);
expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true);
expect(stdout.includes("Updating ../demo/")).toBe(true);
expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(false);
expect(stdout.includes("Updating ../demo-angular/")).toBe(false);
done();
}
});
});
});
it('should crate only Angular app (demo-angular)', function (done) {
testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) {
if (err) {
done.fail(err);
}
_srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md");
testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "n", "y", function (error, stdout) {
if (error) {
done.fail(error);
} else {
var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION);
expect(fs.existsSync(seedCopyPath + "/demo")).toBe(false);
expect(stdout.includes("Updating ../demo/")).toBe(false);
expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true);
expect(stdout.includes("Updating ../demo-angular/")).toBe(true);
done();
}
});
});
});
it('should crate both TypeScript & Angular app (demo & demo-angular)', function (done) {
testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) {
if (err) {
done.fail(err);
}
_srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md");
testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "y", "y", function (error, stdout) {
if (error) {
done.fail(error);
} else {
var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION);
expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true);
expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true);
done();
}
});
});
});
it('should delete the seed screenshots folder', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/screenshots")).toBeFalsy();
});
it('should delete the seed CONTRIBUTING.md', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/CONTRIBUTING.md")).toBeFalsy();
});
it('should delete the seed CODE_OF_CONDUCT.md', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/CODE_OF_CONDUCT.md")).toBeFalsy();
});
it('should delete the postclone.js', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/src/scripts/postclone.js")).toBeFalsy();
});
it('should delete the seed tests folder', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/seed-tests")).toBeFalsy();
});
it('should replace the seed README with the plugin one', function () {
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/README.md")).toBeTruthy();
expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/src/README.md")).toBeFalsy();
var readmeContent = fs.readFileSync(constants.SEED_COPY_LOCATION + "/README.md");
expect(_srcReadmeContent).toEqual(readmeContent);
});
it('should rename each yourplugin file', function (done) {
glob(constants.SEED_COPY_LOCATION + "/**/yourplugin*.*", function (er, files) {
expect(files.length).toEqual(0);
done();
});
});
it('should rename each yourplugin file with the new plugin name', function (done) {
glob(constants.SEED_COPY_LOCATION + "/**/" + constants.TEST_PLUGIN_NAME + "*.*", function (er, files) {
expect(files.length).toBeGreaterThan(0);
done();
});
});
it('should replace each yourplugin string', function (done) {
testUtils.findInFiles("yourplugin", constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toEqual(0);
done();
});
});
it('should replace each YourPlugin string', function (done) {
testUtils.findInFiles("YourPlugin", constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toEqual(0);
done();
});
});
it('should replace each yourPlugin string', function (done) {
testUtils.findInFiles("yourPlugin", constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toEqual(0);
done();
});
});
it('should replace each YourName string', function (done) {
testUtils.findInFiles("YourName", constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toEqual(0);
done();
});
});
it('should replace each YourName string with the test github username', function (done) {
testUtils.findInFiles(constants.TEST_GITHUB_USERNAME, constants.SEED_COPY_LOCATION, function (resultsCount) {
// plugin author in the package json
expect(resultsCount).toEqual(1);
done();
});
});
it('should replace each YourPlugin string with ThePlugin', function (done) {
testUtils.findInFiles(constants.TEST_PLUGIN_NAME, constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toBeGreaterThan(0);
done();
});
});
it('should replace each nativescript-YourPlugin string with nativescript-ThePlugin', function (done) {
testUtils.findInFiles("nativescript-" + constants.TEST_PLUGIN_NAME, constants.SEED_COPY_LOCATION, function (resultsCount) {
expect(resultsCount).toBeGreaterThan(0);
done();
});
});
});