create-platformatic 0.45.1 → 0.46.2
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/package.json +4 -4
- package/src/composer/create-composer-cli.mjs +1 -1
- package/src/create-plugins.mjs +232 -0
- package/src/db/create-db-cli.mjs +3 -2
- package/src/db/create-db.mjs +246 -36
- package/src/ghaction.mjs +1 -1
- package/src/runtime/create-runtime-cli.mjs +1 -1
- package/src/service/create-service-cli.mjs +6 -3
- package/src/service/create-service.mjs +3 -84
- package/test/cli-options.test.mjs +0 -84
- package/test/composer/create-composer.test.mjs +0 -75
- package/test/create-gitignore.test.mjs +0 -35
- package/test/create-package-json.test.mjs +0 -81
- package/test/db/create-db.test.mjs +0 -295
- package/test/exports.test.mjs +0 -8
- package/test/get-pkg-manager.test.mjs +0 -36
- package/test/ghaction-dynamic.test.mjs +0 -98
- package/test/ghaction-static.test.mjs +0 -97
- package/test/runtime/create-runtime.test.mjs +0 -70
- package/test/service/create-service.test.mjs +0 -147
- package/test/utils.test.mjs +0 -261
package/test/utils.test.mjs
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { test } from 'tap'
|
|
2
|
-
import { randomBetween, sleep, validatePath, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, minimumSupportedNodeVersions, findRuntimeConfigFile, findComposerConfigFile } from '../src/utils.mjs'
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
|
4
|
-
import { tmpdir, platform } from 'os'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import esmock from 'esmock'
|
|
7
|
-
import semver from 'semver'
|
|
8
|
-
|
|
9
|
-
// esmock is broken on Node v20.6.0+
|
|
10
|
-
// Resolve once https://github.com/iambumblehead/esmock/issues/234 is fixed.
|
|
11
|
-
|
|
12
|
-
const skip = semver.gte(process.version, '20.6.0')
|
|
13
|
-
|
|
14
|
-
test('getUsername from git', { skip }, async ({ end, equal }) => {
|
|
15
|
-
const name = 'lukeskywalker'
|
|
16
|
-
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
17
|
-
execa: {
|
|
18
|
-
execa: (command) => {
|
|
19
|
-
if (command === 'git') {
|
|
20
|
-
return { stdout: name }
|
|
21
|
-
}
|
|
22
|
-
return ''
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
const username = await getUsername()
|
|
27
|
-
equal(username, name)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('getUsername from whoami', { skip }, async ({ end, equal }) => {
|
|
31
|
-
const name = 'hansolo'
|
|
32
|
-
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
33
|
-
execa: {
|
|
34
|
-
execa: (command) => {
|
|
35
|
-
if (command === 'whoami') {
|
|
36
|
-
return { stdout: name }
|
|
37
|
-
}
|
|
38
|
-
return ''
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
const username = await getUsername()
|
|
43
|
-
equal(username, name)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('if getUsername from git failed, it tries whoim', { skip }, async ({ end, equal }) => {
|
|
47
|
-
const name = 'lukeskywalker'
|
|
48
|
-
|
|
49
|
-
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
50
|
-
execa: {
|
|
51
|
-
execa: (command) => {
|
|
52
|
-
if (command === 'git') {
|
|
53
|
-
throw new Error('git failed')
|
|
54
|
-
}
|
|
55
|
-
if (command === 'whoami') {
|
|
56
|
-
return { stdout: name }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return ''
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
const username = await getUsername()
|
|
64
|
-
equal(username, name)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('if both git usern.ame and whoami fail, no username is set', { skip }, async ({ end, equal }) => {
|
|
68
|
-
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
69
|
-
execa: {
|
|
70
|
-
execa: (command) => {
|
|
71
|
-
if (command === 'git') {
|
|
72
|
-
throw new Error('git failed')
|
|
73
|
-
}
|
|
74
|
-
if (command === 'whoami') {
|
|
75
|
-
throw new Error('whoami failed')
|
|
76
|
-
}
|
|
77
|
-
return ''
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
const username = await getUsername()
|
|
82
|
-
equal(username, null)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('getUsername - no username found', { skip }, async ({ end, equal }) => {
|
|
86
|
-
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
87
|
-
execa: {
|
|
88
|
-
execa: (command) => {
|
|
89
|
-
return ''
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
const username = await getUsername()
|
|
94
|
-
equal(username, null)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test('randomBetween', async ({ end, equal }) => {
|
|
98
|
-
const min = 1
|
|
99
|
-
const max = 10
|
|
100
|
-
const random = randomBetween(min, max)
|
|
101
|
-
equal(random >= min && random <= max, true)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('sleep', async ({ equal }) => {
|
|
105
|
-
const start = Date.now()
|
|
106
|
-
await sleep(100)
|
|
107
|
-
const end = Date.now()
|
|
108
|
-
equal(end - start >= 100, true)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('validatePath', async ({ end, equal, rejects, ok }) => {
|
|
112
|
-
{
|
|
113
|
-
// new folder
|
|
114
|
-
const valid = await validatePath('new-project')
|
|
115
|
-
ok(valid)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
// existing folder
|
|
120
|
-
const valid = await validatePath('test')
|
|
121
|
-
ok(valid)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
{
|
|
125
|
-
// current folder
|
|
126
|
-
const valid = await validatePath('.')
|
|
127
|
-
ok(valid)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (platform().indexOf('win') < 0) {
|
|
131
|
-
// not writeable folder
|
|
132
|
-
const valid = await validatePath('/')
|
|
133
|
-
ok(!valid)
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test('getDependencyVersion', async ({ equal }) => {
|
|
138
|
-
const fastifyVersion = await getDependencyVersion('fastify')
|
|
139
|
-
// We cannot assert the exact version because it changes
|
|
140
|
-
equal(semver.valid(fastifyVersion), fastifyVersion)
|
|
141
|
-
equal(semver.gt(fastifyVersion, '4.10.0'), true)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('findDBConfigFile', async ({ end, equal, mock }) => {
|
|
145
|
-
const tmpDir1 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
146
|
-
const tmpDir2 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
147
|
-
const config = join(tmpDir1, 'platformatic.db.yml')
|
|
148
|
-
writeFileSync(config, 'TEST')
|
|
149
|
-
equal(await findDBConfigFile(tmpDir1), 'platformatic.db.yml')
|
|
150
|
-
equal(await findDBConfigFile(tmpDir2), undefined)
|
|
151
|
-
rmSync(tmpDir1, { recursive: true, force: true })
|
|
152
|
-
rmSync(tmpDir2, { recursive: true, force: true })
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('findServiceConfigFile', async ({ end, equal, mock }) => {
|
|
156
|
-
const tmpDir1 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
157
|
-
const tmpDir2 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
158
|
-
const config = join(tmpDir1, 'platformatic.service.toml')
|
|
159
|
-
writeFileSync(config, 'TEST')
|
|
160
|
-
equal(await findServiceConfigFile(tmpDir1), 'platformatic.service.toml')
|
|
161
|
-
equal(await findServiceConfigFile(tmpDir2), undefined)
|
|
162
|
-
rmSync(tmpDir1, { recursive: true, force: true })
|
|
163
|
-
rmSync(tmpDir2, { recursive: true, force: true })
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
test('findComposerConfigFile', async ({ end, equal, mock }) => {
|
|
167
|
-
const tmpDir1 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
168
|
-
const tmpDir2 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
169
|
-
const config = join(tmpDir1, 'platformatic.composer.yml')
|
|
170
|
-
writeFileSync(config, 'TEST')
|
|
171
|
-
equal(await findComposerConfigFile(tmpDir1), 'platformatic.composer.yml')
|
|
172
|
-
equal(await findComposerConfigFile(tmpDir2), undefined)
|
|
173
|
-
rmSync(tmpDir1, { recursive: true, force: true })
|
|
174
|
-
rmSync(tmpDir2, { recursive: true, force: true })
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
test('findRuntimeConfigFile', async ({ end, equal, mock }) => {
|
|
178
|
-
const tmpDir1 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
179
|
-
const tmpDir2 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
180
|
-
const config = join(tmpDir1, 'platformatic.runtime.yml')
|
|
181
|
-
writeFileSync(config, 'TEST')
|
|
182
|
-
equal(await findRuntimeConfigFile(tmpDir1), 'platformatic.runtime.yml')
|
|
183
|
-
equal(await findRuntimeConfigFile(tmpDir2), undefined)
|
|
184
|
-
rmSync(tmpDir1, { recursive: true, force: true })
|
|
185
|
-
rmSync(tmpDir2, { recursive: true, force: true })
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
test('isFileAccessible', async ({ end, equal, mock }) => {
|
|
189
|
-
const tmpDir1 = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
190
|
-
const config = join(tmpDir1, 'platformatic.db.yml')
|
|
191
|
-
writeFileSync(config, 'TEST')
|
|
192
|
-
equal(await isFileAccessible(config), true)
|
|
193
|
-
const config2 = join(tmpDir1, 'platformatic2.db.yml')
|
|
194
|
-
equal(await isFileAccessible(config2), false)
|
|
195
|
-
rmSync(tmpDir1, { recursive: true, force: true })
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
test('minimumSupportedNodeVersions', async ({ equal, not }) => {
|
|
199
|
-
equal(Array.isArray(minimumSupportedNodeVersions), true)
|
|
200
|
-
not(minimumSupportedNodeVersions.length, 0)
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
test('isCurrentVersionSupported', async ({ equal }) => {
|
|
204
|
-
const { major, minor, patch } = semver.minVersion(minimumSupportedNodeVersions[0])
|
|
205
|
-
{
|
|
206
|
-
// major - 1 not supported
|
|
207
|
-
const nodeVersion = `${major - 1}.${minor}.${patch}`
|
|
208
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
209
|
-
equal(supported, false)
|
|
210
|
-
}
|
|
211
|
-
{
|
|
212
|
-
// minor - 1 not supported
|
|
213
|
-
const nodeVersion = `${major}.${minor - 1}.${patch}`
|
|
214
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
215
|
-
equal(supported, false)
|
|
216
|
-
}
|
|
217
|
-
{
|
|
218
|
-
// v16 more than minimum is supported
|
|
219
|
-
const supported = isCurrentVersionSupported(`${major}.${minor + 2}.${patch}`)
|
|
220
|
-
equal(supported, true)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// node version 20 test, to check greater and lesser major version
|
|
224
|
-
{
|
|
225
|
-
// v18.0.0 is not supported
|
|
226
|
-
const nodeVersion = '18.0.0'
|
|
227
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
228
|
-
equal(supported, false)
|
|
229
|
-
}
|
|
230
|
-
{
|
|
231
|
-
// v18.8.0 is supported
|
|
232
|
-
const nodeVersion = '18.8.0'
|
|
233
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
234
|
-
equal(supported, true)
|
|
235
|
-
}
|
|
236
|
-
{
|
|
237
|
-
// v20.5.1 is not supported
|
|
238
|
-
const supported = isCurrentVersionSupported('20.5.1')
|
|
239
|
-
equal(supported, false)
|
|
240
|
-
}
|
|
241
|
-
{
|
|
242
|
-
// v20.6.0 is supported
|
|
243
|
-
const nodeVersion = '20.6.0'
|
|
244
|
-
const supported = isCurrentVersionSupported(nodeVersion)
|
|
245
|
-
equal(supported, true)
|
|
246
|
-
}
|
|
247
|
-
{
|
|
248
|
-
// v19.0.0 is not supported
|
|
249
|
-
const supported = isCurrentVersionSupported('19.0.0')
|
|
250
|
-
equal(supported, false)
|
|
251
|
-
}
|
|
252
|
-
{
|
|
253
|
-
// v19.9.0 is not supported
|
|
254
|
-
const supported = isCurrentVersionSupported('19.9.0')
|
|
255
|
-
equal(supported, false)
|
|
256
|
-
}
|
|
257
|
-
for (const version of minimumSupportedNodeVersions) {
|
|
258
|
-
const supported = isCurrentVersionSupported(version)
|
|
259
|
-
equal(supported, true)
|
|
260
|
-
}
|
|
261
|
-
})
|