@orieljs/testing 0.1.0-alpha.5 → 0.1.0-alpha.6
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/NOTICE +3 -0
- package/dist/index.d.ts +95 -4
- package/dist/index.js +223 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/NOTICE
CHANGED
|
@@ -7,3 +7,6 @@ This product includes software developed by the Oriel project
|
|
|
7
7
|
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
8
|
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
9
|
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
|
10
|
+
|
|
11
|
+
@orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
|
|
12
|
+
voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
import { Application, ModelInstance, InertiaPage, Encrypter, Session, View, Authenticatable, Container, AuthFactory, ServiceProvider, ServiceProviderClass, DatabaseManager, Row, ExceptionHandler, ViewFactory, Class, Token, EventDispatcher, Listener, PendingBatchOptions, Job, BusDispatcher, PendingChain, PendingBatch, Batch, QueuePayload, QueueManager, Queue, QueueJob, MailManager, Mailable, Address, MailRecipient, Mailer, PendingMail, SentMessage, MailTransport, Notifiable, NotificationDispatcher, Notification, NotificationChannel, Filesystem, PutOptions, UploadedFile, FilesystemManager } from '@orieljs/contracts';
|
|
2
2
|
|
|
3
|
+
/** A date the tests travel to: a Date, an ISO string or milliseconds since the epoch. */
|
|
4
|
+
type TravelDate = Date | string | number;
|
|
5
|
+
/**
|
|
6
|
+
* Laravel's travelTo(): the clock stands at `date` (new Date(), Date.now() and now() all read it) until travelBack().
|
|
7
|
+
* With a callback, it runs there and the clock travels back after it; its result is returned.
|
|
8
|
+
*/
|
|
9
|
+
declare function travelTo(date: TravelDate): void;
|
|
10
|
+
declare function travelTo<R>(date: TravelDate, callback: (date: Date) => R): R;
|
|
11
|
+
/** Laravel's travelBack(): the real clock again. Returns the real time. */
|
|
12
|
+
declare function travelBack(): Date;
|
|
13
|
+
/** Laravel's freezeTime(): holds the clock where it is now. Returns that time, or the callback's result. */
|
|
14
|
+
declare function freezeTime(): Date;
|
|
15
|
+
declare function freezeTime<R>(callback: (date: Date) => R): R;
|
|
16
|
+
/** Laravel's freezeSecond(): freezeTime() at the start of the current second. */
|
|
17
|
+
declare function freezeSecond(): Date;
|
|
18
|
+
declare function freezeSecond<R>(callback: (date: Date) => R): R;
|
|
19
|
+
/** Laravel's travel(5).minutes(): moves the clock on (a negative value moves it back) from where it stands. */
|
|
20
|
+
declare function travel(value: number): Wormhole;
|
|
21
|
+
/**
|
|
22
|
+
* Laravel's Wormhole: each unit moves the clock by `value` of it (months and years overflow as Carbon's do: 31 January
|
|
23
|
+
* plus a month is 3 March), in UTC. With a callback, it runs there, the clock travels back after it, and its result is
|
|
24
|
+
* returned. JavaScript dates hold milliseconds, so there are no microseconds.
|
|
25
|
+
*/
|
|
26
|
+
declare class Wormhole {
|
|
27
|
+
#private;
|
|
28
|
+
readonly value: number;
|
|
29
|
+
constructor(value: number);
|
|
30
|
+
millisecond(): void;
|
|
31
|
+
millisecond<R>(callback: () => R): R;
|
|
32
|
+
milliseconds(): void;
|
|
33
|
+
milliseconds<R>(callback: () => R): R;
|
|
34
|
+
second(): void;
|
|
35
|
+
second<R>(callback: () => R): R;
|
|
36
|
+
seconds(): void;
|
|
37
|
+
seconds<R>(callback: () => R): R;
|
|
38
|
+
minute(): void;
|
|
39
|
+
minute<R>(callback: () => R): R;
|
|
40
|
+
minutes(): void;
|
|
41
|
+
minutes<R>(callback: () => R): R;
|
|
42
|
+
hour(): void;
|
|
43
|
+
hour<R>(callback: () => R): R;
|
|
44
|
+
hours(): void;
|
|
45
|
+
hours<R>(callback: () => R): R;
|
|
46
|
+
day(): void;
|
|
47
|
+
day<R>(callback: () => R): R;
|
|
48
|
+
days(): void;
|
|
49
|
+
days<R>(callback: () => R): R;
|
|
50
|
+
week(): void;
|
|
51
|
+
week<R>(callback: () => R): R;
|
|
52
|
+
weeks(): void;
|
|
53
|
+
weeks<R>(callback: () => R): R;
|
|
54
|
+
month(): void;
|
|
55
|
+
month<R>(callback: () => R): R;
|
|
56
|
+
months(): void;
|
|
57
|
+
months<R>(callback: () => R): R;
|
|
58
|
+
year(): void;
|
|
59
|
+
year<R>(callback: () => R): R;
|
|
60
|
+
years(): void;
|
|
61
|
+
years<R>(callback: () => R): R;
|
|
62
|
+
/** Laravel's Wormhole::back(). */
|
|
63
|
+
static back(): Date;
|
|
64
|
+
}
|
|
65
|
+
|
|
3
66
|
/**
|
|
4
67
|
* Laravel's PendingCommand: `await t.artisan('inspire').expectsOutput('…').assertExitCode(0)`.
|
|
5
68
|
* It runs through ConsoleKernel.call() when awaited (or run()), then checks every expectation against the
|
|
@@ -536,11 +599,28 @@ declare abstract class InteractsWithConsole extends InteractsWithDatabase {
|
|
|
536
599
|
artisan(command: string, parameters?: Record<string, unknown>): PendingCommand;
|
|
537
600
|
}
|
|
538
601
|
|
|
602
|
+
/**
|
|
603
|
+
* Laravel's InteractsWithTime: `t.travelTo(date)`, `t.travel(5).minutes()`, `t.freezeTime()`, `t.travelBack()`.
|
|
604
|
+
* The functions of the same names do the same outside a test case. A test case's tearDown travels back, so each of its
|
|
605
|
+
* tests ends in the real time; with the plain functions, call `travelBack()` in your own `afterEach()` or pass a callback.
|
|
606
|
+
*/
|
|
607
|
+
declare abstract class InteractsWithTime extends InteractsWithConsole {
|
|
608
|
+
travelTo(date: TravelDate): void;
|
|
609
|
+
travelTo<R>(date: TravelDate, callback: (date: Date) => R): R;
|
|
610
|
+
travel(value: number): Wormhole;
|
|
611
|
+
travelBack(): Date;
|
|
612
|
+
freezeTime(): Date;
|
|
613
|
+
freezeTime<R>(callback: (date: Date) => R): R;
|
|
614
|
+
freezeSecond(): Date;
|
|
615
|
+
freezeSecond<R>(callback: (date: Date) => R): R;
|
|
616
|
+
tearDown(): Promise<void>;
|
|
617
|
+
}
|
|
618
|
+
|
|
539
619
|
/**
|
|
540
620
|
* Laravel's TestCase. Extend it in tests/TestCase.ts (override createApplication() and set `static hooks`),
|
|
541
621
|
* then in each file: `const t = TestCase.boot()`, or `TestCase.boot({ uses: [RefreshDatabase] })`.
|
|
542
622
|
*/
|
|
543
|
-
declare abstract class TestCase extends
|
|
623
|
+
declare abstract class TestCase extends InteractsWithTime {
|
|
544
624
|
}
|
|
545
625
|
|
|
546
626
|
/**
|
|
@@ -619,6 +699,8 @@ interface DispatchedEvent {
|
|
|
619
699
|
payload: unknown[];
|
|
620
700
|
}
|
|
621
701
|
type EventFilter<E> = (event: E, payload: unknown[]) => boolean;
|
|
702
|
+
/** A listener as assertListening() expects it: a class, a [class, method] pair, a closure, or Function for any closure. */
|
|
703
|
+
type ExpectedListener = Listener<never> | readonly [Class<object>, string] | FunctionConstructor;
|
|
622
704
|
/**
|
|
623
705
|
* Laravel's Event::fake(): records dispatched events instead of running listeners. With a list, only those
|
|
624
706
|
* events are faked and everything else reaches the original dispatcher (so model events keep working).
|
|
@@ -649,11 +731,17 @@ declare class EventFake implements EventDispatcher {
|
|
|
649
731
|
assertDispatchedTimes<E>(event: Class<E> | string, times?: number): void;
|
|
650
732
|
assertNotDispatched<E>(event: Class<E> | string, callback?: EventFilter<E>): void;
|
|
651
733
|
assertNothingDispatched(): void;
|
|
652
|
-
/**
|
|
653
|
-
|
|
734
|
+
/**
|
|
735
|
+
* Laravel's assertListening(event, listener): the original dispatcher has that listener for the event (a class, a
|
|
736
|
+
* [class, method] pair, the same closure, or Function for any closure; wildcard listeners count for a string event).
|
|
737
|
+
* With only the event, any listener will do.
|
|
738
|
+
*/
|
|
739
|
+
assertListening(event: Class<unknown> | string, listener?: ExpectedListener): void;
|
|
654
740
|
/** The recorded events (objects, or names for string events) that match. */
|
|
655
741
|
dispatched<E>(event: Class<E> | string, callback?: EventFilter<E>): E[];
|
|
656
742
|
hasDispatched(event: Class<unknown> | string): boolean;
|
|
743
|
+
/** The original dispatcher's listeners for the event, as registered, wildcard ones included for a string event. */
|
|
744
|
+
private listenersFor;
|
|
657
745
|
private shouldFake;
|
|
658
746
|
}
|
|
659
747
|
|
|
@@ -807,6 +895,8 @@ declare class MailFake implements MailManager {
|
|
|
807
895
|
mailer(name?: string): Mailer;
|
|
808
896
|
to(recipients: MailRecipient | MailRecipient[]): PendingMail;
|
|
809
897
|
send(mailable: Mailable): Promise<SentMessage | undefined>;
|
|
898
|
+
/** Recorded as sent, never queued, like the real sendNow(). */
|
|
899
|
+
sendNow(mailable: Mailable): Promise<SentMessage | undefined>;
|
|
810
900
|
queue(mailable: Mailable): Promise<void>;
|
|
811
901
|
extend(_transport: string, _factory: (config: Record<string, unknown>) => MailTransport): void;
|
|
812
902
|
/** Sent (not queued) at least once; a number asserts the count; a filter gets (mailable, record). */
|
|
@@ -828,6 +918,7 @@ declare class MailFake implements MailManager {
|
|
|
828
918
|
hasQueued(mailable: Target<Mailable>): boolean;
|
|
829
919
|
private pending;
|
|
830
920
|
private sendVia;
|
|
921
|
+
private sendNowVia;
|
|
831
922
|
private queueVia;
|
|
832
923
|
private record;
|
|
833
924
|
private matching;
|
|
@@ -987,4 +1078,4 @@ declare const FakeFile: {
|
|
|
987
1078
|
image(name: string, width?: number, height?: number): File;
|
|
988
1079
|
};
|
|
989
1080
|
|
|
990
|
-
export { AnonymousNotifiable, AssertableInertia, AssertableJson, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, guessMimeType, inertiaPageOf, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, usingInMemoryDatabase };
|
|
1081
|
+
export { AnonymousNotifiable, AssertableInertia, AssertableJson, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, type ExpectedListener, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, InteractsWithTime, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, type TravelDate, Wormhole, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, freezeSecond, freezeTime, guessMimeType, inertiaPageOf, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, travel, travelBack, travelTo, usingInMemoryDatabase };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
+
// time.ts
|
|
2
|
+
var original;
|
|
3
|
+
var testNow;
|
|
4
|
+
var realDate = () => original ?? globalThis.Date;
|
|
5
|
+
function install() {
|
|
6
|
+
if (original !== void 0) return;
|
|
7
|
+
const Real = original = globalThis.Date;
|
|
8
|
+
const current = () => testNow ?? Real.now();
|
|
9
|
+
const Travelling = new Proxy(Real, {
|
|
10
|
+
construct: (target2, args, newTarget) => Reflect.construct(target2, args.length === 0 ? [current()] : args, newTarget === Travelling ? target2 : newTarget),
|
|
11
|
+
apply: (target2) => new target2(current()).toString(),
|
|
12
|
+
get: (target2, property) => property === "now" ? current : Reflect.get(target2, property, target2)
|
|
13
|
+
});
|
|
14
|
+
globalThis.Date = Travelling;
|
|
15
|
+
}
|
|
16
|
+
function setTestNow(date) {
|
|
17
|
+
const time = new (realDate())(date).getTime();
|
|
18
|
+
if (Number.isNaN(time)) throw new TypeError(`Invalid date: ${String(date)}`);
|
|
19
|
+
install();
|
|
20
|
+
testNow = time;
|
|
21
|
+
return new (realDate())(time);
|
|
22
|
+
}
|
|
23
|
+
function thenTravelBack(callback) {
|
|
24
|
+
let result;
|
|
25
|
+
try {
|
|
26
|
+
result = callback();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
travelBack();
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
if (result instanceof Promise) return result.finally(travelBack);
|
|
32
|
+
travelBack();
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function travelTo(date, callback) {
|
|
36
|
+
const at = setTestNow(date);
|
|
37
|
+
if (callback) return thenTravelBack(() => callback(at));
|
|
38
|
+
}
|
|
39
|
+
function travelBack() {
|
|
40
|
+
if (original !== void 0) globalThis.Date = original;
|
|
41
|
+
original = void 0;
|
|
42
|
+
testNow = void 0;
|
|
43
|
+
return /* @__PURE__ */ new Date();
|
|
44
|
+
}
|
|
45
|
+
function freezeTime(callback) {
|
|
46
|
+
const at = new (realDate())(testNow ?? Date.now());
|
|
47
|
+
if (callback) return travelTo(at, callback);
|
|
48
|
+
travelTo(at);
|
|
49
|
+
return at;
|
|
50
|
+
}
|
|
51
|
+
function freezeSecond(callback) {
|
|
52
|
+
const at = new (realDate())(testNow ?? Date.now());
|
|
53
|
+
at.setMilliseconds(0);
|
|
54
|
+
if (callback) return travelTo(at, callback);
|
|
55
|
+
travelTo(at);
|
|
56
|
+
return at;
|
|
57
|
+
}
|
|
58
|
+
function travel(value) {
|
|
59
|
+
return new Wormhole(value);
|
|
60
|
+
}
|
|
61
|
+
var Wormhole = class {
|
|
62
|
+
constructor(value) {
|
|
63
|
+
this.value = value;
|
|
64
|
+
}
|
|
65
|
+
value;
|
|
66
|
+
millisecond(callback) {
|
|
67
|
+
return this.milliseconds(callback);
|
|
68
|
+
}
|
|
69
|
+
milliseconds(callback) {
|
|
70
|
+
return this.#move((date) => date.setTime(date.getTime() + this.value), callback);
|
|
71
|
+
}
|
|
72
|
+
second(callback) {
|
|
73
|
+
return this.seconds(callback);
|
|
74
|
+
}
|
|
75
|
+
seconds(callback) {
|
|
76
|
+
return this.#move((date) => date.setTime(date.getTime() + this.value * 1e3), callback);
|
|
77
|
+
}
|
|
78
|
+
minute(callback) {
|
|
79
|
+
return this.minutes(callback);
|
|
80
|
+
}
|
|
81
|
+
minutes(callback) {
|
|
82
|
+
return this.#move((date) => date.setTime(date.getTime() + this.value * 6e4), callback);
|
|
83
|
+
}
|
|
84
|
+
hour(callback) {
|
|
85
|
+
return this.hours(callback);
|
|
86
|
+
}
|
|
87
|
+
hours(callback) {
|
|
88
|
+
return this.#move((date) => date.setTime(date.getTime() + this.value * 36e5), callback);
|
|
89
|
+
}
|
|
90
|
+
day(callback) {
|
|
91
|
+
return this.days(callback);
|
|
92
|
+
}
|
|
93
|
+
days(callback) {
|
|
94
|
+
return this.#move((date) => date.setUTCDate(date.getUTCDate() + this.value), callback);
|
|
95
|
+
}
|
|
96
|
+
week(callback) {
|
|
97
|
+
return this.weeks(callback);
|
|
98
|
+
}
|
|
99
|
+
weeks(callback) {
|
|
100
|
+
return this.#move((date) => date.setUTCDate(date.getUTCDate() + this.value * 7), callback);
|
|
101
|
+
}
|
|
102
|
+
month(callback) {
|
|
103
|
+
return this.months(callback);
|
|
104
|
+
}
|
|
105
|
+
months(callback) {
|
|
106
|
+
return this.#move((date) => date.setUTCMonth(date.getUTCMonth() + this.value), callback);
|
|
107
|
+
}
|
|
108
|
+
year(callback) {
|
|
109
|
+
return this.years(callback);
|
|
110
|
+
}
|
|
111
|
+
years(callback) {
|
|
112
|
+
return this.#move((date) => date.setUTCFullYear(date.getUTCFullYear() + this.value), callback);
|
|
113
|
+
}
|
|
114
|
+
/** Laravel's Wormhole::back(). */
|
|
115
|
+
static back() {
|
|
116
|
+
return travelBack();
|
|
117
|
+
}
|
|
118
|
+
#move(step, callback) {
|
|
119
|
+
const date = new (realDate())(testNow ?? Date.now());
|
|
120
|
+
step(date);
|
|
121
|
+
setTestNow(date);
|
|
122
|
+
if (callback) return thenTravelBack(callback);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
1
126
|
// Console/PendingCommand.ts
|
|
2
127
|
import { ConsoleKernel } from "@orieljs/contracts";
|
|
3
128
|
|
|
@@ -1956,14 +2081,40 @@ var InteractsWithConsole = class extends InteractsWithDatabase {
|
|
|
1956
2081
|
}
|
|
1957
2082
|
};
|
|
1958
2083
|
|
|
2084
|
+
// Concerns/InteractsWithTime.ts
|
|
2085
|
+
var InteractsWithTime = class extends InteractsWithConsole {
|
|
2086
|
+
travelTo(date, callback) {
|
|
2087
|
+
return callback ? travelTo(date, callback) : travelTo(date);
|
|
2088
|
+
}
|
|
2089
|
+
travel(value) {
|
|
2090
|
+
return travel(value);
|
|
2091
|
+
}
|
|
2092
|
+
travelBack() {
|
|
2093
|
+
return travelBack();
|
|
2094
|
+
}
|
|
2095
|
+
freezeTime(callback) {
|
|
2096
|
+
return callback ? freezeTime(callback) : freezeTime();
|
|
2097
|
+
}
|
|
2098
|
+
freezeSecond(callback) {
|
|
2099
|
+
return callback ? freezeSecond(callback) : freezeSecond();
|
|
2100
|
+
}
|
|
2101
|
+
async tearDown() {
|
|
2102
|
+
try {
|
|
2103
|
+
await super.tearDown();
|
|
2104
|
+
} finally {
|
|
2105
|
+
travelBack();
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
|
|
1959
2110
|
// TestCase.ts
|
|
1960
|
-
var TestCase = class extends
|
|
2111
|
+
var TestCase = class extends InteractsWithTime {
|
|
1961
2112
|
};
|
|
1962
2113
|
|
|
1963
2114
|
// Fakes/support.ts
|
|
1964
2115
|
import { currentContainer } from "@orieljs/container";
|
|
1965
2116
|
import { facade } from "@orieljs/support";
|
|
1966
|
-
function
|
|
2117
|
+
function install2(token2, fake) {
|
|
1967
2118
|
facade(token2).swap(fake);
|
|
1968
2119
|
return fake;
|
|
1969
2120
|
}
|
|
@@ -1999,6 +2150,24 @@ function isQueueable(job) {
|
|
|
1999
2150
|
|
|
2000
2151
|
// Fakes/EventFake.ts
|
|
2001
2152
|
import { EventDispatcher } from "@orieljs/contracts";
|
|
2153
|
+
import { Str } from "@orieljs/support";
|
|
2154
|
+
var isClass = (value) => typeof value === "function" && typeof value.prototype?.handle === "function";
|
|
2155
|
+
var asPair = (listener) => {
|
|
2156
|
+
if (Array.isArray(listener) && listener.length === 2 && typeof listener[1] === "string") return [listener[0], listener[1]];
|
|
2157
|
+
return isClass(listener) ? [listener, "handle"] : void 0;
|
|
2158
|
+
};
|
|
2159
|
+
function listenerMatches(registered, expected) {
|
|
2160
|
+
if (expected === Function) return typeof registered === "function" && !isClass(registered);
|
|
2161
|
+
const [left, right] = [asPair(registered), asPair(expected)];
|
|
2162
|
+
if (left && right) return left[0] === right[0] && left[1] === right[1];
|
|
2163
|
+
return registered === expected;
|
|
2164
|
+
}
|
|
2165
|
+
function listenerName(listener) {
|
|
2166
|
+
const pair = asPair(listener);
|
|
2167
|
+
if (pair === void 0) return "Closure";
|
|
2168
|
+
const [owner, method] = pair;
|
|
2169
|
+
return Array.isArray(listener) ? `${owner.name}@${method}` : owner.name;
|
|
2170
|
+
}
|
|
2002
2171
|
var EventFake = class _EventFake {
|
|
2003
2172
|
constructor(dispatcher, eventsToFake = [], eventsToDispatch = []) {
|
|
2004
2173
|
this.dispatcher = dispatcher;
|
|
@@ -2011,11 +2180,11 @@ var EventFake = class _EventFake {
|
|
|
2011
2180
|
events = [];
|
|
2012
2181
|
/** Installs the fake (on the current container) and returns it: `const events = EventFake.fake([OrderShipped])`. */
|
|
2013
2182
|
static fake(eventsToFake = []) {
|
|
2014
|
-
return
|
|
2183
|
+
return install2(EventDispatcher, new _EventFake(_EventFake.original(), [eventsToFake].flat()));
|
|
2015
2184
|
}
|
|
2016
2185
|
/** Fakes every event except these. */
|
|
2017
2186
|
static fakeExcept(eventsToDispatch) {
|
|
2018
|
-
return
|
|
2187
|
+
return install2(EventDispatcher, new _EventFake(_EventFake.original(), [], [eventsToDispatch].flat()));
|
|
2019
2188
|
}
|
|
2020
2189
|
static original() {
|
|
2021
2190
|
const current = bound(EventDispatcher);
|
|
@@ -2072,9 +2241,20 @@ var EventFake = class _EventFake {
|
|
|
2072
2241
|
|
|
2073
2242
|
- ${names.join("\n- ")}`);
|
|
2074
2243
|
}
|
|
2075
|
-
/**
|
|
2076
|
-
|
|
2077
|
-
|
|
2244
|
+
/**
|
|
2245
|
+
* Laravel's assertListening(event, listener): the original dispatcher has that listener for the event (a class, a
|
|
2246
|
+
* [class, method] pair, the same closure, or Function for any closure; wildcard listeners count for a string event).
|
|
2247
|
+
* With only the event, any listener will do.
|
|
2248
|
+
*/
|
|
2249
|
+
assertListening(event, listener) {
|
|
2250
|
+
if (listener === void 0) {
|
|
2251
|
+
assert(this.hasListeners(event), `Event [${nameOf(event)}] does not have any listeners.`);
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
assert(
|
|
2255
|
+
this.listenersFor(event).some((registered) => listenerMatches(registered, listener)),
|
|
2256
|
+
`Event [${nameOf(event)}] does not have the [${listenerName(listener)}] listener attached to it`
|
|
2257
|
+
);
|
|
2078
2258
|
}
|
|
2079
2259
|
/** The recorded events (objects, or names for string events) that match. */
|
|
2080
2260
|
dispatched(event, callback) {
|
|
@@ -2083,6 +2263,17 @@ var EventFake = class _EventFake {
|
|
|
2083
2263
|
hasDispatched(event) {
|
|
2084
2264
|
return this.dispatched(event).length > 0;
|
|
2085
2265
|
}
|
|
2266
|
+
/** The original dispatcher's listeners for the event, as registered, wildcard ones included for a string event. */
|
|
2267
|
+
listenersFor(event) {
|
|
2268
|
+
const raw = this.dispatcher?.getRawListeners?.();
|
|
2269
|
+
if (raw === void 0) return [];
|
|
2270
|
+
const listeners = [...raw.get(event) ?? []];
|
|
2271
|
+
if (typeof event !== "string") return listeners;
|
|
2272
|
+
for (const [key, list] of raw) {
|
|
2273
|
+
if (typeof key === "string" && key !== event && key.includes("*") && Str.is(key, event)) listeners.push(...list);
|
|
2274
|
+
}
|
|
2275
|
+
return listeners;
|
|
2276
|
+
}
|
|
2086
2277
|
shouldFake(event) {
|
|
2087
2278
|
if (matchesAny(event, this.eventsToDispatch)) return false;
|
|
2088
2279
|
return this.eventsToFake.length === 0 || matchesAny(event, this.eventsToFake);
|
|
@@ -2140,10 +2331,10 @@ var BusFake = class _BusFake {
|
|
|
2140
2331
|
/** The rest of the chain, by the first job (Bus.chain([a, b, c]) records a with [b, c]). */
|
|
2141
2332
|
chains = /* @__PURE__ */ new Map();
|
|
2142
2333
|
static fake(jobsToFake = []) {
|
|
2143
|
-
return
|
|
2334
|
+
return install2(BusDispatcher, new _BusFake(_BusFake.original(), [jobsToFake].flat()));
|
|
2144
2335
|
}
|
|
2145
2336
|
static fakeExcept(jobsToDispatch) {
|
|
2146
|
-
return
|
|
2337
|
+
return install2(BusDispatcher, new _BusFake(_BusFake.original(), [], [jobsToDispatch].flat()));
|
|
2147
2338
|
}
|
|
2148
2339
|
static original() {
|
|
2149
2340
|
const current = bound(BusDispatcher);
|
|
@@ -2352,10 +2543,10 @@ var QueueFake = class _QueueFake {
|
|
|
2352
2543
|
jobsToPush;
|
|
2353
2544
|
jobs = [];
|
|
2354
2545
|
static fake(jobsToFake = []) {
|
|
2355
|
-
return
|
|
2546
|
+
return install2(QueueManager, new _QueueFake(_QueueFake.original(), [jobsToFake].flat()));
|
|
2356
2547
|
}
|
|
2357
2548
|
static fakeExcept(jobsToPush) {
|
|
2358
|
-
return
|
|
2549
|
+
return install2(QueueManager, new _QueueFake(_QueueFake.original(), [], [jobsToPush].flat()));
|
|
2359
2550
|
}
|
|
2360
2551
|
static original() {
|
|
2361
2552
|
const current = bound(QueueManager);
|
|
@@ -2537,13 +2728,14 @@ var MailFake = class _MailFake {
|
|
|
2537
2728
|
records = [];
|
|
2538
2729
|
static fake() {
|
|
2539
2730
|
const current = bound(MailManager);
|
|
2540
|
-
return
|
|
2731
|
+
return install2(MailManager, new _MailFake(current instanceof _MailFake ? current.manager : current));
|
|
2541
2732
|
}
|
|
2542
2733
|
// MailManager ----------------------------------------------------------------------------------------------
|
|
2543
2734
|
mailer(name) {
|
|
2544
2735
|
return {
|
|
2545
2736
|
to: (recipients) => this.pending(name, recipients),
|
|
2546
2737
|
send: (mailable) => this.sendVia(name, mailable, empty()),
|
|
2738
|
+
sendNow: (mailable) => this.sendNowVia(name, mailable, empty()),
|
|
2547
2739
|
queue: (mailable) => this.queueVia(name, mailable, empty(), void 0)
|
|
2548
2740
|
};
|
|
2549
2741
|
}
|
|
@@ -2553,6 +2745,10 @@ var MailFake = class _MailFake {
|
|
|
2553
2745
|
send(mailable) {
|
|
2554
2746
|
return this.sendVia(void 0, mailable, empty());
|
|
2555
2747
|
}
|
|
2748
|
+
/** Recorded as sent, never queued, like the real sendNow(). */
|
|
2749
|
+
sendNow(mailable) {
|
|
2750
|
+
return this.sendNowVia(void 0, mailable, empty());
|
|
2751
|
+
}
|
|
2556
2752
|
queue(mailable) {
|
|
2557
2753
|
return this.queueVia(void 0, mailable, empty(), void 0);
|
|
2558
2754
|
}
|
|
@@ -2636,6 +2832,7 @@ var MailFake = class _MailFake {
|
|
|
2636
2832
|
return pending;
|
|
2637
2833
|
},
|
|
2638
2834
|
send: (mailable) => this.sendVia(mailer, mailable, overrides),
|
|
2835
|
+
sendNow: (mailable) => this.sendNowVia(mailer, mailable, overrides),
|
|
2639
2836
|
queue: (mailable) => this.queueVia(mailer, mailable, overrides, void 0),
|
|
2640
2837
|
later: (delay, mailable) => this.queueVia(mailer, mailable, overrides, delay)
|
|
2641
2838
|
};
|
|
@@ -2645,6 +2842,10 @@ var MailFake = class _MailFake {
|
|
|
2645
2842
|
await this.record(mailer, mailable, overrides, isQueueable(mailable), void 0);
|
|
2646
2843
|
return void 0;
|
|
2647
2844
|
}
|
|
2845
|
+
async sendNowVia(mailer, mailable, overrides) {
|
|
2846
|
+
await this.record(mailer, mailable, overrides, false, void 0);
|
|
2847
|
+
return void 0;
|
|
2848
|
+
}
|
|
2648
2849
|
async queueVia(mailer, mailable, overrides, delay) {
|
|
2649
2850
|
await this.record(mailer, mailable, overrides, true, delay);
|
|
2650
2851
|
}
|
|
@@ -2719,7 +2920,7 @@ var NotificationFake = class _NotificationFake {
|
|
|
2719
2920
|
notifications = [];
|
|
2720
2921
|
static fake() {
|
|
2721
2922
|
const current = bound(NotificationDispatcher);
|
|
2722
|
-
return
|
|
2923
|
+
return install2(NotificationDispatcher, new _NotificationFake(current instanceof _NotificationFake ? current.dispatcher : current));
|
|
2723
2924
|
}
|
|
2724
2925
|
// NotificationDispatcher -------------------------------------------------------------------------------------
|
|
2725
2926
|
async send(notifiables, notification) {
|
|
@@ -3087,7 +3288,7 @@ var StorageFake = class _StorageFake {
|
|
|
3087
3288
|
static fake(disk) {
|
|
3088
3289
|
const current = bound(FilesystemManager);
|
|
3089
3290
|
const config = bound(ConfigRepository4);
|
|
3090
|
-
const fake = current instanceof _StorageFake ? current :
|
|
3291
|
+
const fake = current instanceof _StorageFake ? current : install2(FilesystemManager, new _StorageFake(current, config?.get("filesystems.default", "local") ?? "local"));
|
|
3091
3292
|
const name = disk ?? fake.defaultDisk;
|
|
3092
3293
|
const faked = new FakeDisk(name);
|
|
3093
3294
|
fake.disks.set(name, faked);
|
|
@@ -3413,6 +3614,7 @@ export {
|
|
|
3413
3614
|
InteractsWithApplication,
|
|
3414
3615
|
InteractsWithConsole,
|
|
3415
3616
|
InteractsWithDatabase,
|
|
3617
|
+
InteractsWithTime,
|
|
3416
3618
|
MailFake,
|
|
3417
3619
|
MailRecord,
|
|
3418
3620
|
MakesHttpRequests,
|
|
@@ -3426,6 +3628,7 @@ export {
|
|
|
3426
3628
|
TESTING_ENVIRONMENT,
|
|
3427
3629
|
TestCase,
|
|
3428
3630
|
TestResponse,
|
|
3631
|
+
Wormhole,
|
|
3429
3632
|
actingAsAuthFactory,
|
|
3430
3633
|
addresses,
|
|
3431
3634
|
applyEnvironment,
|
|
@@ -3434,9 +3637,11 @@ export {
|
|
|
3434
3637
|
decryptCookie,
|
|
3435
3638
|
encryptCookie,
|
|
3436
3639
|
flatten,
|
|
3640
|
+
freezeSecond,
|
|
3641
|
+
freezeTime,
|
|
3437
3642
|
guessMimeType,
|
|
3438
3643
|
inertiaPageOf,
|
|
3439
|
-
install,
|
|
3644
|
+
install2 as install,
|
|
3440
3645
|
isExpired,
|
|
3441
3646
|
isQueueable,
|
|
3442
3647
|
matches,
|
|
@@ -3446,6 +3651,9 @@ export {
|
|
|
3446
3651
|
recordingViewFactory,
|
|
3447
3652
|
responseCookies,
|
|
3448
3653
|
runCommand,
|
|
3654
|
+
travel,
|
|
3655
|
+
travelBack,
|
|
3656
|
+
travelTo,
|
|
3449
3657
|
usingInMemoryDatabase
|
|
3450
3658
|
};
|
|
3451
3659
|
//# sourceMappingURL=index.js.map
|