-
-
Notifications
You must be signed in to change notification settings - Fork 796
Expand file tree
/
Copy pathgenerators.test.ts
More file actions
152 lines (135 loc) · 4.74 KB
/
generators.test.ts
File metadata and controls
152 lines (135 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* eslint-disable @typescript-eslint/prefer-for-of */
import os from 'os'
import path from 'path'
import { mkdtemp } from 'fs/promises'
import assert from 'assert'
import { getContext } from '@feathershq/pinion'
import { AppGeneratorContext } from '../src/app'
import { FeathersBaseContext } from '../src/commons'
import { ConnectionGeneratorArguments } from '../src/connection'
import { ServiceGeneratorArguments } from '../src/service'
import { combinate, dependencyVersions } from './utils'
import { generate as generateApp } from '../lib/app'
import { generate as generateConnection } from '../lib/connection'
import { generate as generateService } from '../lib/service'
import { listAllFiles } from '@feathershq/pinion/lib/utils'
const matrix = {
language: ['js', 'ts'] as const,
framework: ['koa', 'express'] as const
}
const defaultCombination = {
language: process.env.FEATHERS_LANGUAGE || 'ts',
framework: process.env.FEATHERS_FRAMEWORK || 'koa'
}
const combinations =
process.version > 'v16.0.0' ? (process.env.CI ? combinate(matrix as any) : [defaultCombination]) : []
describe('@feathersjs/cli', () => {
for (const { language, framework } of combinations) {
describe(`${language} ${framework} app`, () => {
const name = `feathers_${language}_${framework}`
let context: FeathersBaseContext
let cwd: string
before(async () => {
cwd = await mkdtemp(path.join(os.tmpdir(), name + '-'))
console.log(`\nGenerating test application to\n${cwd}\n\n`)
try {
context = await generateApp(
getContext<AppGeneratorContext>(
{
name,
framework,
language,
dependencyVersions,
lib: 'src',
description: 'A Feathers test app',
packager: 'npm',
database: 'sqlite',
connectionString: `${name}.sqlite`,
transports: ['rest', 'websockets'],
authStrategies: ['local', 'github'],
schema: 'typebox'
},
{ cwd }
)
)
} catch (error: any) {
console.error(error.stack)
console.error((await listAllFiles(cwd)).join('\n'))
throw error
}
})
it('generated app with SQLite and passes tests', async () => {
const testResult = await context.pinion.exec('npm', ['test'], { cwd })
assert.ok(context)
assert.strictEqual(testResult, 0)
})
it('generates a MongoDB connection and service and passes tests', async () => {
const connectionContext = await generateConnection(
getContext<ConnectionGeneratorArguments>(
{
dependencyVersions,
database: 'mongodb' as const,
connectionString: `mongodb://127.0.0.1:27017/${name}`
},
{ cwd }
)
)
const mongoService1Context = await generateService(
getContext<ServiceGeneratorArguments>(
{
dependencyVersions,
name: 'testing',
path: 'path/to/test',
authentication: true,
type: 'mongodb',
schema: false
},
{ cwd }
)
)
const messageServiceContext = await generateService(
getContext<ServiceGeneratorArguments>(
{
dependencyVersions,
name: 'message',
path: 'messages',
authentication: true,
type: 'mongodb',
schema: 'typebox'
},
{ cwd }
)
)
const testResult = await context.pinion.exec('npm', ['test'], { cwd })
assert.ok(connectionContext)
assert.ok(mongoService1Context)
assert.ok(messageServiceContext)
assert.strictEqual(testResult, 0)
})
it('generates a custom service and passes tests', async () => {
const customServiceContext = await generateService(
getContext<ServiceGeneratorArguments>(
{
dependencyVersions,
name: 'Custom',
path: 'customized',
authentication: false,
type: 'custom',
schema: 'json'
},
{ cwd }
)
)
const testResult = await context.pinion.exec('npm', ['test'], { cwd })
assert.ok(customServiceContext)
assert.strictEqual(testResult, 0)
})
it('compiles successfully', async () => {
if (language === 'ts' && framework === 'koa') {
const testResult = await context.pinion.exec('npm', ['run', 'compile'], { cwd })
assert.strictEqual(testResult, 0)
}
})
})
}
})