create-platformatic 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -1,25 +1,39 @@
1
1
  'use strict'
2
2
 
3
+ import { safeRemove } from '@platformatic/utils'
4
+ import esmock from 'esmock'
5
+ import { mkdtemp, writeFile } from 'fs/promises'
6
+ import { deepEqual, equal, notEqual } from 'node:assert'
3
7
  import { test } from 'node:test'
4
- import { equal, deepEqual, notEqual, doesNotThrow } from 'node:assert'
5
- import { randomBetween, sleep, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, minimumSupportedNodeVersions, findRuntimeConfigFile, findComposerConfigFile, convertServiceNameToPrefix, addPrefixToEnv, safeMkdir } from '../../src/utils.mjs'
6
8
  import { tmpdir } from 'os'
7
9
  import { join } from 'path'
8
- import esmock from 'esmock'
9
10
  import semver from 'semver'
10
- import { mkdir, mkdtemp, rm, writeFile } from 'fs/promises'
11
+ import {
12
+ addPrefixToEnv,
13
+ convertServiceNameToPrefix,
14
+ findComposerConfigFile,
15
+ findDBConfigFile,
16
+ findRuntimeConfigFile,
17
+ findServiceConfigFile,
18
+ getDependencyVersion,
19
+ isCurrentVersionSupported,
20
+ isFileAccessible,
21
+ minimumSupportedNodeVersions,
22
+ randomBetween,
23
+ sleep,
24
+ } from '../../src/utils.mjs'
11
25
 
12
26
  test('getUsername from git', async () => {
13
27
  const name = 'lukeskywalker'
14
28
  const { getUsername } = await esmock.strict('../../src/utils.mjs', {
15
29
  execa: {
16
- execa: (command) => {
30
+ execa: command => {
17
31
  if (command === 'git') {
18
32
  return { stdout: name }
19
33
  }
20
34
  return ''
21
- }
22
- }
35
+ },
36
+ },
23
37
  })
24
38
  const username = await getUsername()
25
39
  equal(username, name)
@@ -29,13 +43,13 @@ test('getUsername from whoami', async () => {
29
43
  const name = 'hansolo'
30
44
  const { getUsername } = await esmock.strict('../../src/utils.mjs', {
31
45
  execa: {
32
- execa: (command) => {
46
+ execa: command => {
33
47
  if (command === 'whoami') {
34
48
  return { stdout: name }
35
49
  }
36
50
  return ''
37
- }
38
- }
51
+ },
52
+ },
39
53
  })
40
54
  const username = await getUsername()
41
55
  equal(username, name)
@@ -46,7 +60,7 @@ test('if getUsername from git failed, it tries whoim', async () => {
46
60
 
47
61
  const { getUsername } = await esmock.strict('../../src/utils.mjs', {
48
62
  execa: {
49
- execa: (command) => {
63
+ execa: command => {
50
64
  if (command === 'git') {
51
65
  throw new Error('git failed')
52
66
  }
@@ -55,8 +69,8 @@ test('if getUsername from git failed, it tries whoim', async () => {
55
69
  }
56
70
 
57
71
  return ''
58
- }
59
- }
72
+ },
73
+ },
60
74
  })
61
75
  const username = await getUsername()
62
76
  equal(username, name)
@@ -65,7 +79,7 @@ test('if getUsername from git failed, it tries whoim', async () => {
65
79
  test('if both git usern.ame and whoami fail, no username is set', async () => {
66
80
  const { getUsername } = await esmock.strict('../../src/utils.mjs', {
67
81
  execa: {
68
- execa: (command) => {
82
+ execa: command => {
69
83
  if (command === 'git') {
70
84
  throw new Error('git failed')
71
85
  }
@@ -73,8 +87,8 @@ test('if both git usern.ame and whoami fail, no username is set', async () => {
73
87
  throw new Error('whoami failed')
74
88
  }
75
89
  return ''
76
- }
77
- }
90
+ },
91
+ },
78
92
  })
79
93
  const username = await getUsername()
80
94
  equal(username, null)
@@ -83,10 +97,10 @@ test('if both git usern.ame and whoami fail, no username is set', async () => {
83
97
  test('getUsername - no username found', async () => {
84
98
  const { getUsername } = await esmock.strict('../../src/utils.mjs', {
85
99
  execa: {
86
- execa: (command) => {
100
+ execa: command => {
87
101
  return ''
88
- }
89
- }
102
+ },
103
+ },
90
104
  })
91
105
  const username = await getUsername()
92
106
  equal(username, null)
@@ -140,8 +154,8 @@ test('findDBConfigFile', async () => {
140
154
  await writeFile(config, 'TEST')
141
155
  equal(await findDBConfigFile(tmpDir1), 'platformatic.db.yml')
142
156
  equal(await findDBConfigFile(tmpDir2), undefined)
143
- await rm(tmpDir1, { recursive: true, force: true })
144
- await rm(tmpDir2, { recursive: true, force: true })
157
+ await safeRemove(tmpDir1)
158
+ await safeRemove(tmpDir2)
145
159
  })
146
160
 
147
161
  test('findServiceConfigFile', async () => {
@@ -151,8 +165,8 @@ test('findServiceConfigFile', async () => {
151
165
  await writeFile(config, 'TEST')
152
166
  equal(await findServiceConfigFile(tmpDir1), 'platformatic.service.toml')
153
167
  equal(await findServiceConfigFile(tmpDir2), undefined)
154
- await rm(tmpDir1, { recursive: true, force: true })
155
- await rm(tmpDir2, { recursive: true, force: true })
168
+ await safeRemove(tmpDir1)
169
+ await safeRemove(tmpDir2)
156
170
  })
157
171
 
158
172
  test('findComposerConfigFile', async () => {
@@ -162,8 +176,8 @@ test('findComposerConfigFile', async () => {
162
176
  await writeFile(config, 'TEST')
163
177
  equal(await findComposerConfigFile(tmpDir1), 'platformatic.composer.yml')
164
178
  equal(await findComposerConfigFile(tmpDir2), undefined)
165
- await rm(tmpDir1, { recursive: true, force: true })
166
- await rm(tmpDir2, { recursive: true, force: true })
179
+ await safeRemove(tmpDir1)
180
+ await safeRemove(tmpDir2)
167
181
  })
168
182
 
169
183
  test('findRuntimeConfigFile', async () => {
@@ -173,8 +187,8 @@ test('findRuntimeConfigFile', async () => {
173
187
  await writeFile(config, 'TEST')
174
188
  equal(await findRuntimeConfigFile(tmpDir1), 'platformatic.runtime.yml')
175
189
  equal(await findRuntimeConfigFile(tmpDir2), undefined)
176
- await rm(tmpDir1, { recursive: true, force: true })
177
- await rm(tmpDir2, { recursive: true, force: true })
190
+ await safeRemove(tmpDir1)
191
+ await safeRemove(tmpDir2)
178
192
  })
179
193
 
180
194
  test('isFileAccessible', async () => {
@@ -184,7 +198,7 @@ test('isFileAccessible', async () => {
184
198
  equal(await isFileAccessible(config), true)
185
199
  const config2 = join(tmpDir1, 'platformatic2.db.yml')
186
200
  equal(await isFileAccessible(config2), false)
187
- await rm(tmpDir1, { recursive: true, force: true })
201
+ await safeRemove(tmpDir1)
188
202
  })
189
203
 
190
204
  test('minimumSupportedNodeVersions', async () => {
@@ -257,10 +271,10 @@ test('should convert service name to env prefix', async () => {
257
271
  'my-service': 'MY_SERVICE',
258
272
  a: 'A',
259
273
  MY_SERVICE: 'MY_SERVICE',
260
- asderas123: 'ASDERAS123'
274
+ asderas123: 'ASDERAS123',
261
275
  }
262
276
 
263
- Object.entries(expectations).forEach((exp) => {
277
+ Object.entries(expectations).forEach(exp => {
264
278
  const converted = convertServiceNameToPrefix(exp[0])
265
279
  equal(exp[1], converted)
266
280
  })
@@ -270,22 +284,10 @@ test('should add prefix to a key/value object', async () => {
270
284
  const prefix = 'MY_PREFIX'
271
285
  const env = {
272
286
  PLT_HOSTNAME: 'myhost',
273
- PORT: '3042'
287
+ PORT: '3042',
274
288
  }
275
289
  deepEqual(addPrefixToEnv(env, prefix), {
276
290
  MY_PREFIX_PLT_HOSTNAME: 'myhost',
277
- MY_PREFIX_PORT: '3042'
278
- })
279
- })
280
-
281
- test('safeMkdir should not throw if dir already exists', async () => {
282
- const tempDirectory = join(tmpdir(), 'safeMkdirTest')
283
- test.after(async () => {
284
- await rm(tempDirectory, { recursive: true })
285
- })
286
- await mkdir(tempDirectory)
287
-
288
- doesNotThrow(async () => {
289
- await safeMkdir(tempDirectory)
291
+ MY_PREFIX_PORT: '3042',
290
292
  })
291
293
  })