Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed May 31, 2024
1 parent a63f5dd commit 8b3ecce
Show file tree
Hide file tree
Showing 12 changed files with 720 additions and 28 deletions.
5 changes: 4 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"complexity": {
"noBannedTypes": "off"
}
}
},
"javascript": {
Expand Down
111 changes: 110 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/instances/defineInstance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ test('default', async () => {
const foo = defineInstance(() => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start() {
started = true
},
Expand All @@ -29,6 +31,8 @@ test('behavior: parameters', async () => {
const foo = defineInstance((parameters: { bar: string }) => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start() {
started = [true, parameters]
},
Expand All @@ -52,6 +56,8 @@ test('behavior: start', async () => {
const foo = defineInstance(() => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start() {
count++
},
Expand Down Expand Up @@ -89,6 +95,8 @@ test('behavior: stop', async () => {
const foo = defineInstance(() => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start() {},
async stop() {
count++
Expand Down Expand Up @@ -123,6 +131,8 @@ test('options: timeout', async () => {
const foo = defineInstance(() => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start() {
await new Promise((resolve) => setTimeout(resolve, 200))
},
Expand All @@ -138,6 +148,8 @@ test('options: timeout', async () => {
const bar = defineInstance(() => {
return {
name: 'bar',
host: 'localhost',
port: 3000,
async start() {},
async stop() {
await new Promise((resolve) => setTimeout(resolve, 200))
Expand All @@ -151,3 +163,21 @@ test('options: timeout', async () => {
'Instance "bar" failed to stop in time',
)
})

test('behavior: events', async () => {
const foo = defineInstance(() => {
return {
name: 'foo',
host: 'localhost',
port: 3000,
async start({ emitter }) {
emitter.emit('message', 'hello')
},
async stop() {
emitter.emit('message', 'goodbye')
},
}
})

const instance = foo()
})
Loading

0 comments on commit 8b3ecce

Please sign in to comment.