create-platformatic 0.46.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/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 -303
- 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 -155
- package/test/utils.test.mjs +0 -261
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.2",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"semver": "^7.5.1",
|
|
35
35
|
"undici": "^5.22.1",
|
|
36
36
|
"which": "^3.0.1",
|
|
37
|
-
"@platformatic/config": "0.46.
|
|
37
|
+
"@platformatic/config": "0.46.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"ajv": "^8.12.0",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"tap": "^16.3.6",
|
|
48
48
|
"typescript": "~5.2.0",
|
|
49
49
|
"yaml": "^2.3.1",
|
|
50
|
-
"@platformatic/db": "0.46.
|
|
51
|
-
"@platformatic/service": "0.46.
|
|
50
|
+
"@platformatic/db": "0.46.2",
|
|
51
|
+
"@platformatic/service": "0.46.2"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 tap --no-coverage test/*test.mjs test/*/*test.mjs",
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { test } from 'tap'
|
|
2
|
-
import { getRunPackageManagerInstall, getUseTypescript, getPort, getOverwriteReadme } from '../src/cli-options.mjs'
|
|
3
|
-
|
|
4
|
-
test('getRunPackageManagerInstall', async ({ same }) => {
|
|
5
|
-
same(
|
|
6
|
-
getRunPackageManagerInstall('npm'),
|
|
7
|
-
{
|
|
8
|
-
type: 'list',
|
|
9
|
-
name: 'runPackageManagerInstall',
|
|
10
|
-
message: 'Do you want to run npm install?',
|
|
11
|
-
default: true,
|
|
12
|
-
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
13
|
-
}
|
|
14
|
-
)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('getUseTypescript', async ({ same }) => {
|
|
18
|
-
same(
|
|
19
|
-
getUseTypescript(true),
|
|
20
|
-
{
|
|
21
|
-
type: 'list',
|
|
22
|
-
when: false,
|
|
23
|
-
name: 'useTypescript',
|
|
24
|
-
message: 'Do you want to use TypeScript?',
|
|
25
|
-
default: true,
|
|
26
|
-
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('getOverwriteReadme', async ({ same }) => {
|
|
32
|
-
same(
|
|
33
|
-
getOverwriteReadme(),
|
|
34
|
-
{
|
|
35
|
-
type: 'list',
|
|
36
|
-
name: 'shouldReplace',
|
|
37
|
-
message: 'Do you want to overwrite the existing README.md?',
|
|
38
|
-
default: true,
|
|
39
|
-
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('getPort', async ({ same }) => {
|
|
45
|
-
same(
|
|
46
|
-
getPort(undefined),
|
|
47
|
-
{
|
|
48
|
-
type: 'input',
|
|
49
|
-
name: 'port',
|
|
50
|
-
message: 'What port do you want to use?',
|
|
51
|
-
default: 3042
|
|
52
|
-
}
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
same(
|
|
56
|
-
getPort(undefined),
|
|
57
|
-
{
|
|
58
|
-
type: 'input',
|
|
59
|
-
name: 'port',
|
|
60
|
-
message: 'What port do you want to use?',
|
|
61
|
-
default: 3043
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
same(
|
|
66
|
-
getPort(1234),
|
|
67
|
-
{
|
|
68
|
-
type: 'input',
|
|
69
|
-
name: 'port',
|
|
70
|
-
message: 'What port do you want to use?',
|
|
71
|
-
default: 1234
|
|
72
|
-
}
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
same(
|
|
76
|
-
getPort(undefined),
|
|
77
|
-
{
|
|
78
|
-
type: 'input',
|
|
79
|
-
name: 'port',
|
|
80
|
-
message: 'What port do you want to use?',
|
|
81
|
-
default: 3044
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
})
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import createComposer from '../../src/composer/create-composer.mjs'
|
|
2
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
3
|
-
import { tmpdir } from 'os'
|
|
4
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import dotenv from 'dotenv'
|
|
7
|
-
|
|
8
|
-
const base = tmpdir()
|
|
9
|
-
let tmpDir
|
|
10
|
-
let log = []
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
log = []
|
|
17
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
18
|
-
process.env = {}
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const fakeLogger = {
|
|
22
|
-
debug: msg => log.push(msg),
|
|
23
|
-
info: msg => log.push(msg)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
test('creates composer', async ({ equal, same, ok }) => {
|
|
27
|
-
const params = {
|
|
28
|
-
hostname: 'myhost',
|
|
29
|
-
port: 6666,
|
|
30
|
-
typescript: false
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
await createComposer(params, fakeLogger, tmpDir)
|
|
34
|
-
|
|
35
|
-
const pathToComposerConfigFile = join(tmpDir, 'platformatic.composer.json')
|
|
36
|
-
const composerConfigFile = readFileSync(pathToComposerConfigFile, 'utf8')
|
|
37
|
-
const composerConfig = JSON.parse(composerConfigFile)
|
|
38
|
-
const { server, composer } = composerConfig
|
|
39
|
-
|
|
40
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
41
|
-
equal(server.port, '{PORT}')
|
|
42
|
-
|
|
43
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
44
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
45
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
46
|
-
equal(process.env.PORT, '6666')
|
|
47
|
-
process.env = {}
|
|
48
|
-
|
|
49
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
50
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
51
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
52
|
-
equal(process.env.PORT, '6666')
|
|
53
|
-
|
|
54
|
-
same(composer, {
|
|
55
|
-
services: [{
|
|
56
|
-
id: 'example',
|
|
57
|
-
origin: '{PLT_EXAMPLE_ORIGIN}',
|
|
58
|
-
openapi: {
|
|
59
|
-
url: '/documentation/json'
|
|
60
|
-
}
|
|
61
|
-
}],
|
|
62
|
-
refreshTimeout: 1000
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
67
|
-
const pathToComposerConfigFileOld = join(tmpDir, 'platformatic.composer.json')
|
|
68
|
-
writeFileSync(pathToComposerConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
69
|
-
const params = {
|
|
70
|
-
hostname: 'myhost',
|
|
71
|
-
port: 6666
|
|
72
|
-
}
|
|
73
|
-
await createComposer(params, fakeLogger, tmpDir)
|
|
74
|
-
ok(log.includes('Configuration file platformatic.composer.json found, skipping creation of configuration file.'))
|
|
75
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
2
|
-
import { tmpdir } from 'os'
|
|
3
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
4
|
-
import { createGitignore } from '../src/create-gitignore.mjs'
|
|
5
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
|
|
8
|
-
let log = ''
|
|
9
|
-
const fakeLogger = {
|
|
10
|
-
debug: msg => { log = msg }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let tmpDir
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
log = ''
|
|
16
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('creates gitignore file', async ({ end, equal }) => {
|
|
24
|
-
await createGitignore(fakeLogger, tmpDir)
|
|
25
|
-
equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} successfully created.`)
|
|
26
|
-
const accessible = await isFileAccessible(join(tmpDir, '.gitignore'))
|
|
27
|
-
equal(accessible, true)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('do not create gitignore file because already present', async ({ end, equal }) => {
|
|
31
|
-
const gitignore = join(tmpDir, '.gitignore')
|
|
32
|
-
writeFileSync(gitignore, 'TEST')
|
|
33
|
-
await createGitignore(fakeLogger, tmpDir)
|
|
34
|
-
equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} found, skipping creation of gitignore file.`)
|
|
35
|
-
})
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
2
|
-
import { tmpdir } from 'os'
|
|
3
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
4
|
-
import { createPackageJson } from '../src/create-package-json.mjs'
|
|
5
|
-
import { mkdtempSync, rmSync, writeFileSync, readFileSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
|
|
8
|
-
let log = ''
|
|
9
|
-
const fakeLogger = {
|
|
10
|
-
debug: msg => { log = msg }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let tmpDir
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
log = ''
|
|
16
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('creates package.json file for db project', async ({ equal }) => {
|
|
24
|
-
const version = '1.2.3'
|
|
25
|
-
const fastifyVersion = '4.5.6'
|
|
26
|
-
const addTSBuild = false
|
|
27
|
-
const scripts = {}
|
|
28
|
-
const dependencies = {
|
|
29
|
-
'@platformatic/db': `^${version}`
|
|
30
|
-
}
|
|
31
|
-
await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild, scripts, dependencies)
|
|
32
|
-
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
33
|
-
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
34
|
-
equal(accessible, true)
|
|
35
|
-
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
36
|
-
equal(packageJson.scripts.start, 'platformatic start')
|
|
37
|
-
equal(packageJson.scripts.build, undefined)
|
|
38
|
-
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
39
|
-
equal(packageJson.dependencies['@platformatic/db'], `^${version}`)
|
|
40
|
-
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('creates package.json file for service project', async ({ equal }) => {
|
|
44
|
-
const version = '1.2.3'
|
|
45
|
-
const fastifyVersion = '4.5.6'
|
|
46
|
-
const addTSBuild = false
|
|
47
|
-
await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
|
|
48
|
-
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
49
|
-
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
50
|
-
equal(accessible, true)
|
|
51
|
-
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
52
|
-
equal(packageJson.scripts.start, 'platformatic start')
|
|
53
|
-
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
54
|
-
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('do not create package.json file because already present', async ({ equal }) => {
|
|
58
|
-
const version = '1.2.3'
|
|
59
|
-
const fastifyVersion = '4.5.6'
|
|
60
|
-
const addTSBuild = false
|
|
61
|
-
const packagejson = join(tmpDir, 'package.json')
|
|
62
|
-
writeFileSync(packagejson, 'TEST')
|
|
63
|
-
await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
|
|
64
|
-
equal(log, `${join(tmpDir, 'package.json')} found, skipping creation of package.json file.`)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('creates package.json file with TS build', async ({ equal }) => {
|
|
68
|
-
const version = '1.2.3'
|
|
69
|
-
const fastifyVersion = '4.5.6'
|
|
70
|
-
const addTSBuild = true
|
|
71
|
-
await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
|
|
72
|
-
equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
|
|
73
|
-
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
74
|
-
equal(accessible, true)
|
|
75
|
-
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
76
|
-
equal(packageJson.scripts.start, 'platformatic start')
|
|
77
|
-
equal(packageJson.scripts.clean, 'rm -fr ./dist')
|
|
78
|
-
equal(packageJson.scripts.build, 'platformatic compile')
|
|
79
|
-
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
80
|
-
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
81
|
-
})
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import createDB from '../../src/db/create-db.mjs'
|
|
2
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
3
|
-
import { isFileAccessible } from '../../src/utils.mjs'
|
|
4
|
-
import { tmpdir } from 'os'
|
|
5
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
import dotenv from 'dotenv'
|
|
8
|
-
import { schema } from '@platformatic/db'
|
|
9
|
-
import Ajv from 'ajv'
|
|
10
|
-
|
|
11
|
-
const moviesMigrationDo = `
|
|
12
|
-
-- Add SQL in this file to create the database tables for your API
|
|
13
|
-
CREATE TABLE IF NOT EXISTS movies (
|
|
14
|
-
id INTEGER PRIMARY KEY,
|
|
15
|
-
title TEXT NOT NULL
|
|
16
|
-
);
|
|
17
|
-
`
|
|
18
|
-
|
|
19
|
-
const moviesMigrationUndo = `
|
|
20
|
-
-- Add SQL in this file to drop the database tables
|
|
21
|
-
DROP TABLE movies;
|
|
22
|
-
`
|
|
23
|
-
|
|
24
|
-
const base = tmpdir()
|
|
25
|
-
let tmpDir
|
|
26
|
-
let log = []
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
log = []
|
|
33
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
34
|
-
process.env = {}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const fakeLogger = {
|
|
38
|
-
debug: msg => log.push(msg),
|
|
39
|
-
info: msg => log.push(msg)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
test('creates project with no typescript', async ({ equal }) => {
|
|
43
|
-
const params = {
|
|
44
|
-
hostname: 'myhost',
|
|
45
|
-
port: 6666,
|
|
46
|
-
plugin: true
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
50
|
-
|
|
51
|
-
const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
|
|
52
|
-
const pathToMigrationFolder = join(tmpDir, 'migrations')
|
|
53
|
-
const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
|
|
54
|
-
const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
|
|
55
|
-
|
|
56
|
-
const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
|
|
57
|
-
const dbConfig = JSON.parse(dbConfigFile)
|
|
58
|
-
const { server, db, migrations } = dbConfig
|
|
59
|
-
const ajv = new Ajv({ strict: false })
|
|
60
|
-
ajv.addKeyword('relativePath')
|
|
61
|
-
const validate = ajv.compile(schema)
|
|
62
|
-
equal(validate(dbConfig), true)
|
|
63
|
-
|
|
64
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
65
|
-
equal(server.port, '{PORT}')
|
|
66
|
-
equal(db.connectionString, '{DATABASE_URL}')
|
|
67
|
-
equal(db.schemalock, true)
|
|
68
|
-
|
|
69
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
70
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
71
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
72
|
-
equal(process.env.PORT, '6666')
|
|
73
|
-
equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
|
|
74
|
-
process.env = {}
|
|
75
|
-
|
|
76
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
77
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
78
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
79
|
-
equal(process.env.PORT, '6666')
|
|
80
|
-
equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
|
|
81
|
-
|
|
82
|
-
equal(db.graphql, true)
|
|
83
|
-
equal(db.openapi, true)
|
|
84
|
-
equal(migrations.dir, 'migrations')
|
|
85
|
-
|
|
86
|
-
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
87
|
-
equal(migrationFileDo, moviesMigrationDo)
|
|
88
|
-
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
89
|
-
equal(migrationFileUndo, moviesMigrationUndo)
|
|
90
|
-
|
|
91
|
-
equal(await isFileAccessible(join(tmpDir, 'routes', 'root.js')), true)
|
|
92
|
-
equal(await isFileAccessible(join(tmpDir, 'plugins', 'example.js')), true)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('creates project with no typescript and no plugin', async ({ equal }) => {
|
|
96
|
-
const params = {
|
|
97
|
-
hostname: 'myhost',
|
|
98
|
-
port: 6666,
|
|
99
|
-
plugin: false,
|
|
100
|
-
connectionString: 'sqlite://./custom/path/to/db.sqlite'
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
104
|
-
|
|
105
|
-
const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
|
|
106
|
-
const pathToMigrationFolder = join(tmpDir, 'migrations')
|
|
107
|
-
const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
|
|
108
|
-
const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
|
|
109
|
-
|
|
110
|
-
const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
|
|
111
|
-
const dbConfig = JSON.parse(dbConfigFile)
|
|
112
|
-
const { server, db, migrations } = dbConfig
|
|
113
|
-
|
|
114
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
115
|
-
equal(server.port, '{PORT}')
|
|
116
|
-
equal(db.connectionString, '{DATABASE_URL}')
|
|
117
|
-
|
|
118
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
119
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
120
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
121
|
-
equal(process.env.PORT, '6666')
|
|
122
|
-
equal(process.env.DATABASE_URL, 'sqlite://./custom/path/to/db.sqlite')
|
|
123
|
-
process.env = {}
|
|
124
|
-
|
|
125
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
126
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
127
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
128
|
-
equal(process.env.PORT, '6666')
|
|
129
|
-
equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
|
|
130
|
-
|
|
131
|
-
equal(db.graphql, true)
|
|
132
|
-
equal(db.openapi, true)
|
|
133
|
-
equal(migrations.dir, 'migrations')
|
|
134
|
-
|
|
135
|
-
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
136
|
-
equal(migrationFileDo, moviesMigrationDo)
|
|
137
|
-
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
138
|
-
equal(migrationFileUndo, moviesMigrationUndo)
|
|
139
|
-
|
|
140
|
-
equal(await isFileAccessible(join(tmpDir, 'plugin.js')), false)
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('creates project with no migrations', async ({ equal }) => {
|
|
144
|
-
const params = {
|
|
145
|
-
hostname: 'myhost',
|
|
146
|
-
port: 6666,
|
|
147
|
-
migrations: ''
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
151
|
-
|
|
152
|
-
const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
|
|
153
|
-
const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
|
|
154
|
-
const dbConfig = JSON.parse(dbConfigFile)
|
|
155
|
-
const { migrations } = dbConfig
|
|
156
|
-
|
|
157
|
-
equal(migrations, undefined)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('creates project with typescript', async ({ equal, same }) => {
|
|
161
|
-
const params = {
|
|
162
|
-
hostname: 'myhost',
|
|
163
|
-
port: 6666,
|
|
164
|
-
typescript: true
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
168
|
-
|
|
169
|
-
const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
|
|
170
|
-
const pathToMigrationFolder = join(tmpDir, 'migrations')
|
|
171
|
-
const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
|
|
172
|
-
const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
|
|
173
|
-
|
|
174
|
-
const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
|
|
175
|
-
const dbConfig = JSON.parse(dbConfigFile)
|
|
176
|
-
const { server, db, migrations, plugins } = dbConfig
|
|
177
|
-
|
|
178
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
179
|
-
equal(server.port, '{PORT}')
|
|
180
|
-
equal(db.connectionString, '{DATABASE_URL}')
|
|
181
|
-
|
|
182
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
183
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
184
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
185
|
-
equal(process.env.PORT, '6666')
|
|
186
|
-
equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
|
|
187
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
188
|
-
process.env = {}
|
|
189
|
-
|
|
190
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
191
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
192
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
193
|
-
equal(process.env.PORT, '6666')
|
|
194
|
-
equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
|
|
195
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
196
|
-
|
|
197
|
-
equal(db.graphql, true)
|
|
198
|
-
equal(db.openapi, true)
|
|
199
|
-
equal(migrations.dir, 'migrations')
|
|
200
|
-
|
|
201
|
-
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
202
|
-
equal(migrationFileDo, moviesMigrationDo)
|
|
203
|
-
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
204
|
-
equal(migrationFileUndo, moviesMigrationUndo)
|
|
205
|
-
|
|
206
|
-
same(plugins.paths, [{
|
|
207
|
-
path: './plugins',
|
|
208
|
-
encapsulate: false
|
|
209
|
-
}, {
|
|
210
|
-
path: './routes'
|
|
211
|
-
}])
|
|
212
|
-
equal(plugins.typescript, '{PLT_TYPESCRIPT}')
|
|
213
|
-
equal(await isFileAccessible(join(tmpDir, 'plugins', 'example.ts')), true)
|
|
214
|
-
equal(await isFileAccessible(join(tmpDir, 'routes', 'root.ts')), true)
|
|
215
|
-
equal(await isFileAccessible(join(tmpDir, 'tsconfig.json')), true)
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
219
|
-
const pathToDbConfigFileOld = join(tmpDir, 'platformatic.db.json')
|
|
220
|
-
writeFileSync(pathToDbConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
221
|
-
const params = {
|
|
222
|
-
hostname: 'myhost',
|
|
223
|
-
port: 6666
|
|
224
|
-
}
|
|
225
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
226
|
-
ok(log.includes('Configuration file platformatic.db.json found, skipping creation of configuration file.'))
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
test('creates project with migration folder already present', async ({ equal }) => {
|
|
230
|
-
const pathToMigrationsOld = join(tmpDir, 'migrations')
|
|
231
|
-
mkdirSync(pathToMigrationsOld)
|
|
232
|
-
const params = {
|
|
233
|
-
hostname: 'myhost',
|
|
234
|
-
port: 6666
|
|
235
|
-
}
|
|
236
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
237
|
-
equal(log.includes('Migrations folder migrations found, skipping creation of migrations folder.'), true)
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
test('creates project with "do" migration already present', async ({ ok }) => {
|
|
241
|
-
const pathToMigrationsOld = join(tmpDir, 'migrations')
|
|
242
|
-
mkdirSync(pathToMigrationsOld)
|
|
243
|
-
const pathToMigrationFileDo = join(pathToMigrationsOld, '001.do.sql')
|
|
244
|
-
writeFileSync(pathToMigrationFileDo, 'test')
|
|
245
|
-
const params = {
|
|
246
|
-
hostname: 'myhost',
|
|
247
|
-
port: 6666
|
|
248
|
-
}
|
|
249
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
250
|
-
ok(log.includes('Migration file 001.do.sql found, skipping creation of migration file.'))
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
test('creates project with tsconfig already present', async ({ ok }) => {
|
|
254
|
-
const pathToTsConfig = join(tmpDir, 'tsconfig.json')
|
|
255
|
-
writeFileSync(pathToTsConfig, 'test')
|
|
256
|
-
const params = {
|
|
257
|
-
hostname: 'myhost',
|
|
258
|
-
port: 6666,
|
|
259
|
-
typescript: true
|
|
260
|
-
}
|
|
261
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
262
|
-
ok(log.includes(`Typescript configuration file ${pathToTsConfig} found, skipping creation of typescript configuration file.`))
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
test('creates project with plugin already present', async ({ ok }) => {
|
|
266
|
-
const pathToPlugin = join(tmpDir, 'routes', 'root.js')
|
|
267
|
-
mkdirSync(join(tmpDir, 'routes'))
|
|
268
|
-
writeFileSync(pathToPlugin, 'test')
|
|
269
|
-
const params = {
|
|
270
|
-
hostname: 'myhost',
|
|
271
|
-
port: 6666,
|
|
272
|
-
plugin: true,
|
|
273
|
-
types: true
|
|
274
|
-
}
|
|
275
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
276
|
-
ok(log.includes('Routes folder "routes" found, skipping creation of routes folder.'))
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
test('creates project with no default migrations', async ({ notOk }) => {
|
|
280
|
-
const params = {
|
|
281
|
-
hostname: 'myhost',
|
|
282
|
-
port: 6666,
|
|
283
|
-
plugin: false,
|
|
284
|
-
migrations: ''
|
|
285
|
-
}
|
|
286
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
287
|
-
notOk(log.includes('Migrations folder migrations successfully created.'))
|
|
288
|
-
notOk(log.includes('Migration file 001.do.sql successfully created.'))
|
|
289
|
-
notOk(log.includes('Migration file 001.undo.sql successfully created.'))
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
test('creates project with default migrations', async ({ ok }) => {
|
|
293
|
-
const params = {
|
|
294
|
-
hostname: 'myhost',
|
|
295
|
-
port: 6666,
|
|
296
|
-
plugin: false,
|
|
297
|
-
migrations: 'migrations'
|
|
298
|
-
}
|
|
299
|
-
await createDB(params, fakeLogger, tmpDir)
|
|
300
|
-
ok(log.includes('Migrations folder migrations successfully created.'))
|
|
301
|
-
ok(log.includes('Migration file 001.do.sql successfully created.'))
|
|
302
|
-
ok(log.includes('Migration file 001.undo.sql successfully created.'))
|
|
303
|
-
})
|
package/test/exports.test.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { test, beforeEach } from 'tap'
|
|
2
|
-
import { getPkgManager } from '../src/get-pkg-manager.mjs'
|
|
3
|
-
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
delete process.env.npm_config_user_agent
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test('detects npm', async ({ end, equal }) => {
|
|
9
|
-
process.env.npm_config_user_agent = 'npm/7.18.1 node/v16.4.2 darwin x64'
|
|
10
|
-
equal(getPkgManager(), 'npm')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('detects yarn', async ({ end, equal }) => {
|
|
14
|
-
process.env.npm_config_user_agent = 'yarn/1.22.10 npm/? node/v16.4.2 darwin x64'
|
|
15
|
-
equal(getPkgManager(), 'yarn')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('detects pnpm', async ({ end, equal }) => {
|
|
19
|
-
process.env.npm_config_user_agent = 'pnpm/6.14.1 npm/? node/v16.4.2 darwin x64'
|
|
20
|
-
equal(getPkgManager(), 'pnpm')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('detects cnpm', async ({ end, equal }) => {
|
|
24
|
-
process.env.npm_config_user_agent = 'cnpm/7.0.0 npminsall/1.0.0 node/v16.4.2 darwin x64'
|
|
25
|
-
equal(getPkgManager(), 'cnpm')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('defaults to npm if the user agent is unknown', async ({ end, equal }) => {
|
|
29
|
-
process.env.npm_config_user_agent = 'xxxxxxxxxxxxxxxxxx'
|
|
30
|
-
equal(getPkgManager(), 'npm')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
test('defaults to npm if the user agent is not set', async ({ end, equal }) => {
|
|
34
|
-
delete process.env.npm_config_user_agent
|
|
35
|
-
equal(getPkgManager(), 'npm')
|
|
36
|
-
})
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { mkdtemp, rmdir, writeFile, readFile, mkdir } from 'fs/promises'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import { tmpdir } from 'os'
|
|
7
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
8
|
-
import { createDynamicWorkspaceGHAction } from '../src/ghaction.mjs'
|
|
9
|
-
import { parse } from 'yaml'
|
|
10
|
-
|
|
11
|
-
let log = []
|
|
12
|
-
let tmpDir
|
|
13
|
-
const fakeLogger = {
|
|
14
|
-
info: msg => { log.push(msg) },
|
|
15
|
-
warn: msg => { log.push(msg) }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
log = []
|
|
20
|
-
tmpDir = await mkdtemp(join(tmpdir(), 'test-create-platformatic-'))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await rmdir(tmpDir, { recursive: true, force: true })
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const env = {
|
|
28
|
-
DATABASE_URL: 'mydbconnectionstring',
|
|
29
|
-
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test('creates gh action', async ({ equal, match }) => {
|
|
33
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
35
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
36
|
-
equal(accessible, true)
|
|
37
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
38
|
-
const ghAction = parse(ghFile)
|
|
39
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
40
|
-
equal(steps.length, 3)
|
|
41
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
42
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
43
|
-
equal(steps[2].name, 'Deploy project')
|
|
44
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
45
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
46
|
-
|
|
47
|
-
equal(permissions.contents, 'read')
|
|
48
|
-
equal(permissions['pull-requests'], 'write')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
52
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
54
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
55
|
-
equal(accessible, true)
|
|
56
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
57
|
-
const ghAction = parse(ghFile)
|
|
58
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
59
|
-
equal(steps.length, 4)
|
|
60
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
61
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
62
|
-
equal(steps[2].name, 'Build project')
|
|
63
|
-
equal(steps[3].name, 'Deploy project')
|
|
64
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
65
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
66
|
-
|
|
67
|
-
equal(permissions.contents, 'read')
|
|
68
|
-
equal(permissions['pull-requests'], 'write')
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('do not create gitignore file because already present', async ({ end, equal }) => {
|
|
72
|
-
await mkdir(join(tmpDir, '.github', 'workflows'), { recursive: true })
|
|
73
|
-
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')
|
|
74
|
-
await writeFile(ghaction, 'TEST')
|
|
75
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
76
|
-
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
80
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
81
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
82
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
83
|
-
equal(accessible, true)
|
|
84
|
-
const secretsLogLine = log[1].split('\n')
|
|
85
|
-
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_ID: your workspace id')
|
|
86
|
-
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY: your workspace API key')
|
|
87
|
-
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
88
|
-
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
92
|
-
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
93
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
94
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
95
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
96
|
-
equal(accessible, true)
|
|
97
|
-
equal(log.length, 2)
|
|
98
|
-
})
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { mkdtemp, rmdir, writeFile, readFile, mkdir } from 'fs/promises'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import { tmpdir } from 'os'
|
|
7
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
8
|
-
import { createStaticWorkspaceGHAction } from '../src/ghaction.mjs'
|
|
9
|
-
import { parse } from 'yaml'
|
|
10
|
-
|
|
11
|
-
let log = []
|
|
12
|
-
let tmpDir
|
|
13
|
-
const fakeLogger = {
|
|
14
|
-
info: msg => { log.push(msg) },
|
|
15
|
-
warn: msg => { log.push(msg) }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
log = []
|
|
20
|
-
tmpDir = await mkdtemp(join(tmpdir(), 'test-create-platformatic-'))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await rmdir(tmpDir, { recursive: true, force: true })
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const env = {
|
|
28
|
-
DATABASE_URL: 'mydbconnectionstring',
|
|
29
|
-
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test('creates gh action', async ({ equal, match }) => {
|
|
33
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
35
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
36
|
-
equal(accessible, true)
|
|
37
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
38
|
-
const ghAction = parse(ghFile)
|
|
39
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
40
|
-
|
|
41
|
-
equal(steps.length, 3)
|
|
42
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
43
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
44
|
-
equal(steps[2].name, 'Deploy project')
|
|
45
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
46
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
47
|
-
|
|
48
|
-
equal(permissions.contents, 'read')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
52
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
54
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
55
|
-
equal(accessible, true)
|
|
56
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
57
|
-
const ghAction = parse(ghFile)
|
|
58
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
59
|
-
equal(steps.length, 4)
|
|
60
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
61
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
62
|
-
equal(steps[2].name, 'Build project')
|
|
63
|
-
equal(steps[3].name, 'Deploy project')
|
|
64
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
65
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
66
|
-
|
|
67
|
-
equal(permissions.contents, 'read')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('do not create gitignore file because already present', async ({ end, equal }) => {
|
|
71
|
-
await mkdir(join(tmpDir, '.github', 'workflows'), { recursive: true })
|
|
72
|
-
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')
|
|
73
|
-
await writeFile(ghaction, 'TEST')
|
|
74
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
75
|
-
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
79
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
80
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
81
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
82
|
-
equal(accessible, true)
|
|
83
|
-
const secretsLogLine = log[1].split('\n')
|
|
84
|
-
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_ID: your workspace id')
|
|
85
|
-
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_API_KEY: your workspace API key')
|
|
86
|
-
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
87
|
-
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
91
|
-
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
92
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
93
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
94
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
95
|
-
equal(accessible, true)
|
|
96
|
-
equal(log.length, 2)
|
|
97
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import createRuntime from '../../src/runtime/create-runtime.mjs'
|
|
2
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
3
|
-
import { tmpdir } from 'os'
|
|
4
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
|
|
7
|
-
const base = tmpdir()
|
|
8
|
-
let tmpDir
|
|
9
|
-
let log = []
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
log = []
|
|
16
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
17
|
-
process.env = {}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const fakeLogger = {
|
|
21
|
-
debug: msg => log.push(msg),
|
|
22
|
-
info: msg => log.push(msg)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test('creates runtime', async ({ equal, same, ok }) => {
|
|
26
|
-
await createRuntime(fakeLogger, tmpDir, undefined, 'library-app/services', 'foobar')
|
|
27
|
-
|
|
28
|
-
const pathToRuntimeConfigFile = join(tmpDir, 'platformatic.runtime.json')
|
|
29
|
-
const runtimeConfigFile = readFileSync(pathToRuntimeConfigFile, 'utf8')
|
|
30
|
-
const runtimeConfig = JSON.parse(runtimeConfigFile)
|
|
31
|
-
|
|
32
|
-
delete runtimeConfig.$schema
|
|
33
|
-
|
|
34
|
-
same(runtimeConfig, {
|
|
35
|
-
entrypoint: 'foobar',
|
|
36
|
-
allowCycles: false,
|
|
37
|
-
hotReload: true,
|
|
38
|
-
autoload: {
|
|
39
|
-
path: 'library-app/services',
|
|
40
|
-
exclude: ['docs']
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('with a full path for autoload', async ({ equal, same, ok }) => {
|
|
46
|
-
await createRuntime(fakeLogger, tmpDir, undefined, join(tmpDir, 'services'), 'foobar')
|
|
47
|
-
|
|
48
|
-
const pathToRuntimeConfigFile = join(tmpDir, 'platformatic.runtime.json')
|
|
49
|
-
const runtimeConfigFile = readFileSync(pathToRuntimeConfigFile, 'utf8')
|
|
50
|
-
const runtimeConfig = JSON.parse(runtimeConfigFile)
|
|
51
|
-
|
|
52
|
-
delete runtimeConfig.$schema
|
|
53
|
-
|
|
54
|
-
same(runtimeConfig, {
|
|
55
|
-
entrypoint: 'foobar',
|
|
56
|
-
allowCycles: false,
|
|
57
|
-
hotReload: true,
|
|
58
|
-
autoload: {
|
|
59
|
-
path: 'services',
|
|
60
|
-
exclude: ['docs']
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
66
|
-
const pathToRuntimeConfigFileOld = join(tmpDir, 'platformatic.runtime.json')
|
|
67
|
-
writeFileSync(pathToRuntimeConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
68
|
-
await createRuntime(fakeLogger, tmpDir, 'foobar')
|
|
69
|
-
ok(log.includes('Configuration file platformatic.runtime.json found, skipping creation of configuration file.'))
|
|
70
|
-
})
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import createService from '../../src/service/create-service.mjs'
|
|
2
|
-
import { isFileAccessible } from '../../src/utils.mjs'
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { tmpdir } from 'os'
|
|
5
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
import dotenv from 'dotenv'
|
|
8
|
-
import Ajv from 'ajv'
|
|
9
|
-
import { schema } from '@platformatic/service'
|
|
10
|
-
|
|
11
|
-
const base = tmpdir()
|
|
12
|
-
let tmpDir
|
|
13
|
-
let log = []
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
log = []
|
|
20
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
21
|
-
process.env = {}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const fakeLogger = {
|
|
25
|
-
debug: msg => log.push(msg),
|
|
26
|
-
info: msg => log.push(msg)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test('creates service with typescript', async ({ equal, same, ok }) => {
|
|
30
|
-
const params = {
|
|
31
|
-
hostname: 'myhost',
|
|
32
|
-
port: 6666,
|
|
33
|
-
typescript: true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await createService(params, fakeLogger, tmpDir)
|
|
37
|
-
|
|
38
|
-
const pathToServiceConfigFile = join(tmpDir, 'platformatic.service.json')
|
|
39
|
-
const serviceConfigFile = readFileSync(pathToServiceConfigFile, 'utf8')
|
|
40
|
-
const serviceConfig = JSON.parse(serviceConfigFile)
|
|
41
|
-
const ajv = new Ajv()
|
|
42
|
-
ajv.addKeyword('resolvePath')
|
|
43
|
-
const validate = ajv.compile(schema.schema)
|
|
44
|
-
const isValid = validate(serviceConfig)
|
|
45
|
-
equal(isValid, true)
|
|
46
|
-
const { server, plugins } = serviceConfig
|
|
47
|
-
|
|
48
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
49
|
-
equal(server.port, '{PORT}')
|
|
50
|
-
|
|
51
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
52
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
53
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
54
|
-
equal(process.env.PORT, '6666')
|
|
55
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
56
|
-
|
|
57
|
-
process.env = {}
|
|
58
|
-
|
|
59
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
60
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
61
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
62
|
-
equal(process.env.PORT, '6666')
|
|
63
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
64
|
-
|
|
65
|
-
same(plugins.paths, [{ path: './plugins', encapsulate: false }, './routes'])
|
|
66
|
-
equal(plugins.typescript, '{PLT_TYPESCRIPT}')
|
|
67
|
-
|
|
68
|
-
ok(await isFileAccessible(join(tmpDir, 'tsconfig.json')))
|
|
69
|
-
ok(await isFileAccessible(join(tmpDir, 'plugins', 'example.ts')))
|
|
70
|
-
ok(await isFileAccessible(join(tmpDir, 'routes', 'root.ts')))
|
|
71
|
-
|
|
72
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'plugins', 'example.test.ts')))
|
|
73
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'routes', 'root.test.ts')))
|
|
74
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'helper.ts')))
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
test('creates service with javascript', async ({ equal, same, ok }) => {
|
|
78
|
-
const params = {
|
|
79
|
-
hostname: 'myhost',
|
|
80
|
-
port: 6666,
|
|
81
|
-
typescript: false
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
await createService(params, fakeLogger, tmpDir)
|
|
85
|
-
|
|
86
|
-
const pathToServiceConfigFile = join(tmpDir, 'platformatic.service.json')
|
|
87
|
-
const serviceConfigFile = readFileSync(pathToServiceConfigFile, 'utf8')
|
|
88
|
-
const serviceConfig = JSON.parse(serviceConfigFile)
|
|
89
|
-
const { server, plugins } = serviceConfig
|
|
90
|
-
|
|
91
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
92
|
-
equal(server.port, '{PORT}')
|
|
93
|
-
|
|
94
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
95
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
96
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
97
|
-
equal(process.env.PORT, '6666')
|
|
98
|
-
process.env = {}
|
|
99
|
-
|
|
100
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
101
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
102
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
103
|
-
equal(process.env.PORT, '6666')
|
|
104
|
-
|
|
105
|
-
same(plugins, { paths: [{ path: './plugins', encapsulate: false }, './routes'] })
|
|
106
|
-
ok(await isFileAccessible(join(tmpDir, 'plugins', 'example.js')))
|
|
107
|
-
ok(await isFileAccessible(join(tmpDir, 'routes', 'root.js')))
|
|
108
|
-
|
|
109
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'plugins', 'example.test.js')))
|
|
110
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'routes', 'root.test.js')))
|
|
111
|
-
ok(await isFileAccessible(join(tmpDir, 'test', 'helper.js')))
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
115
|
-
const pathToServiceConfigFileOld = join(tmpDir, 'platformatic.service.json')
|
|
116
|
-
writeFileSync(pathToServiceConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
117
|
-
const params = {
|
|
118
|
-
hostname: 'myhost',
|
|
119
|
-
port: 6666
|
|
120
|
-
}
|
|
121
|
-
await createService(params, fakeLogger, tmpDir)
|
|
122
|
-
ok(log.includes('Configuration file platformatic.service.json found, skipping creation of configuration file.'))
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
test('creates project with tsconfig already present', async ({ ok }) => {
|
|
126
|
-
const pathToTsConfig = join(tmpDir, 'tsconfig.json')
|
|
127
|
-
writeFileSync(pathToTsConfig, 'test')
|
|
128
|
-
const params = {
|
|
129
|
-
hostname: 'myhost',
|
|
130
|
-
port: 6666,
|
|
131
|
-
typescript: true
|
|
132
|
-
}
|
|
133
|
-
await createService(params, fakeLogger, tmpDir)
|
|
134
|
-
ok(log.includes(`Typescript configuration file ${pathToTsConfig} found, skipping creation of typescript configuration file.`))
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test('creates project with plugins already present', async ({ ok }) => {
|
|
138
|
-
const pathToPlugins = join(tmpDir, 'plugins')
|
|
139
|
-
mkdirSync(pathToPlugins)
|
|
140
|
-
const params = {
|
|
141
|
-
hostname: 'myhost'
|
|
142
|
-
}
|
|
143
|
-
await createService(params, fakeLogger, tmpDir)
|
|
144
|
-
ok(log.includes('Plugins folder "plugins" found, skipping creation of plugins folder.'))
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
test('creates project with routes already present', async ({ ok }) => {
|
|
148
|
-
const pathToPlugins = join(tmpDir, 'routes')
|
|
149
|
-
mkdirSync(pathToPlugins)
|
|
150
|
-
const params = {
|
|
151
|
-
hostname: 'myhost'
|
|
152
|
-
}
|
|
153
|
-
await createService(params, fakeLogger, tmpDir)
|
|
154
|
-
ok(log.includes('Routes folder "routes" found, skipping creation of routes folder.'))
|
|
155
|
-
})
|
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
|
-
})
|