Skip to content

Commit ed7977d

Browse files
committed
chore: wip
1 parent 4f2cae3 commit ed7977d

File tree

9 files changed

+123
-39
lines changed

9 files changed

+123
-39
lines changed

storage/framework/core/actions/src/test.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { runCommand } from '@stacksjs/cli'
2-
import { NpmScript } from '@stacksjs/enums'
3-
import { frameworkPath } from '@stacksjs/path'
1+
import { log } from '@stacksjs/cli'
2+
import { projectPath } from '@stacksjs/path'
43

5-
await runCommand(NpmScript.TestFeature, {
6-
verbose: true,
7-
cwd: frameworkPath(),
4+
const process = Bun.spawn(['sh', '-c', 'bun test ./tests/feature/**'], {
5+
cwd: projectPath(),
6+
stdio: ['inherit', 'inherit', 'inherit'], // Inherit stdio to see the output in the console
7+
// env: process.env, // Pass the environment variables
88
})
9+
10+
const exitCode = await process.exited
11+
12+
if (exitCode !== 0) {
13+
log.error('Tests failed')
14+
process.exit(exitCode)
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { log } from '@stacksjs/cli'
2+
import { projectPath } from '@stacksjs/path'
3+
4+
const process = Bun.spawn(['sh', '-c', 'bun test ./tests/feature/** ./tests/unit/**'], {
5+
cwd: projectPath(),
6+
stdio: ['inherit', 'inherit', 'inherit'], // Inherit stdio to see the output in the console
7+
// env: process.env, // Pass the environment variables
8+
})
9+
10+
const exitCode = await process.exited
11+
12+
if (exitCode !== 0) {
13+
log.error('Tests failed')
14+
process.exit(exitCode)
15+
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import { runCommand } from '@stacksjs/cli'
2-
import { NpmScript } from '@stacksjs/enums'
3-
import { frameworkPath } from '@stacksjs/path'
1+
import { log } from '@stacksjs/cli'
2+
import { projectPath } from '@stacksjs/path'
43

5-
await runCommand(NpmScript.TestUnit, { verbose: true, cwd: frameworkPath() })
4+
const process = Bun.spawn(['sh', '-c', 'bun test ./tests/unit/**'], {
5+
cwd: projectPath(),
6+
stdio: ['inherit', 'inherit', 'inherit'], // Inherit stdio to see the output in the console
7+
// env: process.env, // Pass the environment variables
8+
})
9+
10+
const exitCode = await process.exited
11+
12+
if (exitCode !== 0) {
13+
log.error('Tests failed')
14+
process.exit(exitCode)
15+
}

storage/framework/core/buddy/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import * as cmd from './commands'
1010

1111
// setup global error handlers
1212
process.on('uncaughtException', (error: Error) => {
13-
log.debug('uncaughtException')
13+
log.debug('Buddy uncaughtException')
1414
log.error(error)
1515
process.exit(1)
1616
})
1717

1818
process.on('unhandledRejection', (error: Error) => {
19-
log.debug('unhandledRejection', error)
19+
log.debug('Buddy unhandledRejection')
2020
log.error(error)
2121
process.exit(1)
2222
})

storage/framework/core/buddy/src/commands/test.ts

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process'
22
import { runAction } from '@stacksjs/actions'
3-
import { intro, outro } from '@stacksjs/cli'
3+
import { intro, log, outro } from '@stacksjs/cli'
44
import { Action } from '@stacksjs/enums'
55
import { projectPath } from '@stacksjs/path'
66
import type { CLI, TestOptions } from '@stacksjs/types'
@@ -22,23 +22,78 @@ export function test(buddy: CLI) {
2222
.command('test', descriptions.command)
2323
.option('-f, --feature', descriptions.feature, { default: false })
2424
.option('-u, --unit', descriptions.unit, { default: false })
25-
.option('--ui', descriptions.ui, { default: false })
25+
// .option('--ui', descriptions.ui, { default: false })
2626
.option('-p, --project [project]', descriptions.project, { default: false })
2727
.option('--verbose', descriptions.verbose, { default: true })
2828
.action(async (options: TestOptions) => {
2929
const perf = await intro('buddy test')
30-
const result = await runAction(Action.Test, {
31-
...options,
32-
cwd: projectPath(),
33-
})
3430

35-
if (result.isErr()) {
36-
await outro(
37-
'While running `buddy test`, there was an issue',
38-
{ startTime: perf, useSeconds: true },
39-
result.error,
40-
)
41-
process.exit()
31+
if (options.feature && options.unit) {
32+
const result = await runAction(Action.Test, {
33+
...options,
34+
cwd: projectPath(),
35+
})
36+
37+
if (result.isErr()) {
38+
await outro(
39+
'While running `buddy test`, there was an issue',
40+
{ startTime: perf, useSeconds: true },
41+
result.error,
42+
)
43+
process.exit()
44+
}
45+
}
46+
47+
if (options.feature && !options.unit) {
48+
log.info('Running Feature tests...')
49+
50+
const result = await runAction(Action.TestFeature, {
51+
...options,
52+
cwd: projectPath(),
53+
})
54+
55+
if (result.isErr()) {
56+
await outro(
57+
'While running `buddy test`, there was an issue',
58+
{ startTime: perf, useSeconds: true },
59+
result.error,
60+
)
61+
process.exit()
62+
}
63+
}
64+
65+
if (!options.feature && options.unit) {
66+
log.info('Running Unit tests...')
67+
68+
const result = await runAction(Action.TestUnit, {
69+
...options,
70+
cwd: projectPath(),
71+
})
72+
73+
if (result.isErr()) {
74+
await outro(
75+
'While running `buddy test`, there was an issue',
76+
{ startTime: perf, useSeconds: true },
77+
result.error,
78+
)
79+
process.exit()
80+
}
81+
}
82+
83+
if (!options.feature && !options.unit) {
84+
const result = await runAction(Action.Test, {
85+
...options,
86+
cwd: projectPath(),
87+
})
88+
89+
if (result.isErr()) {
90+
await outro(
91+
'While running `buddy test`, there was an issue',
92+
{ startTime: perf, useSeconds: true },
93+
result.error,
94+
)
95+
process.exit()
96+
}
4297
}
4398

4499
await outro('Finished running tests', {

storage/framework/core/enums/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export enum Action {
8585
Prepublish = 'prepublish',
8686
Release = 'release', // ✅
8787
RouteList = 'route/list', // ✅
88-
Test = 'test',
89-
TestUi = 'test-ui',
90-
TestUnit = 'test-unit',
91-
TestFeature = 'test-feature',
88+
Test = 'test/index',
89+
TestUi = 'test/ui',
90+
TestUnit = 'test/unit',
91+
TestFeature = 'test/feature',
9292
Typecheck = 'typecheck',
9393
Upgrade = 'upgrade/index',
9494
UpgradeBinary = 'upgrade/binary', // the `stacks` binary

storage/framework/core/error-handling/src/handler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class ErrorHandler {
1616
if (options?.silent !== false) this.writeErrorToConsole(err)
1717

1818
if (typeof err === 'string') err = new StacksError(err)
19+
if (typeof err === 'object') err = err as Error
1920

2021
this.writeErrorToFile(err).catch((e) => console.error(e))
2122

@@ -50,10 +51,12 @@ export class ErrorHandler {
5051
if (
5152
err === 'Failed to execute command: bunx biome check --fix' ||
5253
err === 'Failed to execute command: bun --bun storage/framework/core/actions/src/lint/fix.ts'
53-
)
54+
) {
5455
// To trigger this, run `buddy release` with a lint error in your codebase
5556
console.error(err)
56-
process.exit(ExitCode.FatalError) // TODO: abstract this by differently catching the error somewhere
57+
process.exit(ExitCode.FatalError) // TODO: abstract this by differently catching the error somewhere
58+
}
59+
5760
console.error(err)
5861
}
5962
}

storage/framework/core/logging/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function writeToLogFile(message: string) {
6969
export interface Log {
7070
info: (...args: any[]) => void
7171
success: (msg: string) => void
72-
error: (err: string | Error | unknown, options?: any | Error) => void
72+
error: (err: string | Error | object | unknown, options?: any | Error) => void
7373
warn: (arg: string) => void
7474
warning: (arg: string) => void
7575
debug: (...args: any[]) => void
@@ -112,10 +112,10 @@ export const log: Log = {
112112
error: (err: unknown, options?: any | Error) => {
113113
if (err instanceof Error) handleError(err, options)
114114
else if (err instanceof Error) handleError(options)
115+
else if (err instanceof Object) handleError(options)
115116
else handleError(err, options)
116117

117118
const errorMessage = isString(err) ? err : err instanceof Error ? err.message : String(err)
118-
logger.error(errorMessage)
119119
writeToLogFile(`ERROR: ${errorMessage}`)
120120
},
121121

0 commit comments

Comments
 (0)