Skip to content

Commit 59ba47c

Browse files
committed
refactor: event system
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 61d3fb2 commit 59ba47c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+644
-215
lines changed

.attw.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"color": true,
33
"emoji": true,
44
"format": "ascii",
5-
"ignoreRules": ["cjs-resolves-to-esm", "internal-resolution-error"],
5+
"ignoreRules": [
6+
"cjs-resolves-to-esm",
7+
"internal-resolution-error",
8+
"no-resolution"
9+
],
610
"summary": true
711
}

.commitlintrc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const config: UserConfig = {
1818
'scope-enum': [RuleConfigSeverity.Error, 'always', scopes([
1919
'chore',
2020
'constructs',
21-
'errors'
21+
'errors',
22+
'events'
2223
])]
2324
}
2425
}

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@
4343
"kronk": "./src/index.mts",
4444
"default": "./dist/index.mjs"
4545
},
46-
"./package.json": "./package.json"
46+
"./errors": {
47+
"kronk": "./src/errors/index.mts",
48+
"default": "./dist/errors/index.mjs"
49+
},
50+
"./events": {
51+
"kronk": "./src/events/index.mts",
52+
"default": "./dist/events/index.mjs"
53+
},
54+
"./package.json": "./package.json",
55+
"./utils": {
56+
"kronk": "./src/utils/index.mts",
57+
"default": "./dist/utils/index.mjs"
58+
}
4759
},
4860
"imports": {
4961
"#constructs/*": {
@@ -58,6 +70,10 @@
5870
"kronk": "./src/errors/*.mts",
5971
"default": "./dist/errors/*.mjs"
6072
},
73+
"#events/*": {
74+
"kronk": "./src/events/*.mts",
75+
"default": "./dist/events/*.mjs"
76+
},
6177
"#fixtures/*": "./__fixtures__/*.mts",
6278
"#interfaces/*": {
6379
"kronk": "./src/interfaces/*.mts",

src/__snapshots__/index.e2e.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
exports[`e2e:kronk > should expose public api 1`] = `
44
[
55
"optionValueSource",
6-
"CommandError",
7-
"KronkError",
86
"Argument",
97
"Command",
108
"Option",
9+
"CommandError",
10+
"KronkError",
11+
"KronkEvent",
12+
"OptionEvent",
1113
"isArgument",
12-
"isCommand",
1314
"isCommandError",
1415
"isKronkError",
16+
"isKronkEvent",
1517
"isOption",
1618
]
1719
`;

src/errors/__tests__/index.e2e.spec.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module kronk/errors/tests/e2e/api
44
*/
55

6-
import * as testSubject from '#errors/index'
6+
import * as testSubject from '@flex-development/kronk/errors'
77

88
describe('e2e:errors', () => {
99
it('should expose public api', () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`e2e:events > should expose public api 1`] = `
4+
[
5+
"KronkEvent",
6+
"OptionEvent",
7+
]
8+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file E2E Tests - events
3+
* @module kronk/errors/tests/e2e/api
4+
*/
5+
6+
import * as testSubject from '@flex-development/kronk/events'
7+
8+
describe('e2e:events', () => {
9+
it('should expose public api', () => {
10+
expect(Object.keys(testSubject)).toMatchSnapshot()
11+
})
12+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @file Unit Tests - KronkEvent
3+
* @module kronk/events/tests/unit/KronkEvent
4+
*/
5+
6+
import TestSubject from '#events/kronk.event'
7+
import isKronkEvent from '#utils/is-kronk-event'
8+
import type { KronkEventName } from '@flex-development/kronk'
9+
10+
describe('unit:events/KronkEvent', () => {
11+
let id: KronkEventName
12+
let subject: TestSubject
13+
14+
beforeAll(() => {
15+
subject = new TestSubject(id = 'option:')
16+
})
17+
18+
describe('constructor', () => {
19+
it('should pass kronk event guard', () => {
20+
expect(subject).to.satisfy(isKronkEvent)
21+
})
22+
23+
it('should set #id', () => {
24+
expect(subject).to.have.property('id', id)
25+
})
26+
})
27+
28+
describe('#toString', () => {
29+
it('should return event as human-readable string', () => {
30+
expect(subject.toString()).to.eq(id).and.eq(String(subject))
31+
})
32+
})
33+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file Unit Tests - OptionEvent
3+
* @module kronk/events/tests/unit/OptionEvent
4+
*/
5+
6+
import optionValueSource from '#enums/option-value-source'
7+
import KronkEvent from '#events/kronk.event'
8+
import TestSubject from '#events/option.event'
9+
import Option from '#lib/option'
10+
import type {
11+
Flags,
12+
OptionValueSource,
13+
RawOptionValue
14+
} from '@flex-development/kronk'
15+
import { ok } from 'devlop'
16+
17+
describe('unit:events/OptionEvent', () => {
18+
let flag: Flags
19+
let option: Option
20+
let source: OptionValueSource
21+
let subject: TestSubject
22+
let value: RawOptionValue
23+
24+
beforeAll(() => {
25+
option = new Option('-d | --debug')
26+
ok(typeof option.long === 'string', 'expected `option.long`')
27+
28+
flag = option.long
29+
source = optionValueSource.config
30+
value = true
31+
32+
subject = new TestSubject(option, value, source, flag)
33+
})
34+
35+
describe('constructor', () => {
36+
it('should be instanceof `KronkEvent`', () => {
37+
expect(subject).to.be.instanceof(KronkEvent)
38+
})
39+
40+
it('should set #flag', () => {
41+
expect(subject).to.have.property('flag', flag)
42+
})
43+
44+
it('should set #id', () => {
45+
expect(subject).to.have.property('id', option.event)
46+
})
47+
48+
it('should set #option', () => {
49+
expect(subject).to.have.property('option', option)
50+
})
51+
52+
it('should set #source', () => {
53+
expect(subject).to.have.property('source', source)
54+
})
55+
56+
it('should set #value', () => {
57+
expect(subject).to.have.property('value', value)
58+
})
59+
})
60+
})

src/events/index.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @file Entry Point - Events
3+
* @module kronk/events
4+
*/
5+
6+
export { default as KronkEvent } from '#events/kronk.event'
7+
export { default as OptionEvent } from '#events/option.event'

0 commit comments

Comments
 (0)