@neurodevs/meta-node 0.6.1 → 0.7.0
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__/modules/GitAutocloner.test.d.ts +4 -7
- package/build/__tests__/modules/GitAutocloner.test.js +31 -27
- package/build/__tests__/modules/GitAutocloner.test.js.map +1 -1
- package/build/__tests__/modules/ImplAutomodule.test.d.ts +2 -0
- package/build/__tests__/modules/ImplAutomodule.test.js +38 -56
- package/build/__tests__/modules/ImplAutomodule.test.js.map +1 -1
- package/build/__tests__/modules/NpmAutopackage.test.d.ts +6 -10
- package/build/__tests__/modules/NpmAutopackage.test.js +96 -120
- package/build/__tests__/modules/NpmAutopackage.test.js.map +1 -1
- package/build/index.d.ts +0 -6
- package/build/index.js +1 -11
- package/build/index.js.map +1 -1
- package/build/modules/GitAutocloner.d.ts +10 -8
- package/build/modules/GitAutocloner.js +32 -25
- package/build/modules/GitAutocloner.js.map +1 -1
- package/build/modules/ImplAutomodule.d.ts +7 -2
- package/build/modules/ImplAutomodule.js +30 -17
- package/build/modules/ImplAutomodule.js.map +1 -1
- package/build/modules/NpmAutopackage.d.ts +18 -14
- package/build/modules/NpmAutopackage.js +99 -89
- package/build/modules/NpmAutopackage.js.map +1 -1
- package/build/scripts/runAutomodule.js +3 -3
- package/build/scripts/runAutomodule.js.map +1 -1
- package/build/scripts/runAutopackage.js +1 -1
- package/build/scripts/runAutopackage.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/modules/GitAutocloner.test.ts +44 -29
- package/src/__tests__/modules/ImplAutomodule.test.ts +34 -10
- package/src/__tests__/modules/NpmAutopackage.test.ts +140 -143
- package/src/index.ts +0 -11
- package/src/modules/GitAutocloner.ts +37 -26
- package/src/modules/ImplAutomodule.ts +35 -19
- package/src/modules/NpmAutopackage.ts +110 -87
- package/src/scripts/runAutomodule.ts +3 -3
- package/src/scripts/runAutopackage.ts +1 -1
- package/build/modules/pathExists.d.ts +0 -1
- package/build/modules/pathExists.js +0 -14
- package/build/modules/pathExists.js.map +0 -1
- package/build/testDoubles/fs/fakePathExists.d.ts +0 -3
- package/build/testDoubles/fs/fakePathExists.js +0 -13
- package/build/testDoubles/fs/fakePathExists.js.map +0 -1
- package/build/testDoubles/fs/fakeReadFile.d.ts +0 -5
- package/build/testDoubles/fs/fakeReadFile.js +0 -20
- package/build/testDoubles/fs/fakeReadFile.js.map +0 -1
- package/build/testDoubles/fs/fakeWriteFile.d.ts +0 -6
- package/build/testDoubles/fs/fakeWriteFile.js +0 -13
- package/build/testDoubles/fs/fakeWriteFile.js.map +0 -1
- package/src/modules/pathExists.ts +0 -10
- package/src/testDoubles/fs/fakePathExists.ts +0 -9
- package/src/testDoubles/fs/fakeReadFile.ts +0 -18
- package/src/testDoubles/fs/fakeWriteFile.ts +0 -12
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { exec as execSync } from 'child_process'
|
|
2
|
+
import { promisify } from 'util'
|
|
2
3
|
import { test, assert, generateId } from '@sprucelabs/test-utils'
|
|
4
|
+
import {
|
|
5
|
+
callsToChdir,
|
|
6
|
+
callsToExec,
|
|
7
|
+
fakeChdir,
|
|
8
|
+
fakeExec,
|
|
9
|
+
fakePathExists,
|
|
10
|
+
resetCallsToChdir,
|
|
11
|
+
resetCallsToExec,
|
|
12
|
+
setPathShouldExist,
|
|
13
|
+
} from '@neurodevs/fake-node-core'
|
|
14
|
+
import { pathExists } from 'fs-extra'
|
|
3
15
|
import GitAutocloner, {
|
|
4
16
|
Autocloner,
|
|
5
17
|
AutoclonerOptions,
|
|
6
18
|
} from '../../modules/GitAutocloner'
|
|
7
19
|
import AbstractPackageTest from '../AbstractPackageTest'
|
|
8
20
|
|
|
21
|
+
const exec = promisify(execSync)
|
|
22
|
+
|
|
9
23
|
export default class AutoclonerTest extends AbstractPackageTest {
|
|
10
24
|
private static instance: Autocloner
|
|
11
|
-
private static originalDir = process.cwd()
|
|
12
|
-
private static originalExecSync = GitAutocloner.execSync
|
|
13
|
-
private static originalExistsSync = GitAutocloner.existsSync
|
|
14
25
|
|
|
15
26
|
protected static async beforeEach() {
|
|
16
27
|
await super.beforeEach()
|
|
17
28
|
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
29
|
+
this.setFakeChdir()
|
|
30
|
+
this.setFakeExec()
|
|
31
|
+
this.setFakePathExists()
|
|
21
32
|
|
|
22
33
|
this.instance = this.GitAutocloner()
|
|
23
34
|
}
|
|
@@ -44,10 +55,8 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
44
55
|
protected static async changesCurrentDirectoryToDirPath() {
|
|
45
56
|
await this.run()
|
|
46
57
|
|
|
47
|
-
const actual = process.cwd().split('/').pop()
|
|
48
|
-
|
|
49
58
|
assert.isEqual(
|
|
50
|
-
|
|
59
|
+
callsToChdir[0],
|
|
51
60
|
this.validDirPath,
|
|
52
61
|
'Should change current directory to the dirPath!'
|
|
53
62
|
)
|
|
@@ -58,7 +67,7 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
58
67
|
await this.run()
|
|
59
68
|
|
|
60
69
|
this.urls.forEach((url) => {
|
|
61
|
-
assert.doesInclude(
|
|
70
|
+
assert.doesInclude(callsToExec, `git clone ${url}`)
|
|
62
71
|
})
|
|
63
72
|
}
|
|
64
73
|
|
|
@@ -66,19 +75,20 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
66
75
|
protected static async doesNotCallGitCloneIfUrlExists() {
|
|
67
76
|
await this.run()
|
|
68
77
|
|
|
69
|
-
this.
|
|
70
|
-
|
|
78
|
+
this.urls.forEach((url) => {
|
|
79
|
+
setPathShouldExist(url.match(this.regexForRepoName)![1], true)
|
|
80
|
+
})
|
|
71
81
|
|
|
72
|
-
|
|
82
|
+
resetCallsToExec()
|
|
73
83
|
|
|
74
84
|
await this.run()
|
|
75
85
|
|
|
76
|
-
assert.isLength(
|
|
86
|
+
assert.isLength(callsToExec, 0)
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
@test()
|
|
80
90
|
protected static async throwsIfGitCloneFails() {
|
|
81
|
-
GitAutocloner.
|
|
91
|
+
GitAutocloner.exec = (_command: string) => {
|
|
82
92
|
throw new Error(this.gitCloneFailedError)
|
|
83
93
|
}
|
|
84
94
|
|
|
@@ -105,20 +115,26 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
105
115
|
})
|
|
106
116
|
}
|
|
107
117
|
|
|
108
|
-
private static
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.callsToExecSync.push(command)
|
|
112
|
-
}
|
|
118
|
+
private static setFakeChdir() {
|
|
119
|
+
GitAutocloner.chdir = fakeChdir
|
|
120
|
+
resetCallsToChdir()
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
private static
|
|
116
|
-
GitAutocloner.
|
|
117
|
-
|
|
123
|
+
private static setFakeExec() {
|
|
124
|
+
GitAutocloner.exec = fakeExec as unknown as typeof exec
|
|
125
|
+
resetCallsToExec()
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
private static
|
|
121
|
-
|
|
128
|
+
private static setFakePathExists() {
|
|
129
|
+
GitAutocloner.pathExists =
|
|
130
|
+
fakePathExists as unknown as typeof pathExists
|
|
131
|
+
resetCallsToExec()
|
|
132
|
+
|
|
133
|
+
setPathShouldExist(this.validDirPath, true)
|
|
134
|
+
|
|
135
|
+
this.urls.forEach((url) => {
|
|
136
|
+
setPathShouldExist(url.match(this.regexForRepoName)![1], false)
|
|
137
|
+
})
|
|
122
138
|
}
|
|
123
139
|
|
|
124
140
|
private static generateUrl() {
|
|
@@ -129,12 +145,11 @@ export default class AutoclonerTest extends AbstractPackageTest {
|
|
|
129
145
|
return `Git clone failed for repo: ${this.urls[0]}! Error: \n\n${this.gitCloneFailedError}\n\n`
|
|
130
146
|
}
|
|
131
147
|
|
|
132
|
-
private static callsToExecSync: string[] = []
|
|
133
|
-
|
|
134
148
|
private static readonly urls = [this.generateUrl(), this.generateUrl()]
|
|
135
|
-
private static readonly validDirPath =
|
|
149
|
+
private static readonly validDirPath = generateId()
|
|
136
150
|
private static readonly invalidDirPath = generateId()
|
|
137
151
|
private static readonly gitCloneFailedError = 'Failed to clone repo!'
|
|
152
|
+
private static readonly regexForRepoName = /\/([a-zA-Z0-9_.-]+)\.git/
|
|
138
153
|
|
|
139
154
|
private static GitAutocloner() {
|
|
140
155
|
return GitAutocloner.Create()
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
import { exec as execSync } from 'child_process'
|
|
1
2
|
import { readFile, writeFile } from 'fs/promises'
|
|
3
|
+
import { promisify } from 'util'
|
|
2
4
|
import { test, assert, generateId } from '@sprucelabs/test-utils'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
callsToExec,
|
|
7
|
+
callsToWriteFile,
|
|
8
|
+
fakeExec,
|
|
9
|
+
fakePathExists,
|
|
10
|
+
fakeReadFile,
|
|
8
11
|
fakeReadFileResult,
|
|
12
|
+
fakeWriteFile,
|
|
9
13
|
resetCallsToReadFile,
|
|
10
|
-
setFakeReadFileResult,
|
|
11
|
-
} from '../../testDoubles/fs/fakeReadFile'
|
|
12
|
-
import fakeWriteFile, {
|
|
13
|
-
callsToWriteFile,
|
|
14
14
|
resetCallsToWriteFile,
|
|
15
|
-
|
|
15
|
+
setFakeReadFileResult,
|
|
16
|
+
setPathShouldExist,
|
|
17
|
+
} from '@neurodevs/fake-node-core'
|
|
18
|
+
import ImplAutomodule, { Automodule } from '../../modules/ImplAutomodule'
|
|
16
19
|
import AbstractPackageTest from '../AbstractPackageTest'
|
|
17
20
|
|
|
21
|
+
const exec = promisify(execSync)
|
|
22
|
+
|
|
18
23
|
export default class ImplAutomoduleTest extends AbstractPackageTest {
|
|
19
24
|
private static instance: Automodule
|
|
20
25
|
|
|
21
26
|
protected static async beforeEach() {
|
|
22
27
|
await super.beforeEach()
|
|
23
28
|
|
|
29
|
+
this.setFakeExec()
|
|
24
30
|
this.setFakePathExists()
|
|
25
31
|
this.setFakeReadFile()
|
|
26
32
|
this.setFakeWriteFile()
|
|
@@ -81,6 +87,7 @@ export default class ImplAutomoduleTest extends AbstractPackageTest {
|
|
|
81
87
|
{
|
|
82
88
|
file: `${this.testSaveDir}/${this.implName}.test.ts`,
|
|
83
89
|
data: this.testFilePattern,
|
|
90
|
+
options: undefined,
|
|
84
91
|
},
|
|
85
92
|
'Did not write expected test file!'
|
|
86
93
|
)
|
|
@@ -95,6 +102,7 @@ export default class ImplAutomoduleTest extends AbstractPackageTest {
|
|
|
95
102
|
{
|
|
96
103
|
file: `${this.moduleSaveDir}/${this.implName}.ts`,
|
|
97
104
|
data: this.moduleFilePattern,
|
|
105
|
+
options: undefined,
|
|
98
106
|
},
|
|
99
107
|
'Did not write expected module file!'
|
|
100
108
|
)
|
|
@@ -109,6 +117,7 @@ export default class ImplAutomoduleTest extends AbstractPackageTest {
|
|
|
109
117
|
{
|
|
110
118
|
file: `${this.fakeSaveDir}/Fake${this.interfaceName}.ts`,
|
|
111
119
|
data: this.fakeFilePattern,
|
|
120
|
+
options: undefined,
|
|
112
121
|
},
|
|
113
122
|
'Did not write expected fake file!'
|
|
114
123
|
)
|
|
@@ -139,10 +148,25 @@ export default class ImplAutomoduleTest extends AbstractPackageTest {
|
|
|
139
148
|
)
|
|
140
149
|
}
|
|
141
150
|
|
|
151
|
+
@test()
|
|
152
|
+
protected static async bumpsMinorVersionWithYarn() {
|
|
153
|
+
await this.run()
|
|
154
|
+
|
|
155
|
+
assert.isEqualDeep(
|
|
156
|
+
callsToExec[0],
|
|
157
|
+
'yarn version --minor --no-git-tag-version',
|
|
158
|
+
'Did not bump minor version!'
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
142
162
|
private static async run() {
|
|
143
163
|
return await this.instance.run()
|
|
144
164
|
}
|
|
145
165
|
|
|
166
|
+
private static setFakeExec() {
|
|
167
|
+
ImplAutomodule.exec = fakeExec as unknown as typeof exec
|
|
168
|
+
}
|
|
169
|
+
|
|
146
170
|
private static setFakePathExists() {
|
|
147
171
|
ImplAutomodule.pathExists = fakePathExists
|
|
148
172
|
|