xenopomp-essentials 0.5.0-canary.2 → 0.5.0-canary.4

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.
package/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { P as PromiseOr } from './shared/xenopomp-essentials.B-Vt61jj.mjs';
1
+ export { O as Optional, P as PromiseOr, U as Undefinable } from './shared/xenopomp-essentials.CO5lcTlK.mjs';
2
2
  import { ElementType, ComponentProps, FC, ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { Jsonifiable } from 'type-fest';
4
4
  import * as transliteration from 'transliteration';
@@ -345,17 +345,6 @@ type ReplaceReturnType<TFn, TR> = TFn extends (...a: infer A) => any ? (...a: A)
345
345
  */
346
346
  type SelectivePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
347
347
 
348
- /**
349
- * Makes type union of type T and undefined
350
- * @since 0.0.1
351
- * @deprecated Renamed to {@link Optional}.
352
- */
353
- type Undefinable<T> = T | undefined;
354
- /**
355
- * Marks type as optional (undefinable).
356
- */
357
- type Optional<T> = T | undefined;
358
-
359
348
  /**
360
349
  * The strict version of Omit. Allows to remove only
361
350
  * keys that are presented in T type.
@@ -618,4 +607,4 @@ declare const minmax: (num: number, [min, max]: [min: number | undefined, max: n
618
607
  declare function jsxDotNotation<Props = EmptyObject, Rest extends Record<string, FC<any>> = EmptyObject>(comp: FC<Props>, rest: Rest): FC<Props> & Rest;
619
608
 
620
609
  export { capitalize, jsxDotNotation, minmax, parseVersion, pipe, transliterate, uncapitalize };
621
- export type { AnyFC, AnyObject, ArrayItemType, ArrayType, AsyncFC, AsyncReturnType, AsyncVariableFC, DataAttributes, Defined, EmptyObject, FCProps, FcProps, Fn, FunctionalChildren, InjectDeep, Jsonish, Lenient, LenientAutocomplete, MatchType, MergeTypes, Modify, NextErrorParams, NextParams, NextSearchParams, Nullable, OneOf, OnlyFirst, Optional, Preid, Prettify, PrettifyDeep, RecordKey, RecordValue, ReplaceReturnType, SelectivePartial, SetState, StrictOmit, Synchronous, Undefinable, VariableFC, VariableProps, VersionData, WeakOmit, Writeable, WriteableDeep };
610
+ export type { AnyFC, AnyObject, ArrayItemType, ArrayType, AsyncFC, AsyncReturnType, AsyncVariableFC, DataAttributes, Defined, EmptyObject, FCProps, FcProps, Fn, FunctionalChildren, InjectDeep, Jsonish, Lenient, LenientAutocomplete, MatchType, MergeTypes, Modify, NextErrorParams, NextParams, NextSearchParams, Nullable, OneOf, OnlyFirst, Preid, Prettify, PrettifyDeep, RecordKey, RecordValue, ReplaceReturnType, SelectivePartial, SetState, StrictOmit, Synchronous, VariableFC, VariableProps, VersionData, WeakOmit, Writeable, WriteableDeep };
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { P as PromiseOr } from './shared/xenopomp-essentials.B-Vt61jj.js';
1
+ export { O as Optional, P as PromiseOr, U as Undefinable } from './shared/xenopomp-essentials.CO5lcTlK.js';
2
2
  import { ElementType, ComponentProps, FC, ReactNode, Dispatch, SetStateAction } from 'react';
3
3
  import { Jsonifiable } from 'type-fest';
4
4
  import * as transliteration from 'transliteration';
@@ -345,17 +345,6 @@ type ReplaceReturnType<TFn, TR> = TFn extends (...a: infer A) => any ? (...a: A)
345
345
  */
346
346
  type SelectivePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
347
347
 
348
- /**
349
- * Makes type union of type T and undefined
350
- * @since 0.0.1
351
- * @deprecated Renamed to {@link Optional}.
352
- */
353
- type Undefinable<T> = T | undefined;
354
- /**
355
- * Marks type as optional (undefinable).
356
- */
357
- type Optional<T> = T | undefined;
358
-
359
348
  /**
360
349
  * The strict version of Omit. Allows to remove only
361
350
  * keys that are presented in T type.
@@ -618,4 +607,4 @@ declare const minmax: (num: number, [min, max]: [min: number | undefined, max: n
618
607
  declare function jsxDotNotation<Props = EmptyObject, Rest extends Record<string, FC<any>> = EmptyObject>(comp: FC<Props>, rest: Rest): FC<Props> & Rest;
619
608
 
620
609
  export { capitalize, jsxDotNotation, minmax, parseVersion, pipe, transliterate, uncapitalize };
621
- export type { AnyFC, AnyObject, ArrayItemType, ArrayType, AsyncFC, AsyncReturnType, AsyncVariableFC, DataAttributes, Defined, EmptyObject, FCProps, FcProps, Fn, FunctionalChildren, InjectDeep, Jsonish, Lenient, LenientAutocomplete, MatchType, MergeTypes, Modify, NextErrorParams, NextParams, NextSearchParams, Nullable, OneOf, OnlyFirst, Optional, Preid, Prettify, PrettifyDeep, RecordKey, RecordValue, ReplaceReturnType, SelectivePartial, SetState, StrictOmit, Synchronous, Undefinable, VariableFC, VariableProps, VersionData, WeakOmit, Writeable, WriteableDeep };
610
+ export type { AnyFC, AnyObject, ArrayItemType, ArrayType, AsyncFC, AsyncReturnType, AsyncVariableFC, DataAttributes, Defined, EmptyObject, FCProps, FcProps, Fn, FunctionalChildren, InjectDeep, Jsonish, Lenient, LenientAutocomplete, MatchType, MergeTypes, Modify, NextErrorParams, NextParams, NextSearchParams, Nullable, OneOf, OnlyFirst, Preid, Prettify, PrettifyDeep, RecordKey, RecordValue, ReplaceReturnType, SelectivePartial, SetState, StrictOmit, Synchronous, VariableFC, VariableProps, VersionData, WeakOmit, Writeable, WriteableDeep };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xenopomp-essentials",
3
- "version": "0.5.0-canary.2",
3
+ "version": "0.5.0-canary.4",
4
4
  "author": "XenoPOMP <101574433+XenoPOMP@users.noreply.github.com>",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -69,6 +69,7 @@
69
69
  "type-fest": "^4.33.0",
70
70
  "typescript": "^5.7.3",
71
71
  "vitest": "^4.0.14",
72
+ "vitest-matchmedia-mock": "^2.0.3",
72
73
  "zod": "^3.24.1"
73
74
  },
74
75
  "devDependencies": {
@@ -0,0 +1,14 @@
1
+ type PromiseOr<T> = T | Promise<T>;
2
+
3
+ /**
4
+ * Makes type union of type T and undefined
5
+ * @since 0.0.1
6
+ * @deprecated Renamed to {@link Optional}.
7
+ */
8
+ type Undefinable<T> = T | undefined;
9
+ /**
10
+ * Marks type as optional (undefinable).
11
+ */
12
+ type Optional<T> = T | undefined;
13
+
14
+ export type { Optional as O, PromiseOr as P, Undefinable as U };
@@ -0,0 +1,14 @@
1
+ type PromiseOr<T> = T | Promise<T>;
2
+
3
+ /**
4
+ * Makes type union of type T and undefined
5
+ * @since 0.0.1
6
+ * @deprecated Renamed to {@link Optional}.
7
+ */
8
+ type Undefinable<T> = T | undefined;
9
+ /**
10
+ * Marks type as optional (undefinable).
11
+ */
12
+ type Optional<T> = T | undefined;
13
+
14
+ export type { Optional as O, PromiseOr as P, Undefinable as U };
@@ -1,7 +1,9 @@
1
- import { P as PromiseOr } from '../shared/xenopomp-essentials.B-Vt61jj.mjs';
1
+ import { P as PromiseOr, O as Optional } from '../shared/xenopomp-essentials.CO5lcTlK.mjs';
2
2
  import { render, renderHook } from '@testing-library/react';
3
3
  import * as vitest from 'vitest';
4
+ import { beforeAll, afterEach, Mock } from 'vitest';
4
5
  import * as _vitest_spy from '@vitest/spy';
6
+ import { PartialDeep } from 'type-fest';
5
7
 
6
8
  /** Executes function and expects that it won't throw. */
7
9
  declare const assertNotThrowing: <T = void>(callable: () => PromiseOr<T>) => void;
@@ -90,4 +92,85 @@ declare function spyFactory(context: string): {
90
92
  callSpy: Caller;
91
93
  };
92
94
 
93
- export { assertHookRendering, assertNotThrowing, assertRendering, clearMocks, mockEnv, mockRouter, spyFactory, twApiMock };
95
+ /**
96
+ * Mocks global scope object.
97
+ *
98
+ * @param name
99
+ * @param stub
100
+ *
101
+ * @example
102
+ * stubGlobal<typeof navigator>('navigator', {
103
+ * clipboard: {
104
+ * writeText: async (text: string) => vi.fn(),
105
+ * },
106
+ * });
107
+ */
108
+ declare const stubGlobal: <Global extends object>(name: string, stub: PartialDeep<Stub<Global>>) => void;
109
+
110
+ type Fn = () => void;
111
+ type Strategy = keyof typeof strategies;
112
+ type AfterAllCallback = Optional<Fn> | void;
113
+ /**
114
+ * Map of all available strategies for
115
+ * injectMocks function.
116
+ */
117
+ declare const strategies: {
118
+ beforeAll: typeof beforeAll;
119
+ afterEach: typeof afterEach;
120
+ };
121
+ /**
122
+ * Inserts mocks according to selected strategy
123
+ * (default is `beforeAll`).
124
+ *
125
+ * This function takes approach of useEffect hook
126
+ * from React. You define mocks inside function body,
127
+ * then you return function, that will be called
128
+ * in `afterAll` event.
129
+ *
130
+ * @example
131
+ * injectMocks(() => {
132
+ * mockRouter();
133
+ *
134
+ * return () => {
135
+ * console.log('This is printed from injectMocks func (afterAll event).');
136
+ * };
137
+ * });
138
+ */
139
+ declare const injectMocks: (func: () => AfterAllCallback, strategy?: Strategy) => void;
140
+
141
+ /**
142
+ * Mocks stuff related to window.matchMedia.
143
+ *
144
+ * @example
145
+ * describe('Root layout test', () => {
146
+ * // Use it inside describe suite. Place it to top
147
+ * injectMatchMediaMock();
148
+ *
149
+ * injectMocks(() => {
150
+ * vi.mock('next/font/google', () => ({
151
+ * Inter: FONT_MOCK,
152
+ * }));
153
+ * });
154
+ *
155
+ * testNextPage(<RootLayout children={undefined} />, {
156
+ * generateMetadata,
157
+ * });
158
+ * });
159
+ */
160
+ declare const injectMatchMediaMock: () => void;
161
+
162
+ /**
163
+ * Recursevely changes all keys` types inside T to R.
164
+ */
165
+ type TypeReplaceDeep<T extends object, R> = {
166
+ [K in keyof T]: T[K] extends object ? TypeReplaceDeep<T[K], R> : R;
167
+ };
168
+
169
+ type StubValue = Mock | (() => Mock) | (() => Promise<Mock>);
170
+ /**
171
+ * Represents vi stub object.
172
+ */
173
+ type Stub<T extends object> = TypeReplaceDeep<T, StubValue>;
174
+
175
+ export { assertHookRendering, assertNotThrowing, assertRendering, clearMocks, injectMatchMediaMock, injectMocks, mockEnv, mockRouter, spyFactory, stubGlobal, twApiMock };
176
+ export type { Stub, TypeReplaceDeep };
package/vitest/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { P as PromiseOr } from '../shared/xenopomp-essentials.B-Vt61jj.js';
1
+ import { P as PromiseOr, O as Optional } from '../shared/xenopomp-essentials.CO5lcTlK.js';
2
2
  import { render, renderHook } from '@testing-library/react';
3
3
  import * as vitest from 'vitest';
4
+ import { beforeAll, afterEach, Mock } from 'vitest';
4
5
  import * as _vitest_spy from '@vitest/spy';
6
+ import { PartialDeep } from 'type-fest';
5
7
 
6
8
  /** Executes function and expects that it won't throw. */
7
9
  declare const assertNotThrowing: <T = void>(callable: () => PromiseOr<T>) => void;
@@ -90,4 +92,85 @@ declare function spyFactory(context: string): {
90
92
  callSpy: Caller;
91
93
  };
92
94
 
93
- export { assertHookRendering, assertNotThrowing, assertRendering, clearMocks, mockEnv, mockRouter, spyFactory, twApiMock };
95
+ /**
96
+ * Mocks global scope object.
97
+ *
98
+ * @param name
99
+ * @param stub
100
+ *
101
+ * @example
102
+ * stubGlobal<typeof navigator>('navigator', {
103
+ * clipboard: {
104
+ * writeText: async (text: string) => vi.fn(),
105
+ * },
106
+ * });
107
+ */
108
+ declare const stubGlobal: <Global extends object>(name: string, stub: PartialDeep<Stub<Global>>) => void;
109
+
110
+ type Fn = () => void;
111
+ type Strategy = keyof typeof strategies;
112
+ type AfterAllCallback = Optional<Fn> | void;
113
+ /**
114
+ * Map of all available strategies for
115
+ * injectMocks function.
116
+ */
117
+ declare const strategies: {
118
+ beforeAll: typeof beforeAll;
119
+ afterEach: typeof afterEach;
120
+ };
121
+ /**
122
+ * Inserts mocks according to selected strategy
123
+ * (default is `beforeAll`).
124
+ *
125
+ * This function takes approach of useEffect hook
126
+ * from React. You define mocks inside function body,
127
+ * then you return function, that will be called
128
+ * in `afterAll` event.
129
+ *
130
+ * @example
131
+ * injectMocks(() => {
132
+ * mockRouter();
133
+ *
134
+ * return () => {
135
+ * console.log('This is printed from injectMocks func (afterAll event).');
136
+ * };
137
+ * });
138
+ */
139
+ declare const injectMocks: (func: () => AfterAllCallback, strategy?: Strategy) => void;
140
+
141
+ /**
142
+ * Mocks stuff related to window.matchMedia.
143
+ *
144
+ * @example
145
+ * describe('Root layout test', () => {
146
+ * // Use it inside describe suite. Place it to top
147
+ * injectMatchMediaMock();
148
+ *
149
+ * injectMocks(() => {
150
+ * vi.mock('next/font/google', () => ({
151
+ * Inter: FONT_MOCK,
152
+ * }));
153
+ * });
154
+ *
155
+ * testNextPage(<RootLayout children={undefined} />, {
156
+ * generateMetadata,
157
+ * });
158
+ * });
159
+ */
160
+ declare const injectMatchMediaMock: () => void;
161
+
162
+ /**
163
+ * Recursevely changes all keys` types inside T to R.
164
+ */
165
+ type TypeReplaceDeep<T extends object, R> = {
166
+ [K in keyof T]: T[K] extends object ? TypeReplaceDeep<T[K], R> : R;
167
+ };
168
+
169
+ type StubValue = Mock | (() => Mock) | (() => Promise<Mock>);
170
+ /**
171
+ * Represents vi stub object.
172
+ */
173
+ type Stub<T extends object> = TypeReplaceDeep<T, StubValue>;
174
+
175
+ export { assertHookRendering, assertNotThrowing, assertRendering, clearMocks, injectMatchMediaMock, injectMocks, mockEnv, mockRouter, spyFactory, stubGlobal, twApiMock };
176
+ export type { Stub, TypeReplaceDeep };
package/vitest/index.mjs CHANGED
@@ -1 +1 @@
1
- import{expect as c,vi as t}from"vitest";import{render as l,renderHook as r}from"@testing-library/react";import{blue as i,green as u,blueBright as d}from"ansi-colors";const a=e=>{c(()=>e()).not.toThrow()},f=(...e)=>{a(()=>l(...e))},h=(...e)=>{a(()=>r(...e))},m=e=>{t.stubEnv("CANONICAL_URL","http://localhost:4242"),t.stubEnv("IS_PRODUCTION","false"),e&&Object.entries(e).forEach(([n,o])=>t.stubEnv(n,o))},p=()=>{t.clearAllMocks(),t.resetAllMocks(),t.unstubAllEnvs(),t.unstubAllGlobals()},C=()=>{t.mock("next/navigation",()=>({useRouter:()=>({push(){}}),usePathname:()=>"/"}))},x={addBase:t.fn(),addComponents:t.fn(),addUtilities:t.fn(),addVariant:t.fn(),config:t.fn(),corePlugins:t.fn(),e:t.fn(),matchComponents:t.fn(),matchUtilities:t.fn(),matchVariant:t.fn(),theme:t.fn()};class b{_executionContext;constructor(n){this._executionContext=n}call(...n){console.debug(`${i(`[${this._executionContext}]`)} ${u(`Custom spy is called with these args: ${d(n.map(o=>`${o}`).join(", "))}`)}`)}}function g(e){const n=new b(e),o=t.spyOn(n,"call");return{expectToBeCalled:(...s)=>c(o).toHaveBeenCalledWith(s),expectToBeNotCalled:(...s)=>c(o).not.toHaveBeenCalledWith(s),spy:o,callSpy:(...s)=>n.call(s)}}export{h as assertHookRendering,a as assertNotThrowing,f as assertRendering,p as clearMocks,m as mockEnv,C as mockRouter,g as spyFactory,x as twApiMock};
1
+ import{expect as c,vi as t,afterEach as f,beforeAll as u,afterAll as h}from"vitest";import{render as d,renderHook as m}from"@testing-library/react";import l from"ansi-colors";import p from"vitest-matchmedia-mock";const a=e=>{c(()=>e()).not.toThrow()},b=(...e)=>{a(()=>d(...e))},C=(...e)=>{a(()=>m(...e))},k=e=>{t.stubEnv("CANONICAL_URL","http://localhost:4242"),t.stubEnv("IS_PRODUCTION","false"),e&&Object.entries(e).forEach(([o,n])=>t.stubEnv(o,n))},r=()=>{t.clearAllMocks(),t.resetAllMocks(),t.unstubAllEnvs(),t.unstubAllGlobals()},x=()=>{t.mock("next/navigation",()=>({useRouter:()=>({push(){}}),usePathname:()=>"/"}))},A={addBase:t.fn(),addComponents:t.fn(),addUtilities:t.fn(),addVariant:t.fn(),config:t.fn(),corePlugins:t.fn(),e:t.fn(),matchComponents:t.fn(),matchUtilities:t.fn(),matchVariant:t.fn(),theme:t.fn()};class g{_executionContext;constructor(o){this._executionContext=o}call(...o){console.debug(`${l.blue(`[${this._executionContext}]`)} ${l.green(`Custom spy is called with these args: ${l.blueBright(o.map(n=>`${n}`).join(", "))}`)}`)}}function v(e){const o=new g(e),n=t.spyOn(o,"call");return{expectToBeCalled:(...s)=>c(n).toHaveBeenCalledWith(s),expectToBeNotCalled:(...s)=>c(n).not.toHaveBeenCalledWith(s),spy:n,callSpy:(...s)=>o.call(s)}}const E=(e,o)=>{t.stubGlobal(e,o)},M={beforeAll:u,afterEach:f},i=(e,o="beforeAll")=>{let n;M[o](()=>n=e()),h(()=>{r(),n?.()})},y=()=>{const e=new p;i(()=>(e.clear(),()=>e.destroy()),"afterEach")};export{C as assertHookRendering,a as assertNotThrowing,b as assertRendering,r as clearMocks,y as injectMatchMediaMock,i as injectMocks,k as mockEnv,x as mockRouter,v as spyFactory,E as stubGlobal,A as twApiMock};
@@ -1,3 +0,0 @@
1
- type PromiseOr<T> = T | Promise<T>;
2
-
3
- export type { PromiseOr as P };
@@ -1,3 +0,0 @@
1
- type PromiseOr<T> = T | Promise<T>;
2
-
3
- export type { PromiseOr as P };