@neurodevs/meta-node 0.14.21 → 0.14.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__tests__/impl/GitAutocloner.test.d.ts +19 -2
- package/build/__tests__/impl/GitAutocloner.test.js +93 -10
- package/build/__tests__/impl/GitAutocloner.test.js.map +1 -1
- package/build/impl/GitAutocloner.d.ts +5 -3
- package/build/impl/GitAutocloner.js +18 -7
- package/build/impl/GitAutocloner.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/impl/GitAutocloner.test.ts +138 -13
- package/src/impl/GitAutocloner.ts +21 -7
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import AbstractPackageTest from '../AbstractPackageTest.js';
|
|
2
2
|
export default class AutoclonerTest extends AbstractPackageTest {
|
|
3
3
|
private static instance;
|
|
4
|
+
private static packageNameA;
|
|
5
|
+
private static packageNameB;
|
|
6
|
+
private static urlA;
|
|
7
|
+
private static urlB;
|
|
8
|
+
private static generateUrl;
|
|
9
|
+
private static readonly urls;
|
|
10
|
+
private static get gitPullPackageA();
|
|
11
|
+
private static get gitPullPackageB();
|
|
4
12
|
protected static beforeEach(): Promise<void>;
|
|
5
13
|
protected static canCreateAutocloner(): Promise<void>;
|
|
6
14
|
protected static throwsIfDirPathDoesNotExist(): Promise<void>;
|
|
@@ -9,13 +17,22 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
9
17
|
protected static doesNotCallGitCloneIfUrlExists(): Promise<void>;
|
|
10
18
|
protected static throwsIfGitCloneFails(): Promise<void>;
|
|
11
19
|
protected static worksWithPeriodInRepoName(): Promise<void>;
|
|
20
|
+
protected static callsYarnInstallAfterCloningFirstRepo(): Promise<void>;
|
|
21
|
+
protected static callsYarnInstallAfterCloningSecondRepo(): Promise<void>;
|
|
22
|
+
protected static callsGitPullIfFirstRepoExists(): Promise<void>;
|
|
23
|
+
protected static callsGitPullIfSecondRepoExists(): Promise<void>;
|
|
24
|
+
protected static callsYarnInstallIfFirstChangesWerePulled(): Promise<void>;
|
|
25
|
+
protected static callsYarnInstallIfSecondChangesWerePulled(): Promise<void>;
|
|
26
|
+
protected static doesNotCallYarnInstallIfNoChangesPulled(): Promise<void>;
|
|
12
27
|
private static run;
|
|
28
|
+
private static setUrlsShouldExistAndRun;
|
|
29
|
+
private static setUrlsShouldExist;
|
|
30
|
+
private static fakeGitPullChanges;
|
|
31
|
+
private static fakeGitPullUpToDate;
|
|
13
32
|
private static setFakeChdir;
|
|
14
33
|
private static setFakeExec;
|
|
15
34
|
private static setFakePathExists;
|
|
16
|
-
private static generateUrl;
|
|
17
35
|
private static get gitCloneFailedMessage();
|
|
18
|
-
private static readonly urls;
|
|
19
36
|
private static readonly validDirPath;
|
|
20
37
|
private static readonly invalidDirPath;
|
|
21
38
|
private static readonly gitCloneFailedError;
|
|
@@ -6,13 +6,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { exec as execSync } from 'child_process';
|
|
8
8
|
import { promisify } from 'util';
|
|
9
|
-
import { callsToChdir, callsToExec, fakeChdir, fakeExec, fakePathExists, resetCallsToChdir, resetCallsToExec, setPathShouldExist, } from '@neurodevs/fake-node-core';
|
|
9
|
+
import { callsToChdir, callsToExec, fakeChdir, fakeExec, fakePathExists, resetCallsToChdir, resetCallsToExec, setFakeExecResult, setPathShouldExist, } from '@neurodevs/fake-node-core';
|
|
10
10
|
import { test, assert } from '@neurodevs/node-tdd';
|
|
11
11
|
import GitAutocloner from '../../impl/GitAutocloner.js';
|
|
12
12
|
import AbstractPackageTest from '../AbstractPackageTest.js';
|
|
13
13
|
const exec = promisify(execSync);
|
|
14
14
|
export default class AutoclonerTest extends AbstractPackageTest {
|
|
15
15
|
static instance;
|
|
16
|
+
static packageNameA = this.generateId();
|
|
17
|
+
static packageNameB = this.generateId();
|
|
18
|
+
static urlA = this.generateUrl(this.packageNameA);
|
|
19
|
+
static urlB = this.generateUrl(this.packageNameB);
|
|
20
|
+
static generateUrl(packageName) {
|
|
21
|
+
return `https://github.com/${packageName}.git`;
|
|
22
|
+
}
|
|
23
|
+
static urls = [this.urlA, this.urlB];
|
|
24
|
+
static get gitPullPackageA() {
|
|
25
|
+
return `git --cwd ./${this.packageNameA} pull`;
|
|
26
|
+
}
|
|
27
|
+
static get gitPullPackageB() {
|
|
28
|
+
return `git --cwd ./${this.packageNameB} pull`;
|
|
29
|
+
}
|
|
16
30
|
static async beforeEach() {
|
|
17
31
|
await super.beforeEach();
|
|
18
32
|
this.setFakeChdir();
|
|
@@ -38,13 +52,10 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
38
52
|
});
|
|
39
53
|
}
|
|
40
54
|
static async doesNotCallGitCloneIfUrlExists() {
|
|
41
|
-
|
|
42
|
-
this.urls.forEach((url) => {
|
|
43
|
-
setPathShouldExist(url.match(this.regexForRepoName)[1], true);
|
|
44
|
-
});
|
|
55
|
+
this.setUrlsShouldExist();
|
|
45
56
|
resetCallsToExec();
|
|
46
57
|
await this.run();
|
|
47
|
-
assert.isLength(callsToExec, 0);
|
|
58
|
+
assert.isLength(callsToExec.filter((call) => call.startsWith('git clone')), 0);
|
|
48
59
|
}
|
|
49
60
|
static async throwsIfGitCloneFails() {
|
|
50
61
|
GitAutocloner.exec = (_command) => {
|
|
@@ -57,6 +68,37 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
57
68
|
const repoName = `/${this.generateId()}.${this.generateId()}.git`;
|
|
58
69
|
await this.run({ urls: [repoName] });
|
|
59
70
|
}
|
|
71
|
+
static async callsYarnInstallAfterCloningFirstRepo() {
|
|
72
|
+
await this.run();
|
|
73
|
+
assert.isEqualDeep(callsToExec[1], `yarn --cwd ./${this.packageNameA} install`, 'Should call yarn install after cloning first package!');
|
|
74
|
+
}
|
|
75
|
+
static async callsYarnInstallAfterCloningSecondRepo() {
|
|
76
|
+
await this.run();
|
|
77
|
+
assert.isEqualDeep(callsToExec[3], `yarn --cwd ./${this.packageNameB} install`, 'Should call yarn install after cloning second package!');
|
|
78
|
+
}
|
|
79
|
+
static async callsGitPullIfFirstRepoExists() {
|
|
80
|
+
await this.setUrlsShouldExistAndRun();
|
|
81
|
+
assert.isEqualDeep(callsToExec[0], this.gitPullPackageA, 'Should call git pull if first repo exists!');
|
|
82
|
+
}
|
|
83
|
+
static async callsGitPullIfSecondRepoExists() {
|
|
84
|
+
await this.setUrlsShouldExistAndRun();
|
|
85
|
+
assert.isEqualDeep(callsToExec[2], this.gitPullPackageB, 'Should call git pull if second repo exists!');
|
|
86
|
+
}
|
|
87
|
+
static async callsYarnInstallIfFirstChangesWerePulled() {
|
|
88
|
+
this.fakeGitPullChanges();
|
|
89
|
+
await this.setUrlsShouldExistAndRun();
|
|
90
|
+
assert.isEqualDeep(callsToExec[1], `yarn --cwd ./${this.packageNameA} install`, 'Should call yarn install after pulling first package!');
|
|
91
|
+
}
|
|
92
|
+
static async callsYarnInstallIfSecondChangesWerePulled() {
|
|
93
|
+
this.fakeGitPullChanges();
|
|
94
|
+
await this.setUrlsShouldExistAndRun();
|
|
95
|
+
assert.isEqualDeep(callsToExec[3], `yarn --cwd ./${this.packageNameB} install`, 'Should call yarn install after pulling second package!');
|
|
96
|
+
}
|
|
97
|
+
static async doesNotCallYarnInstallIfNoChangesPulled() {
|
|
98
|
+
this.fakeGitPullUpToDate();
|
|
99
|
+
await this.setUrlsShouldExistAndRun();
|
|
100
|
+
assert.isLength(callsToExec.filter((call) => call.startsWith('yarn --cwd ./')), 0, 'Should not call yarn install if no changes were pulled!');
|
|
101
|
+
}
|
|
60
102
|
static run(options) {
|
|
61
103
|
return this.instance.run({
|
|
62
104
|
urls: this.urls,
|
|
@@ -64,6 +106,30 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
64
106
|
...options,
|
|
65
107
|
});
|
|
66
108
|
}
|
|
109
|
+
static async setUrlsShouldExistAndRun() {
|
|
110
|
+
this.setUrlsShouldExist();
|
|
111
|
+
resetCallsToExec();
|
|
112
|
+
await this.run();
|
|
113
|
+
}
|
|
114
|
+
static setUrlsShouldExist() {
|
|
115
|
+
this.urls.forEach((url) => {
|
|
116
|
+
setPathShouldExist(url.match(this.regexForRepoName)[1], true);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static fakeGitPullChanges() {
|
|
120
|
+
const fakeResult = {
|
|
121
|
+
stdout: this.generateId(),
|
|
122
|
+
};
|
|
123
|
+
setFakeExecResult(this.gitPullPackageA, fakeResult);
|
|
124
|
+
setFakeExecResult(this.gitPullPackageB, fakeResult);
|
|
125
|
+
}
|
|
126
|
+
static fakeGitPullUpToDate() {
|
|
127
|
+
const fakeResult = {
|
|
128
|
+
stdout: 'Already up to date.',
|
|
129
|
+
};
|
|
130
|
+
setFakeExecResult(this.gitPullPackageA, fakeResult);
|
|
131
|
+
setFakeExecResult(this.gitPullPackageB, fakeResult);
|
|
132
|
+
}
|
|
67
133
|
static setFakeChdir() {
|
|
68
134
|
GitAutocloner.chdir = fakeChdir;
|
|
69
135
|
resetCallsToChdir();
|
|
@@ -81,13 +147,9 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
81
147
|
setPathShouldExist(url.match(this.regexForRepoName)[1], false);
|
|
82
148
|
});
|
|
83
149
|
}
|
|
84
|
-
static generateUrl() {
|
|
85
|
-
return `https://github.com/${this.generateId()}.git`;
|
|
86
|
-
}
|
|
87
150
|
static get gitCloneFailedMessage() {
|
|
88
151
|
return `Git clone failed for repo: ${this.urls[0]}! Error: \n\n${this.gitCloneFailedError}\n\n`;
|
|
89
152
|
}
|
|
90
|
-
static urls = [this.generateUrl(), this.generateUrl()];
|
|
91
153
|
static validDirPath = this.generateId();
|
|
92
154
|
static invalidDirPath = this.generateId();
|
|
93
155
|
static gitCloneFailedError = 'Failed to clone repo!';
|
|
@@ -117,4 +179,25 @@ __decorate([
|
|
|
117
179
|
__decorate([
|
|
118
180
|
test()
|
|
119
181
|
], AutoclonerTest, "worksWithPeriodInRepoName", null);
|
|
182
|
+
__decorate([
|
|
183
|
+
test()
|
|
184
|
+
], AutoclonerTest, "callsYarnInstallAfterCloningFirstRepo", null);
|
|
185
|
+
__decorate([
|
|
186
|
+
test()
|
|
187
|
+
], AutoclonerTest, "callsYarnInstallAfterCloningSecondRepo", null);
|
|
188
|
+
__decorate([
|
|
189
|
+
test()
|
|
190
|
+
], AutoclonerTest, "callsGitPullIfFirstRepoExists", null);
|
|
191
|
+
__decorate([
|
|
192
|
+
test()
|
|
193
|
+
], AutoclonerTest, "callsGitPullIfSecondRepoExists", null);
|
|
194
|
+
__decorate([
|
|
195
|
+
test()
|
|
196
|
+
], AutoclonerTest, "callsYarnInstallIfFirstChangesWerePulled", null);
|
|
197
|
+
__decorate([
|
|
198
|
+
test()
|
|
199
|
+
], AutoclonerTest, "callsYarnInstallIfSecondChangesWerePulled", null);
|
|
200
|
+
__decorate([
|
|
201
|
+
test()
|
|
202
|
+
], AutoclonerTest, "doesNotCallYarnInstallIfNoChangesPulled", null);
|
|
120
203
|
//# sourceMappingURL=GitAutocloner.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitAutocloner.test.js","sourceRoot":"","sources":["../../../src/__tests__/impl/GitAutocloner.test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"GitAutocloner.test.js","sourceRoot":"","sources":["../../../src/__tests__/impl/GitAutocloner.test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAgB,IAAI,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EACH,YAAY,EACZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACrB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,qBAAqB,C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17
|
private checkIfDirPathExists;
|
|
18
18
|
private throwDirPathDoesNotExist;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
19
|
+
private chdirToDirPath;
|
|
20
|
+
private runForEachUrl;
|
|
21
|
+
private runCurrentUrl;
|
|
22
22
|
private checkIfCurrentRepoExists;
|
|
23
23
|
private get currentRepoName();
|
|
24
24
|
private readonly regexForRepoName;
|
|
25
25
|
private tryToCloneRepo;
|
|
26
26
|
private throwGitCloneFailed;
|
|
27
27
|
private get gitCloneFailedMessage();
|
|
28
|
+
private runYarnInstall;
|
|
29
|
+
private runGitPull;
|
|
28
30
|
private get chdir();
|
|
29
31
|
private get exec();
|
|
30
32
|
private get pathExists();
|
|
@@ -21,8 +21,8 @@ export default class GitAutocloner {
|
|
|
21
21
|
this.urls = urls;
|
|
22
22
|
this.dirPath = dirPath;
|
|
23
23
|
await this.throwIfDirPathDoesNotExist();
|
|
24
|
-
this.
|
|
25
|
-
await this.
|
|
24
|
+
this.chdirToDirPath();
|
|
25
|
+
await this.runForEachUrl();
|
|
26
26
|
}
|
|
27
27
|
async throwIfDirPathDoesNotExist() {
|
|
28
28
|
const dirPathExists = await this.checkIfDirPathExists();
|
|
@@ -36,23 +36,28 @@ export default class GitAutocloner {
|
|
|
36
36
|
throwDirPathDoesNotExist() {
|
|
37
37
|
throw new Error(`dirPath does not exist: ${this.dirPath}!`);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
chdirToDirPath() {
|
|
40
40
|
this.chdir(this.dirPath);
|
|
41
41
|
}
|
|
42
|
-
async
|
|
42
|
+
async runForEachUrl() {
|
|
43
43
|
for (const url of this.urls) {
|
|
44
44
|
this.currentUrl = url;
|
|
45
|
-
await this.
|
|
45
|
+
await this.runCurrentUrl();
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async
|
|
48
|
+
async runCurrentUrl() {
|
|
49
49
|
const currentRepoExists = await this.checkIfCurrentRepoExists();
|
|
50
50
|
if (!currentRepoExists) {
|
|
51
51
|
this.log.info(`Cloning repo: ${this.currentUrl}...`);
|
|
52
52
|
await this.tryToCloneRepo();
|
|
53
|
+
await this.runYarnInstall();
|
|
53
54
|
}
|
|
54
55
|
else {
|
|
55
|
-
this.log.info(`Repo exists,
|
|
56
|
+
this.log.info(`Repo exists, pulling: ${this.currentRepoName}...`);
|
|
57
|
+
const { stdout } = await this.runGitPull();
|
|
58
|
+
if (!stdout.includes('Already up to date')) {
|
|
59
|
+
await this.runYarnInstall();
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
async checkIfCurrentRepoExists() {
|
|
@@ -77,6 +82,12 @@ export default class GitAutocloner {
|
|
|
77
82
|
get gitCloneFailedMessage() {
|
|
78
83
|
return `Git clone failed for repo: ${this.currentUrl}!\n\n${this.currentError}\n\n`;
|
|
79
84
|
}
|
|
85
|
+
async runYarnInstall() {
|
|
86
|
+
await this.exec(`yarn --cwd ./${this.currentRepoName} install`);
|
|
87
|
+
}
|
|
88
|
+
async runGitPull() {
|
|
89
|
+
return await this.exec(`git --cwd ./${this.currentRepoName} pull`);
|
|
90
|
+
}
|
|
80
91
|
get chdir() {
|
|
81
92
|
return GitAutocloner.chdir;
|
|
82
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitAutocloner.js","sourceRoot":"","sources":["../../src/impl/GitAutocloner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,MAAM,CAAC,OAAO,OAAO,aAAa;IACvB,MAAM,CAAC,KAAK,CAAwB;IACpC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,MAAM,CAAC,IAAI,GAAG,SAAS,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gBAAgB,IAAI,CAAC,eAAe,UAAU,CAAC,CAAA;IACnE,CAAC;IAEO,KAAK,CAAC,UAAU;QACpB,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,OAAO,CAAC,CAAA;IACtE,CAAC;IAED,IAAY,KAAK;QACb,OAAO,aAAa,CAAC,KAAK,CAAA;IAC9B,CAAC;IAED,IAAY,IAAI;QACZ,OAAO,aAAa,CAAC,IAAI,CAAA;IAC7B,CAAC;IAED,IAAY,UAAU;QAClB,OAAO,aAAa,CAAC,UAAU,CAAA;IACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { exec as execSync } from 'child_process'
|
|
1
|
+
import { ChildProcess, exec as execSync } from 'child_process'
|
|
2
2
|
import { promisify } from 'util'
|
|
3
3
|
import {
|
|
4
4
|
callsToChdir,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
fakePathExists,
|
|
9
9
|
resetCallsToChdir,
|
|
10
10
|
resetCallsToExec,
|
|
11
|
+
setFakeExecResult,
|
|
11
12
|
setPathShouldExist,
|
|
12
13
|
} from '@neurodevs/fake-node-core'
|
|
13
14
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
@@ -24,6 +25,26 @@ const exec = promisify(execSync)
|
|
|
24
25
|
export default class AutoclonerTest extends AbstractPackageTest {
|
|
25
26
|
private static instance: Autocloner
|
|
26
27
|
|
|
28
|
+
private static packageNameA = this.generateId()
|
|
29
|
+
private static packageNameB = this.generateId()
|
|
30
|
+
|
|
31
|
+
private static urlA = this.generateUrl(this.packageNameA)
|
|
32
|
+
private static urlB = this.generateUrl(this.packageNameB)
|
|
33
|
+
|
|
34
|
+
private static generateUrl(packageName: string) {
|
|
35
|
+
return `https://github.com/${packageName}.git`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private static readonly urls = [this.urlA, this.urlB]
|
|
39
|
+
|
|
40
|
+
private static get gitPullPackageA() {
|
|
41
|
+
return `git --cwd ./${this.packageNameA} pull`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private static get gitPullPackageB() {
|
|
45
|
+
return `git --cwd ./${this.packageNameB} pull`
|
|
46
|
+
}
|
|
47
|
+
|
|
27
48
|
protected static async beforeEach() {
|
|
28
49
|
await super.beforeEach()
|
|
29
50
|
|
|
@@ -74,17 +95,15 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
74
95
|
|
|
75
96
|
@test()
|
|
76
97
|
protected static async doesNotCallGitCloneIfUrlExists() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.urls.forEach((url) => {
|
|
80
|
-
setPathShouldExist(url.match(this.regexForRepoName)![1], true)
|
|
81
|
-
})
|
|
82
|
-
|
|
98
|
+
this.setUrlsShouldExist()
|
|
83
99
|
resetCallsToExec()
|
|
84
100
|
|
|
85
101
|
await this.run()
|
|
86
102
|
|
|
87
|
-
assert.isLength(
|
|
103
|
+
assert.isLength(
|
|
104
|
+
callsToExec.filter((call) => call.startsWith('git clone')),
|
|
105
|
+
0
|
|
106
|
+
)
|
|
88
107
|
}
|
|
89
108
|
|
|
90
109
|
@test()
|
|
@@ -108,6 +127,86 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
108
127
|
await this.run({ urls: [repoName] })
|
|
109
128
|
}
|
|
110
129
|
|
|
130
|
+
@test()
|
|
131
|
+
protected static async callsYarnInstallAfterCloningFirstRepo() {
|
|
132
|
+
await this.run()
|
|
133
|
+
|
|
134
|
+
assert.isEqualDeep(
|
|
135
|
+
callsToExec[1],
|
|
136
|
+
`yarn --cwd ./${this.packageNameA} install`,
|
|
137
|
+
'Should call yarn install after cloning first package!'
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@test()
|
|
142
|
+
protected static async callsYarnInstallAfterCloningSecondRepo() {
|
|
143
|
+
await this.run()
|
|
144
|
+
|
|
145
|
+
assert.isEqualDeep(
|
|
146
|
+
callsToExec[3],
|
|
147
|
+
`yarn --cwd ./${this.packageNameB} install`,
|
|
148
|
+
'Should call yarn install after cloning second package!'
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@test()
|
|
153
|
+
protected static async callsGitPullIfFirstRepoExists() {
|
|
154
|
+
await this.setUrlsShouldExistAndRun()
|
|
155
|
+
|
|
156
|
+
assert.isEqualDeep(
|
|
157
|
+
callsToExec[0],
|
|
158
|
+
this.gitPullPackageA,
|
|
159
|
+
'Should call git pull if first repo exists!'
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@test()
|
|
164
|
+
protected static async callsGitPullIfSecondRepoExists() {
|
|
165
|
+
await this.setUrlsShouldExistAndRun()
|
|
166
|
+
|
|
167
|
+
assert.isEqualDeep(
|
|
168
|
+
callsToExec[2],
|
|
169
|
+
this.gitPullPackageB,
|
|
170
|
+
'Should call git pull if second repo exists!'
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@test()
|
|
175
|
+
protected static async callsYarnInstallIfFirstChangesWerePulled() {
|
|
176
|
+
this.fakeGitPullChanges()
|
|
177
|
+
await this.setUrlsShouldExistAndRun()
|
|
178
|
+
|
|
179
|
+
assert.isEqualDeep(
|
|
180
|
+
callsToExec[1],
|
|
181
|
+
`yarn --cwd ./${this.packageNameA} install`,
|
|
182
|
+
'Should call yarn install after pulling first package!'
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@test()
|
|
187
|
+
protected static async callsYarnInstallIfSecondChangesWerePulled() {
|
|
188
|
+
this.fakeGitPullChanges()
|
|
189
|
+
await this.setUrlsShouldExistAndRun()
|
|
190
|
+
|
|
191
|
+
assert.isEqualDeep(
|
|
192
|
+
callsToExec[3],
|
|
193
|
+
`yarn --cwd ./${this.packageNameB} install`,
|
|
194
|
+
'Should call yarn install after pulling second package!'
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@test()
|
|
199
|
+
protected static async doesNotCallYarnInstallIfNoChangesPulled() {
|
|
200
|
+
this.fakeGitPullUpToDate()
|
|
201
|
+
await this.setUrlsShouldExistAndRun()
|
|
202
|
+
|
|
203
|
+
assert.isLength(
|
|
204
|
+
callsToExec.filter((call) => call.startsWith('yarn --cwd ./')),
|
|
205
|
+
0,
|
|
206
|
+
'Should not call yarn install if no changes were pulled!'
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
111
210
|
private static run(options?: Partial<AutoclonerOptions>) {
|
|
112
211
|
return this.instance.run({
|
|
113
212
|
urls: this.urls,
|
|
@@ -116,6 +215,37 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
116
215
|
})
|
|
117
216
|
}
|
|
118
217
|
|
|
218
|
+
private static async setUrlsShouldExistAndRun() {
|
|
219
|
+
this.setUrlsShouldExist()
|
|
220
|
+
resetCallsToExec()
|
|
221
|
+
|
|
222
|
+
await this.run()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private static setUrlsShouldExist() {
|
|
226
|
+
this.urls.forEach((url) => {
|
|
227
|
+
setPathShouldExist(url.match(this.regexForRepoName)![1], true)
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private static fakeGitPullChanges() {
|
|
232
|
+
const fakeResult = {
|
|
233
|
+
stdout: this.generateId(),
|
|
234
|
+
} as unknown as ChildProcess
|
|
235
|
+
|
|
236
|
+
setFakeExecResult(this.gitPullPackageA, fakeResult)
|
|
237
|
+
setFakeExecResult(this.gitPullPackageB, fakeResult)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private static fakeGitPullUpToDate() {
|
|
241
|
+
const fakeResult = {
|
|
242
|
+
stdout: 'Already up to date.',
|
|
243
|
+
} as unknown as ChildProcess
|
|
244
|
+
|
|
245
|
+
setFakeExecResult(this.gitPullPackageA, fakeResult)
|
|
246
|
+
setFakeExecResult(this.gitPullPackageB, fakeResult)
|
|
247
|
+
}
|
|
248
|
+
|
|
119
249
|
private static setFakeChdir() {
|
|
120
250
|
GitAutocloner.chdir = fakeChdir
|
|
121
251
|
resetCallsToChdir()
|
|
@@ -138,15 +268,10 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
138
268
|
})
|
|
139
269
|
}
|
|
140
270
|
|
|
141
|
-
private static generateUrl() {
|
|
142
|
-
return `https://github.com/${this.generateId()}.git`
|
|
143
|
-
}
|
|
144
|
-
|
|
145
271
|
private static get gitCloneFailedMessage() {
|
|
146
272
|
return `Git clone failed for repo: ${this.urls[0]}! Error: \n\n${this.gitCloneFailedError}\n\n`
|
|
147
273
|
}
|
|
148
274
|
|
|
149
|
-
private static readonly urls = [this.generateUrl(), this.generateUrl()]
|
|
150
275
|
private static readonly validDirPath = this.generateId()
|
|
151
276
|
private static readonly invalidDirPath = this.generateId()
|
|
152
277
|
private static readonly gitCloneFailedError = 'Failed to clone repo!'
|
|
@@ -28,9 +28,9 @@ export default class GitAutocloner implements Autocloner {
|
|
|
28
28
|
this.dirPath = dirPath
|
|
29
29
|
|
|
30
30
|
await this.throwIfDirPathDoesNotExist()
|
|
31
|
+
this.chdirToDirPath()
|
|
31
32
|
|
|
32
|
-
this.
|
|
33
|
-
await this.cloneReposFromUrls()
|
|
33
|
+
await this.runForEachUrl()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
private async throwIfDirPathDoesNotExist() {
|
|
@@ -49,25 +49,31 @@ export default class GitAutocloner implements Autocloner {
|
|
|
49
49
|
throw new Error(`dirPath does not exist: ${this.dirPath}!`)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
private
|
|
52
|
+
private chdirToDirPath() {
|
|
53
53
|
this.chdir(this.dirPath)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
private async
|
|
56
|
+
private async runForEachUrl() {
|
|
57
57
|
for (const url of this.urls) {
|
|
58
58
|
this.currentUrl = url
|
|
59
|
-
await this.
|
|
59
|
+
await this.runCurrentUrl()
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
private async
|
|
63
|
+
private async runCurrentUrl() {
|
|
64
64
|
const currentRepoExists = await this.checkIfCurrentRepoExists()
|
|
65
65
|
|
|
66
66
|
if (!currentRepoExists) {
|
|
67
67
|
this.log.info(`Cloning repo: ${this.currentUrl}...`)
|
|
68
68
|
await this.tryToCloneRepo()
|
|
69
|
+
await this.runYarnInstall()
|
|
69
70
|
} else {
|
|
70
|
-
this.log.info(`Repo exists,
|
|
71
|
+
this.log.info(`Repo exists, pulling: ${this.currentRepoName}...`)
|
|
72
|
+
const { stdout } = await this.runGitPull()
|
|
73
|
+
|
|
74
|
+
if (!stdout.includes('Already up to date')) {
|
|
75
|
+
await this.runYarnInstall()
|
|
76
|
+
}
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -98,6 +104,14 @@ export default class GitAutocloner implements Autocloner {
|
|
|
98
104
|
return `Git clone failed for repo: ${this.currentUrl}!\n\n${this.currentError}\n\n`
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
private async runYarnInstall() {
|
|
108
|
+
await this.exec(`yarn --cwd ./${this.currentRepoName} install`)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async runGitPull() {
|
|
112
|
+
return await this.exec(`git --cwd ./${this.currentRepoName} pull`)
|
|
113
|
+
}
|
|
114
|
+
|
|
101
115
|
private get chdir() {
|
|
102
116
|
return GitAutocloner.chdir
|
|
103
117
|
}
|