Skip to content

Commit 9fa2dde

Browse files
committed
feat: addl build testing -d
1 parent ac1911b commit 9fa2dde

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

.fiction/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export interface CompiledServiceConfig {
77
commands: 'bundle' | 'release' | 'render'
88
vars:
9+
| 'APOLLO_API_KEY'
910
| 'AWS_ACCESS_KEY'
1011
| 'AWS_ACCESS_KEY_SECRET'
1112
| 'AWS_BUCKET_MEDIA'

@fiction/analytics/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FictionBeacon } from './plugin-beacon'
77
vars.register(() => [new EnvVar({ name: 'CLICKHOUSE_URL' })])
88

99
type FictionAnalyticsSettings = {
10-
clickhouseUrl?: string
10+
clickhouseUrl: string
1111
fictionServer: FictionServer
1212
fictionUser?: FictionUser
1313
fictionCache: FictionCache
@@ -21,11 +21,7 @@ export class FictionAnalytics extends FictionPlugin<FictionAnalyticsSettings> {
2121
super('FictionAnalytics', { root: safeDirname(import.meta.url), ...settings })
2222

2323
this.fictionClickhouse = new FictionClickHouse({ fictionAnalytics: this, ...this.settings })
24-
this.fictionBeacon = new FictionBeacon({
25-
fictionAnalytics: this,
26-
fictionClickHouse: this.fictionClickhouse,
27-
...this.settings,
28-
})
24+
this.fictionBeacon = new FictionBeacon({ fictionAnalytics: this, fictionClickHouse: this.fictionClickhouse, ...this.settings })
2925
}
3026

3127
async close() {

@fiction/analytics/plugin-clickhouse/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export * from './types.js'
1616
vars.register(() => [new EnvVar({ name: 'CLICKHOUSE_URL' })])
1717

1818
type FictionClickHouseSettings = {
19-
clickhouseUrl?: string
19+
clickhouseUrl: string
2020
fictionServer: FictionServer
2121
fictionUser?: FictionUser
2222
fictionAnalytics?: FictionAnalytics
@@ -54,16 +54,21 @@ export class FictionClickHouse extends FictionPlugin<FictionClickHouseSettings>
5454
constructor(settings: FictionClickHouseSettings) {
5555
super('clickhouse', settings)
5656

57-
if (settings.clickhouseUrl)
57+
if (!settings.clickhouseUrl && !this.fictionEnv.isApp.value) {
58+
throw new Error('no clickhouse connection url')
59+
}
60+
else if (settings.clickhouseUrl) {
5861
this.connectionUrl = new URL(settings.clickhouseUrl)
62+
}
5963
}
6064

6165
async close() {
6266
// close the connection
67+
await this.db.destroy()
6368
}
6469

6570
async init() {
66-
if (!isNode())
71+
if (this.fictionEnv.isApp.value)
6772
return
6873

6974
if (!this.connectionUrl)

@fiction/core/plugin-env/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path'
22
import dotenv from 'dotenv'
33
import { FictionObject } from '../plugin.js'
44
import type { HookType, UserNotification } from '../utils/index.js'
5-
import { camelToUpperSnake, crossVar, isApp, isCi, isDev, isNode, isTest, onResetUi, resetUi, runHooks, runHooksSync, shortId, toSlug, vue } from '../utils/index.js'
5+
import { camelToUpperSnake, crossVar, isApp, isCi, isDev, isNode, isTest, onResetUi, resetUi, runHooks, runHooksSync, shortId, toSlug, vue, waitFor } from '../utils/index.js'
66
import { version as fictionVersion } from '../package.json'
77
import type { RunVars } from '../inject.js'
88
import { TypedEventTarget } from '../utils/eventTarget.js'
@@ -417,7 +417,8 @@ export class FictionEnv<
417417

418418
if (cliCommand.options.exit) {
419419
const reason = `--exit flag set`
420-
this.log.info(`shutting down`, { data: { reason } })
420+
this.log.warn(`shutting down`, { data: { reason } })
421+
await waitFor(1000)
421422
this.events.emit('shutdown', { reason })
422423
}
423424
}

@fiction/core/test-utils/buildTest.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ export async function appBuildTests(config: { moduleName?: string, cwd?: string,
301301

302302
const logger = log.contextLogger('UIUX')
303303
const BUILD_TIMEOUT = 180_000
304-
const { portOptions } = getModifiedCommands(config.commands)
304+
const { portOptions, commands } = getModifiedCommands(config.commands)
305305

306-
const checkRunCommand = async (runCommand: string) => {
306+
const checkRunCommand = async (runCommand: string, opts: { portCommand?: string } = {}) => {
307+
const { portCommand = '' } = opts
307308
const command = [`npm -w ${moduleName} exec -- fiction run ${runCommand} --exit`, ...portOptions].join(' ')
308309

309310
try {
@@ -312,6 +313,23 @@ export async function appBuildTests(config: { moduleName?: string, cwd?: string,
312313
envVars: { IS_TEST: '1', TEST_ENV: 'unit' },
313314
timeout: BUILD_TIMEOUT,
314315
resolveText: '[ready]',
316+
beforeResolve: async () => {
317+
const url = commands.find(_ => _.command === runCommand || (portCommand && _.command === portCommand))?.url.value
318+
try {
319+
logger.info(`RUN CHECK START`, { data: { command, url } })
320+
321+
if (!url)
322+
throw new Error('no url')
323+
324+
await fetch(url)
325+
326+
logger.info('RUN CHECK DONE', { data: { url } })
327+
}
328+
catch (error) {
329+
logger.error('FETCH PROBLEM', { error, data: { commands, runCommand, url } })
330+
throw error
331+
}
332+
},
315333
})
316334

317335
expect(r.stdout).toContain('[ready]')
@@ -346,7 +364,7 @@ export async function appBuildTests(config: { moduleName?: string, cwd?: string,
346364
}, BUILD_TIMEOUT)
347365

348366
it(`RUNS DEV: ${moduleName}`, async () => {
349-
await checkRunCommand('dev')
367+
await checkRunCommand('dev', { portCommand: 'app' })
350368
}, BUILD_TIMEOUT)
351369

352370
it(`LOADS WITHOUT ERROR: ${moduleName}`, async () => {

@fiction/core/utils/nodeUtils.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { PackageJson } from '../types'
1111
import { log } from '../plugin-log'
1212
import { isNode } from './vars'
1313
import { formatBytes } from './number'
14+
import { waitFor } from './utils.js'
1415

1516
interface WhichModule {
1617
moduleName?: string
@@ -42,6 +43,7 @@ export async function executeCommand(args: {
4243
envVars?: { [key: string]: string }
4344
timeout?: number
4445
resolveText?: string
46+
beforeResolve?: () => Promise<void>
4547
triggerText?: string
4648
onTrigger?: (args: { stdout: string, stderr: string, text: string, close: () => void, cp: ResultPromise }) => Promise<void> | void
4749
}) {
@@ -68,23 +70,34 @@ export async function executeCommand(args: {
6870
resolve(1)
6971
}
7072

71-
const onText = (text: string) => {
72-
if (resolveText && text.includes(resolveText))
73+
const onText = async (text: string) => {
74+
if (resolveText && text.includes(resolveText)) {
75+
if (args.beforeResolve) {
76+
try {
77+
await args.beforeResolve()
78+
await waitFor(1000)
79+
}
80+
catch (error) {
81+
reject(error)
82+
}
83+
}
84+
7385
resolve(text)
86+
}
7487
// close()
7588

7689
if (args.triggerText && text.includes(args.triggerText) && args.onTrigger)
7790
void args.onTrigger({ ...commandDetails(), text, close, cp })
7891
}
7992

80-
cp.stdout?.on('data', (d: Buffer) => {
93+
cp.stdout?.on('data', async (d: Buffer) => {
8194
output.push(d.toString())
82-
onText(d.toString())
95+
await onText(d.toString())
8396
})
8497

8598
cp.stderr?.on('data', async (d: Buffer) => {
8699
errorsOutput.push(d.toString())
87-
onText(d.toString())
100+
await onText(d.toString())
88101
})
89102

90103
void cp.on('close', (code) => {

0 commit comments

Comments
 (0)