-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7aaef2
commit 3b0c0cc
Showing
18 changed files
with
240 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@powership/boilerplate", | ||
"version": "3.3.7", | ||
"version": "3.3.9", | ||
"author": "antoniopresto <[email protected]>", | ||
"sideEffects": false, | ||
"type": "module", | ||
|
@@ -61,7 +61,7 @@ | |
"ts-jest": "*", | ||
"typedoc": "*", | ||
"typescript": "*", | ||
"@powership/babel-plugins": "3.3.7", | ||
"@powership/babel-plugins": "3.3.9", | ||
"@babel/preset-typescript": "*", | ||
"@babel/preset-env": "*", | ||
"@babel/plugin-transform-typescript": "*", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "logstorm", | ||
"version": "3.3.7", | ||
"version": "3.3.9", | ||
"typings": "out", | ||
"author": "antoniopresto <[email protected]>", | ||
"type": "module", | ||
|
@@ -124,6 +124,6 @@ | |
"tsx": "*", | ||
"ulid": "*", | ||
"url-pattern": "*", | ||
"@powership/utils": "3.3.7" | ||
"@powership/utils": "3.3.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "powership", | ||
"version": "3.3.7", | ||
"version": "3.3.9", | ||
"author": "antoniopresto <[email protected]>", | ||
"type": "module", | ||
"main": "./out/index.cjs", | ||
|
@@ -105,11 +105,11 @@ | |
"tsconfig": "./tsconfig.module.json" | ||
}, | ||
"peerDependencies": { | ||
"@powership/utils": "3.3.7", | ||
"@powership/schema": "3.3.7", | ||
"@powership/entity": "3.3.7", | ||
"@powership/utils": "3.3.9", | ||
"@powership/schema": "3.3.9", | ||
"@powership/entity": "3.3.9", | ||
"highlight.js": "*", | ||
"@powership/transporter": "3.3.7", | ||
"@powership/transporter": "3.3.9", | ||
"dataloader": "*", | ||
"plugin-hooks": "*", | ||
"sift": "*", | ||
|
@@ -152,12 +152,12 @@ | |
"tsx": "*", | ||
"ulid": "*", | ||
"url-pattern": "*", | ||
"plugin-engine": "3.3.7", | ||
"plugin-engine": "3.3.9", | ||
"body-parser": "*", | ||
"graphql-playground-html": "*", | ||
"http-errors": "*", | ||
"http-status-codes": "*", | ||
"logstorm": "3.3.7", | ||
"@powership/server": "3.3.7" | ||
"logstorm": "3.3.9", | ||
"@powership/server": "3.3.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "runmate", | ||
"version": "3.3.7", | ||
"version": "3.3.9", | ||
"typings": "out", | ||
"author": "antoniopresto <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -141,8 +141,8 @@ | |
"ts-toolbelt": "*", | ||
"ulid": "*", | ||
"url-pattern": "*", | ||
"@powership/utils": "3.3.7", | ||
"logstorm": "3.3.7", | ||
"@powership/utils": "3.3.9", | ||
"logstorm": "3.3.9", | ||
"@types/vorpal": "*", | ||
"@types/glob": "*" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@powership/utils", | ||
"version": "3.3.7", | ||
"version": "3.3.9", | ||
"typings": "out", | ||
"author": "antoniopresto <[email protected]>", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,3 +103,4 @@ export * from './parsePhoneNumber'; | |
export { TU }; | ||
|
||
export * from './hey'; | ||
export * from './watchable'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { watchable } from './watchable'; | ||
|
||
describe('watchable', () => { | ||
test('should delay execution until accessed', async () => { | ||
let executed = false; | ||
const watchableFunction = watchable(() => { | ||
executed = true; | ||
return { message: 'Hello World' }; | ||
}); | ||
|
||
expect(executed).toBe(false); | ||
|
||
expect(watchableFunction.message).toBe('Hello World'); | ||
expect(executed).toBe(true); | ||
}); | ||
|
||
test('should handle promise results properly', async () => { | ||
const asyncFunction = watchable( | ||
() => | ||
new Promise<{ message: string }>((resolve) => | ||
setTimeout(() => resolve({ message: 'Async Hello World' }), 100) | ||
) | ||
); | ||
|
||
expect(asyncFunction.then).toBeDefined(); | ||
const data = await asyncFunction; | ||
expect(data.message).toBe('Async Hello World'); | ||
}); | ||
|
||
test('should allow access to the current value', () => { | ||
const watchableFunction = watchable(() => { | ||
return { message: 'Current Value' }; | ||
}); | ||
|
||
// before access | ||
expect(watchableFunction.current()).toBeUndefined(); | ||
|
||
// force run | ||
expect(watchableFunction.message).toBe('Current Value'); | ||
|
||
// after access | ||
expect(watchableFunction.current()).toEqual({ message: 'Current Value' }); | ||
}); | ||
|
||
test('should throw if trying to access rejected promise', async () => { | ||
const failingFunction = watchable( | ||
() => | ||
new Promise((_, reject) => | ||
setTimeout(() => reject(new Error('Failed')), 100) | ||
) | ||
); | ||
|
||
let err: any = undefined; | ||
try { | ||
await failingFunction; | ||
} catch (error: any) { | ||
err = error; | ||
} | ||
|
||
expect(err).toBeInstanceOf(Error); | ||
expect(err.message).toBe('Failed'); | ||
}); | ||
|
||
test('should resolve subscribers in the order they were added', async () => { | ||
const asyncFunction = watchable( | ||
() => | ||
new Promise((resolve) => | ||
setTimeout(() => resolve({ value: 'Ordered' }), 100) | ||
) | ||
); | ||
|
||
const results: string[] = []; | ||
|
||
asyncFunction.then(() => results.push('first')); | ||
asyncFunction.then(() => results.push('second')); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 200)); // Espera a resolução | ||
|
||
expect(results).toEqual(['first', 'second']); | ||
|
||
expect(await asyncFunction).toEqual({ | ||
value: 'Ordered', | ||
}); | ||
|
||
expect(await asyncFunction).toEqual({ | ||
value: 'Ordered', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.