@xivdyetools/test-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +144 -0
  3. package/dist/assertions/index.d.ts +7 -0
  4. package/dist/assertions/index.d.ts.map +1 -0
  5. package/dist/assertions/index.js +7 -0
  6. package/dist/assertions/index.js.map +1 -0
  7. package/dist/assertions/response.d.ts +84 -0
  8. package/dist/assertions/response.d.ts.map +1 -0
  9. package/dist/assertions/response.js +125 -0
  10. package/dist/assertions/response.js.map +1 -0
  11. package/dist/auth/context.d.ts +55 -0
  12. package/dist/auth/context.d.ts.map +1 -0
  13. package/dist/auth/context.js +95 -0
  14. package/dist/auth/context.js.map +1 -0
  15. package/dist/auth/headers.d.ts +64 -0
  16. package/dist/auth/headers.d.ts.map +1 -0
  17. package/dist/auth/headers.js +101 -0
  18. package/dist/auth/headers.js.map +1 -0
  19. package/dist/auth/index.d.ts +10 -0
  20. package/dist/auth/index.d.ts.map +1 -0
  21. package/dist/auth/index.js +10 -0
  22. package/dist/auth/index.js.map +1 -0
  23. package/dist/auth/jwt.d.ts +76 -0
  24. package/dist/auth/jwt.d.ts.map +1 -0
  25. package/dist/auth/jwt.js +77 -0
  26. package/dist/auth/jwt.js.map +1 -0
  27. package/dist/auth/signature.d.ts +64 -0
  28. package/dist/auth/signature.d.ts.map +1 -0
  29. package/dist/auth/signature.js +75 -0
  30. package/dist/auth/signature.js.map +1 -0
  31. package/dist/cloudflare/analytics.d.ts +55 -0
  32. package/dist/cloudflare/analytics.d.ts.map +1 -0
  33. package/dist/cloudflare/analytics.js +44 -0
  34. package/dist/cloudflare/analytics.js.map +1 -0
  35. package/dist/cloudflare/d1.d.ts +101 -0
  36. package/dist/cloudflare/d1.d.ts.map +1 -0
  37. package/dist/cloudflare/d1.js +148 -0
  38. package/dist/cloudflare/d1.js.map +1 -0
  39. package/dist/cloudflare/fetcher.d.ts +72 -0
  40. package/dist/cloudflare/fetcher.d.ts.map +1 -0
  41. package/dist/cloudflare/fetcher.js +136 -0
  42. package/dist/cloudflare/fetcher.js.map +1 -0
  43. package/dist/cloudflare/index.d.ts +12 -0
  44. package/dist/cloudflare/index.d.ts.map +1 -0
  45. package/dist/cloudflare/index.js +12 -0
  46. package/dist/cloudflare/index.js.map +1 -0
  47. package/dist/cloudflare/kv.d.ts +85 -0
  48. package/dist/cloudflare/kv.d.ts.map +1 -0
  49. package/dist/cloudflare/kv.js +138 -0
  50. package/dist/cloudflare/kv.js.map +1 -0
  51. package/dist/cloudflare/r2.d.ts +88 -0
  52. package/dist/cloudflare/r2.d.ts.map +1 -0
  53. package/dist/cloudflare/r2.js +127 -0
  54. package/dist/cloudflare/r2.js.map +1 -0
  55. package/dist/constants/index.d.ts +8 -0
  56. package/dist/constants/index.d.ts.map +1 -0
  57. package/dist/constants/index.js +8 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/constants/pkce.d.ts +89 -0
  60. package/dist/constants/pkce.d.ts.map +1 -0
  61. package/dist/constants/pkce.js +107 -0
  62. package/dist/constants/pkce.js.map +1 -0
  63. package/dist/constants/secrets.d.ts +72 -0
  64. package/dist/constants/secrets.d.ts.map +1 -0
  65. package/dist/constants/secrets.js +73 -0
  66. package/dist/constants/secrets.js.map +1 -0
  67. package/dist/dom/canvas.d.ts +108 -0
  68. package/dist/dom/canvas.d.ts.map +1 -0
  69. package/dist/dom/canvas.js +125 -0
  70. package/dist/dom/canvas.js.map +1 -0
  71. package/dist/dom/fetch.d.ts +69 -0
  72. package/dist/dom/fetch.d.ts.map +1 -0
  73. package/dist/dom/fetch.js +107 -0
  74. package/dist/dom/fetch.js.map +1 -0
  75. package/dist/dom/index.d.ts +12 -0
  76. package/dist/dom/index.d.ts.map +1 -0
  77. package/dist/dom/index.js +12 -0
  78. package/dist/dom/index.js.map +1 -0
  79. package/dist/dom/localStorage.d.ts +80 -0
  80. package/dist/dom/localStorage.d.ts.map +1 -0
  81. package/dist/dom/localStorage.js +124 -0
  82. package/dist/dom/localStorage.js.map +1 -0
  83. package/dist/dom/matchMedia.d.ts +51 -0
  84. package/dist/dom/matchMedia.d.ts.map +1 -0
  85. package/dist/dom/matchMedia.js +120 -0
  86. package/dist/dom/matchMedia.js.map +1 -0
  87. package/dist/dom/resizeObserver.d.ts +68 -0
  88. package/dist/dom/resizeObserver.d.ts.map +1 -0
  89. package/dist/dom/resizeObserver.js +99 -0
  90. package/dist/dom/resizeObserver.js.map +1 -0
  91. package/dist/factories/category.d.ts +74 -0
  92. package/dist/factories/category.d.ts.map +1 -0
  93. package/dist/factories/category.js +99 -0
  94. package/dist/factories/category.js.map +1 -0
  95. package/dist/factories/dye.d.ts +76 -0
  96. package/dist/factories/dye.d.ts.map +1 -0
  97. package/dist/factories/dye.js +211 -0
  98. package/dist/factories/dye.js.map +1 -0
  99. package/dist/factories/index.d.ts +13 -0
  100. package/dist/factories/index.d.ts.map +1 -0
  101. package/dist/factories/index.js +14 -0
  102. package/dist/factories/index.js.map +1 -0
  103. package/dist/factories/preset.d.ts +105 -0
  104. package/dist/factories/preset.d.ts.map +1 -0
  105. package/dist/factories/preset.js +170 -0
  106. package/dist/factories/preset.js.map +1 -0
  107. package/dist/factories/user.d.ts +74 -0
  108. package/dist/factories/user.d.ts.map +1 -0
  109. package/dist/factories/user.js +115 -0
  110. package/dist/factories/user.js.map +1 -0
  111. package/dist/factories/vote.d.ts +55 -0
  112. package/dist/factories/vote.d.ts.map +1 -0
  113. package/dist/factories/vote.js +68 -0
  114. package/dist/factories/vote.js.map +1 -0
  115. package/dist/index.d.ts +17 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +24 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/utils/counters.d.ts +35 -0
  120. package/dist/utils/counters.d.ts.map +1 -0
  121. package/dist/utils/counters.js +53 -0
  122. package/dist/utils/counters.js.map +1 -0
  123. package/dist/utils/crypto.d.ts +42 -0
  124. package/dist/utils/crypto.d.ts.map +1 -0
  125. package/dist/utils/crypto.js +72 -0
  126. package/dist/utils/crypto.js.map +1 -0
  127. package/dist/utils/index.d.ts +6 -0
  128. package/dist/utils/index.d.ts.map +1 -0
  129. package/dist/utils/index.js +6 -0
  130. package/dist/utils/index.js.map +1 -0
  131. package/package.json +88 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * User factory functions for testing
3
+ *
4
+ * Provides functions to create mock users for OAuth and auth testing.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const user = createMockUser({ username: 'TestPlayer' });
9
+ * const row = createMockUserRow({ auth_provider: 'discord' });
10
+ * ```
11
+ */
12
+ import { nextStringId } from '../utils/counters.js';
13
+ /**
14
+ * Creates a mock user row (as returned from database)
15
+ *
16
+ * @param overrides - Optional overrides for the default values
17
+ * @returns A UserRow object
18
+ */
19
+ export function createMockUserRow(overrides = {}) {
20
+ const id = overrides.id ?? nextStringId('user');
21
+ const now = new Date().toISOString();
22
+ return {
23
+ id,
24
+ discord_id: '123456789',
25
+ xivauth_id: null,
26
+ auth_provider: 'discord',
27
+ username: 'TestUser',
28
+ avatar_url: null,
29
+ created_at: now,
30
+ updated_at: now,
31
+ ...overrides,
32
+ };
33
+ }
34
+ /**
35
+ * Creates a mock AuthUser (domain object)
36
+ *
37
+ * @param overrides - Optional overrides for the default values
38
+ * @returns An AuthUser object
39
+ */
40
+ export function createMockUser(overrides = {}) {
41
+ const id = overrides.id ?? nextStringId('user');
42
+ return {
43
+ id,
44
+ username: 'TestUser',
45
+ global_name: 'Test User',
46
+ avatar: null,
47
+ avatar_url: null,
48
+ auth_provider: 'discord',
49
+ ...overrides,
50
+ };
51
+ }
52
+ /**
53
+ * Creates multiple mock users
54
+ *
55
+ * @param count - Number of users to create
56
+ * @param overrides - Optional overrides to apply to all users
57
+ * @returns Array of AuthUser objects
58
+ */
59
+ export function createMockUsers(count, overrides = {}) {
60
+ return Array.from({ length: count }, (_, i) => createMockUser({
61
+ username: `User${i + 1}`,
62
+ global_name: `User ${i + 1}`,
63
+ ...overrides,
64
+ }));
65
+ }
66
+ /**
67
+ * Creates a Discord-authenticated user
68
+ *
69
+ * @param discordId - Discord user ID
70
+ * @param overrides - Optional additional overrides
71
+ * @returns An AuthUser object
72
+ */
73
+ export function createDiscordUser(discordId, overrides = {}) {
74
+ return createMockUser({
75
+ id: discordId,
76
+ auth_provider: 'discord',
77
+ ...overrides,
78
+ });
79
+ }
80
+ /**
81
+ * Creates an XIVAuth-authenticated user
82
+ *
83
+ * @param xivauthId - XIVAuth user ID
84
+ * @param overrides - Optional additional overrides
85
+ * @returns An AuthUser object
86
+ */
87
+ export function createXIVAuthUser(xivauthId, overrides = {}) {
88
+ return createMockUser({
89
+ id: xivauthId,
90
+ auth_provider: 'xivauth',
91
+ ...overrides,
92
+ });
93
+ }
94
+ /**
95
+ * Converts an AuthUser to a UserRow
96
+ *
97
+ * @param user - The AuthUser to convert
98
+ * @param discordId - Discord ID (if auth_provider is 'discord')
99
+ * @param xivauthId - XIVAuth ID (if auth_provider is 'xivauth')
100
+ * @returns A UserRow object
101
+ */
102
+ export function userToRow(user, discordId, xivauthId) {
103
+ const now = new Date().toISOString();
104
+ return {
105
+ id: user.id,
106
+ discord_id: discordId ?? (user.auth_provider === 'discord' ? user.id : null),
107
+ xivauth_id: xivauthId ?? (user.auth_provider === 'xivauth' ? user.id : null),
108
+ auth_provider: user.auth_provider ?? 'discord',
109
+ username: user.username,
110
+ avatar_url: user.avatar_url,
111
+ created_at: now,
112
+ updated_at: now,
113
+ };
114
+ }
115
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/factories/user.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAmBpD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAA8B,EAAE;IAChE,MAAM,EAAE,GAAG,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;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAAiB,EACjB,YAA+B,EAAE;IAEjC,OAAO,cAAc,CAAC;QACpB,EAAE,EAAE,SAAS;QACb,aAAa,EAAE,SAAS;QACxB,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,IAAc,EACd,SAAyB,EACzB,SAAyB;IAEzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAErC,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,UAAU,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5E,UAAU,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5E,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,SAAS;QAC9C,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,GAAG;QACf,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Vote factory functions for testing
3
+ *
4
+ * Provides functions to create mock votes.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const vote = createMockVote({ preset_id: 'preset-1' });
9
+ * const votes = createMockVotes(5, { user_discord_id: '123' });
10
+ * ```
11
+ */
12
+ /**
13
+ * Vote database row type (as stored in D1)
14
+ */
15
+ export interface VoteRow {
16
+ preset_id: string;
17
+ user_discord_id: string;
18
+ created_at: string;
19
+ }
20
+ /**
21
+ * Creates a mock vote row
22
+ *
23
+ * @param overrides - Optional overrides for the default values
24
+ * @returns A VoteRow object
25
+ */
26
+ export declare function createMockVoteRow(overrides?: Partial<VoteRow>): VoteRow;
27
+ /**
28
+ * Alias for createMockVoteRow
29
+ */
30
+ export declare const createMockVote: typeof createMockVoteRow;
31
+ /**
32
+ * Creates multiple mock votes
33
+ *
34
+ * @param count - Number of votes to create
35
+ * @param overrides - Optional overrides to apply to all votes
36
+ * @returns Array of VoteRow objects
37
+ */
38
+ export declare function createMockVotes(count: number, overrides?: Partial<VoteRow>): VoteRow[];
39
+ /**
40
+ * Creates votes for a specific preset from multiple users
41
+ *
42
+ * @param presetId - The preset ID
43
+ * @param userCount - Number of unique users to vote
44
+ * @returns Array of VoteRow objects
45
+ */
46
+ export declare function createVotesForPreset(presetId: string, userCount: number): VoteRow[];
47
+ /**
48
+ * Creates votes from a specific user for multiple presets
49
+ *
50
+ * @param userId - The user's Discord ID
51
+ * @param presetIds - Array of preset IDs to vote for
52
+ * @returns Array of VoteRow objects
53
+ */
54
+ export declare function createVotesFromUser(userId: string, presetIds: string[]): VoteRow[];
55
+ //# sourceMappingURL=vote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vote.d.ts","sourceRoot":"","sources":["../../src/factories/vote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,OAAO,CAAC,OAAO,CAAM,GAAG,OAAO,CAS3E;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,0BAAoB,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,OAAO,CAAC,OAAO,CAAM,GAC/B,OAAO,EAAE,CAEX;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,EAAE,CAOX;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,EAAE,CAOX"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Vote factory functions for testing
3
+ *
4
+ * Provides functions to create mock votes.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const vote = createMockVote({ preset_id: 'preset-1' });
9
+ * const votes = createMockVotes(5, { user_discord_id: '123' });
10
+ * ```
11
+ */
12
+ import { nextId } from '../utils/counters.js';
13
+ /**
14
+ * Creates a mock vote row
15
+ *
16
+ * @param overrides - Optional overrides for the default values
17
+ * @returns A VoteRow object
18
+ */
19
+ export function createMockVoteRow(overrides = {}) {
20
+ const voteNum = nextId('vote');
21
+ return {
22
+ preset_id: `preset-${voteNum}`,
23
+ user_discord_id: '123456789',
24
+ created_at: new Date().toISOString(),
25
+ ...overrides,
26
+ };
27
+ }
28
+ /**
29
+ * Alias for createMockVoteRow
30
+ */
31
+ export const createMockVote = createMockVoteRow;
32
+ /**
33
+ * Creates multiple mock votes
34
+ *
35
+ * @param count - Number of votes to create
36
+ * @param overrides - Optional overrides to apply to all votes
37
+ * @returns Array of VoteRow objects
38
+ */
39
+ export function createMockVotes(count, overrides = {}) {
40
+ return Array.from({ length: count }, () => createMockVoteRow(overrides));
41
+ }
42
+ /**
43
+ * Creates votes for a specific preset from multiple users
44
+ *
45
+ * @param presetId - The preset ID
46
+ * @param userCount - Number of unique users to vote
47
+ * @returns Array of VoteRow objects
48
+ */
49
+ export function createVotesForPreset(presetId, userCount) {
50
+ return Array.from({ length: userCount }, (_, i) => createMockVoteRow({
51
+ preset_id: presetId,
52
+ user_discord_id: `user-${i + 1}`,
53
+ }));
54
+ }
55
+ /**
56
+ * Creates votes from a specific user for multiple presets
57
+ *
58
+ * @param userId - The user's Discord ID
59
+ * @param presetIds - Array of preset IDs to vote for
60
+ * @returns Array of VoteRow objects
61
+ */
62
+ export function createVotesFromUser(userId, presetIds) {
63
+ return presetIds.map((presetId) => createMockVoteRow({
64
+ preset_id: presetId,
65
+ user_discord_id: userId,
66
+ }));
67
+ }
68
+ //# sourceMappingURL=vote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vote.js","sourceRoot":"","sources":["../../src/factories/vote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAW9C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAA8B,EAAE;IAChE,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/B,OAAO;QACL,SAAS,EAAE,UAAU,OAAO,EAAE;QAC9B,eAAe,EAAE,WAAW;QAC5B,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAa,EACb,YAA8B,EAAE;IAEhC,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAgB,EAChB,SAAiB;IAEjB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChD,iBAAiB,CAAC;QAChB,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE;KACjC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,SAAmB;IAEnB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAChC,iBAAiB,CAAC;QAChB,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,MAAM;KACxB,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @xivdyetools/test-utils
3
+ *
4
+ * Shared testing utilities for the xivdyetools ecosystem.
5
+ * Provides mocks for Cloudflare Workers bindings, authentication helpers,
6
+ * domain object factories, and DOM utilities.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export * from './cloudflare/index.js';
11
+ export * from './auth/index.js';
12
+ export * from './factories/index.js';
13
+ export * from './dom/index.js';
14
+ export * from './assertions/index.js';
15
+ export * from './constants/index.js';
16
+ export * from './utils/index.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,uBAAuB,CAAC;AAGtC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,uBAAuB,CAAC;AAGtC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @xivdyetools/test-utils
3
+ *
4
+ * Shared testing utilities for the xivdyetools ecosystem.
5
+ * Provides mocks for Cloudflare Workers bindings, authentication helpers,
6
+ * domain object factories, and DOM utilities.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ // Cloudflare Workers mocks
11
+ export * from './cloudflare/index.js';
12
+ // Authentication helpers
13
+ export * from './auth/index.js';
14
+ // Domain object factories
15
+ export * from './factories/index.js';
16
+ // DOM/browser utilities
17
+ export * from './dom/index.js';
18
+ // Response assertions
19
+ export * from './assertions/index.js';
20
+ // Test constants
21
+ export * from './constants/index.js';
22
+ // Utilities
23
+ export * from './utils/index.js';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,2BAA2B;AAC3B,cAAc,uBAAuB,CAAC;AAEtC,yBAAyB;AACzB,cAAc,iBAAiB,CAAC;AAEhC,0BAA0B;AAC1B,cAAc,sBAAsB,CAAC;AAErC,wBAAwB;AACxB,cAAc,gBAAgB,CAAC;AAE/B,sBAAsB;AACtB,cAAc,uBAAuB,CAAC;AAEtC,iBAAiB;AACjB,cAAc,sBAAsB,CAAC;AAErC,YAAY;AACZ,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Auto-increment counter management for test factories
3
+ *
4
+ * Provides unique IDs for test objects while allowing reset between tests
5
+ * to ensure test isolation.
6
+ */
7
+ /**
8
+ * Get the next value for a named counter
9
+ * @param name - The counter name (e.g., 'preset', 'category')
10
+ * @returns The next sequential value
11
+ */
12
+ export declare function nextId(name: string): number;
13
+ /**
14
+ * Get a string ID with prefix
15
+ * @param prefix - The ID prefix (e.g., 'preset', 'category')
16
+ * @returns A string ID like 'preset-1', 'category-2'
17
+ */
18
+ export declare function nextStringId(prefix: string): string;
19
+ /**
20
+ * Reset all counters to zero
21
+ * Call this in beforeEach() for test isolation
22
+ */
23
+ export declare function resetCounters(): void;
24
+ /**
25
+ * Reset a specific counter
26
+ * @param name - The counter name to reset
27
+ */
28
+ export declare function resetCounter(name: string): void;
29
+ /**
30
+ * Get the current value of a counter (without incrementing)
31
+ * @param name - The counter name
32
+ * @returns The current counter value, or 0 if not set
33
+ */
34
+ export declare function getCounterValue(name: string): number;
35
+ //# sourceMappingURL=counters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counters.d.ts","sourceRoot":"","sources":["../../src/utils/counters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAIpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Auto-increment counter management for test factories
3
+ *
4
+ * Provides unique IDs for test objects while allowing reset between tests
5
+ * to ensure test isolation.
6
+ */
7
+ // Counter storage
8
+ const counters = {};
9
+ /**
10
+ * Get the next value for a named counter
11
+ * @param name - The counter name (e.g., 'preset', 'category')
12
+ * @returns The next sequential value
13
+ */
14
+ export function nextId(name) {
15
+ if (!(name in counters)) {
16
+ counters[name] = 0;
17
+ }
18
+ counters[name]++;
19
+ return counters[name];
20
+ }
21
+ /**
22
+ * Get a string ID with prefix
23
+ * @param prefix - The ID prefix (e.g., 'preset', 'category')
24
+ * @returns A string ID like 'preset-1', 'category-2'
25
+ */
26
+ export function nextStringId(prefix) {
27
+ return `${prefix}-${nextId(prefix)}`;
28
+ }
29
+ /**
30
+ * Reset all counters to zero
31
+ * Call this in beforeEach() for test isolation
32
+ */
33
+ export function resetCounters() {
34
+ for (const key in counters) {
35
+ delete counters[key];
36
+ }
37
+ }
38
+ /**
39
+ * Reset a specific counter
40
+ * @param name - The counter name to reset
41
+ */
42
+ export function resetCounter(name) {
43
+ delete counters[name];
44
+ }
45
+ /**
46
+ * Get the current value of a counter (without incrementing)
47
+ * @param name - The counter name
48
+ * @returns The current counter value, or 0 if not set
49
+ */
50
+ export function getCounterValue(name) {
51
+ return counters[name] ?? 0;
52
+ }
53
+ //# sourceMappingURL=counters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counters.js","sourceRoot":"","sources":["../../src/utils/counters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kBAAkB;AAClB,MAAM,QAAQ,GAA2B,EAAE,CAAC;AAE5C;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,IAAI,CAAC,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IACjB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,GAAG,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Cryptographic utilities for test helpers
3
+ *
4
+ * Provides Base64URL encoding for JWT creation and other crypto operations.
5
+ */
6
+ /**
7
+ * Encode a string to Base64URL format (RFC 4648)
8
+ * Used for JWT header and payload encoding
9
+ *
10
+ * @param str - The string to encode
11
+ * @returns Base64URL encoded string
12
+ */
13
+ export declare function base64UrlEncode(str: string): string;
14
+ /**
15
+ * Encode bytes to Base64URL format
16
+ *
17
+ * @param bytes - The bytes to encode
18
+ * @returns Base64URL encoded string
19
+ */
20
+ export declare function base64UrlEncodeBytes(bytes: Uint8Array): string;
21
+ /**
22
+ * Decode a Base64URL string
23
+ *
24
+ * @param str - The Base64URL string to decode
25
+ * @returns Decoded string
26
+ */
27
+ export declare function base64UrlDecode(str: string): string;
28
+ /**
29
+ * Convert a hex string to Uint8Array
30
+ *
31
+ * @param hex - The hex string
32
+ * @returns Uint8Array of bytes
33
+ */
34
+ export declare function hexToBytes(hex: string): Uint8Array;
35
+ /**
36
+ * Convert Uint8Array to hex string
37
+ *
38
+ * @param bytes - The bytes to convert
39
+ * @returns Hex string
40
+ */
41
+ export declare function bytesToHex(bytes: Uint8Array): string;
42
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAM9D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMlD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Cryptographic utilities for test helpers
3
+ *
4
+ * Provides Base64URL encoding for JWT creation and other crypto operations.
5
+ */
6
+ /**
7
+ * Encode a string to Base64URL format (RFC 4648)
8
+ * Used for JWT header and payload encoding
9
+ *
10
+ * @param str - The string to encode
11
+ * @returns Base64URL encoded string
12
+ */
13
+ export function base64UrlEncode(str) {
14
+ const bytes = new TextEncoder().encode(str);
15
+ let binary = '';
16
+ for (let i = 0; i < bytes.length; i++) {
17
+ binary += String.fromCharCode(bytes[i]);
18
+ }
19
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
20
+ }
21
+ /**
22
+ * Encode bytes to Base64URL format
23
+ *
24
+ * @param bytes - The bytes to encode
25
+ * @returns Base64URL encoded string
26
+ */
27
+ export function base64UrlEncodeBytes(bytes) {
28
+ let binary = '';
29
+ for (let i = 0; i < bytes.length; i++) {
30
+ binary += String.fromCharCode(bytes[i]);
31
+ }
32
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
33
+ }
34
+ /**
35
+ * Decode a Base64URL string
36
+ *
37
+ * @param str - The Base64URL string to decode
38
+ * @returns Decoded string
39
+ */
40
+ export function base64UrlDecode(str) {
41
+ // Add padding if needed
42
+ let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
43
+ while (base64.length % 4) {
44
+ base64 += '=';
45
+ }
46
+ return atob(base64);
47
+ }
48
+ /**
49
+ * Convert a hex string to Uint8Array
50
+ *
51
+ * @param hex - The hex string
52
+ * @returns Uint8Array of bytes
53
+ */
54
+ export function hexToBytes(hex) {
55
+ const bytes = new Uint8Array(hex.length / 2);
56
+ for (let i = 0; i < hex.length; i += 2) {
57
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
58
+ }
59
+ return bytes;
60
+ }
61
+ /**
62
+ * Convert Uint8Array to hex string
63
+ *
64
+ * @param bytes - The bytes to convert
65
+ * @returns Hex string
66
+ */
67
+ export function bytesToHex(bytes) {
68
+ return Array.from(bytes)
69
+ .map((b) => b.toString(16).padStart(2, '0'))
70
+ .join('');
71
+ }
72
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,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,GAAG,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Utility functions for test utilities
3
+ */
4
+ export * from './counters.js';
5
+ export * from './crypto.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Utility functions for test utilities
3
+ */
4
+ export * from './counters.js';
5
+ export * from './crypto.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@xivdyetools/test-utils",
3
+ "version": "1.0.0",
4
+ "description": "Shared testing utilities for the xivdyetools ecosystem",
5
+ "author": "XIV Dye Tools",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./cloudflare": {
16
+ "types": "./dist/cloudflare/index.d.ts",
17
+ "import": "./dist/cloudflare/index.js"
18
+ },
19
+ "./auth": {
20
+ "types": "./dist/auth/index.d.ts",
21
+ "import": "./dist/auth/index.js"
22
+ },
23
+ "./factories": {
24
+ "types": "./dist/factories/index.d.ts",
25
+ "import": "./dist/factories/index.js"
26
+ },
27
+ "./dom": {
28
+ "types": "./dist/dom/index.d.ts",
29
+ "import": "./dist/dom/index.js"
30
+ },
31
+ "./assertions": {
32
+ "types": "./dist/assertions/index.d.ts",
33
+ "import": "./dist/assertions/index.js"
34
+ },
35
+ "./constants": {
36
+ "types": "./dist/constants/index.d.ts",
37
+ "import": "./dist/constants/index.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md"
43
+ ],
44
+ "sideEffects": false,
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.build.json",
47
+ "type-check": "tsc --noEmit",
48
+ "clean": "rimraf dist",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest",
51
+ "test:coverage": "vitest run --coverage",
52
+ "prepublishOnly": "npm run clean && npm run build"
53
+ },
54
+ "peerDependencies": {
55
+ "vitest": ">=2.0.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "vitest": {
59
+ "optional": false
60
+ }
61
+ },
62
+ "dependencies": {
63
+ "@xivdyetools/types": "^1.0.0"
64
+ },
65
+ "devDependencies": {
66
+ "@cloudflare/workers-types": "^4.20241205.0",
67
+ "@testing-library/dom": "^10.0.0",
68
+ "@vitest/coverage-v8": "^2.0.0",
69
+ "rimraf": "^5.0.5",
70
+ "typescript": "^5.3.2",
71
+ "vitest": "^2.0.0"
72
+ },
73
+ "engines": {
74
+ "node": ">=18.0.0"
75
+ },
76
+ "keywords": [
77
+ "xivdyetools",
78
+ "testing",
79
+ "vitest",
80
+ "cloudflare-workers",
81
+ "mocks",
82
+ "test-utils"
83
+ ],
84
+ "repository": {
85
+ "type": "git",
86
+ "url": "https://github.com/xivdyetools/xivdyetools-test-utils.git"
87
+ }
88
+ }