@orieljs/testing 0.1.0-alpha.1 → 0.1.0-alpha.10

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/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
 
@@ -274,18 +399,7 @@ var DatabaseTransactions = {
274
399
  };
275
400
 
276
401
  // Concerns/MakesHttpRequests.ts
277
- import { AuthFactory as AuthFactory2 } from "@orieljs/contracts";
278
-
279
- // Http/HttpClient.ts
280
- import {
281
- AuthFactory,
282
- ConfigRepository as ConfigRepository2,
283
- Encrypter as Encrypter2,
284
- ExceptionHandler,
285
- HttpKernel,
286
- Session,
287
- ViewFactory
288
- } from "@orieljs/contracts";
402
+ import { AuthFactory as AuthFactory2, token } from "@orieljs/contracts";
289
403
 
290
404
  // environment.ts
291
405
  var TESTING_ENVIRONMENT = Object.freeze({
@@ -311,9 +425,422 @@ function clonePlain(value) {
311
425
  return value;
312
426
  }
313
427
 
428
+ // Http/HttpClient.ts
429
+ import {
430
+ AuthFactory,
431
+ ConfigRepository as ConfigRepository3,
432
+ Encrypter as Encrypter2,
433
+ ExceptionHandler,
434
+ HttpKernel,
435
+ HttpRequest,
436
+ Session,
437
+ ViewFactory
438
+ } from "@orieljs/contracts";
439
+ import { IncomingRequest } from "@orieljs/http";
440
+
314
441
  // TestResponse.ts
315
442
  import { Encrypter, UrlGenerator } from "@orieljs/contracts";
443
+ import { Arr as Arr3 } from "@orieljs/support";
444
+
445
+ // Fluent/AssertableInertia.ts
446
+ import { existsSync } from "fs";
447
+ import { join } from "path";
448
+ import { ConfigRepository as ConfigRepository2 } from "@orieljs/contracts";
449
+ import { Arr as Arr2 } from "@orieljs/support";
450
+
451
+ // Fluent/AssertableJson.ts
316
452
  import { Arr } from "@orieljs/support";
453
+ function typeOf(value) {
454
+ if (value === null) return ["null"];
455
+ if (Array.isArray(value)) return ["array"];
456
+ switch (typeof value) {
457
+ case "string":
458
+ return ["string"];
459
+ case "boolean":
460
+ return ["boolean"];
461
+ case "number":
462
+ return Number.isInteger(value) ? ["integer", "number"] : ["double", "float", "number"];
463
+ case "object":
464
+ return ["array", "object"];
465
+ default:
466
+ return [typeof value];
467
+ }
468
+ }
469
+ var AssertableJson = class _AssertableJson {
470
+ constructor(props, path = void 0) {
471
+ this.props = props;
472
+ this.path = path;
473
+ }
474
+ props;
475
+ path;
476
+ interactedKeys = [];
477
+ static fromJson(json) {
478
+ return new _AssertableJson(json);
479
+ }
480
+ /** A child scope of the same class (subclasses override to keep their extra state out of scopes). */
481
+ newScope(props, path) {
482
+ return new _AssertableJson(props, path);
483
+ }
484
+ dotPath(key = "") {
485
+ if (this.path === void 0) return key;
486
+ return key === "" ? this.path : `${this.path}.${key}`;
487
+ }
488
+ /** The value at `key` in this scope, or the whole scope. */
489
+ prop(key) {
490
+ if (key !== void 0 && this.hasOwnKey(key)) return this.props[key];
491
+ return Arr.get(this.props, key);
492
+ }
493
+ /** A literal key of this scope wins over a dot path, like Laravel's Arr::get (keys such as 'items.0.name'). */
494
+ hasOwnKey(key) {
495
+ return typeof this.props === "object" && this.props !== null && Object.hasOwn(this.props, key);
496
+ }
497
+ exists(key) {
498
+ return this.hasOwnKey(key) || Arr.has(this.props, key);
499
+ }
500
+ interactsWith(key) {
501
+ const prop = this.hasOwnKey(String(key)) ? String(key) : String(key).split(".")[0];
502
+ if (!this.interactedKeys.includes(prop)) this.interactedKeys.push(prop);
503
+ }
504
+ /** Every property of the scope was checked (called when a scope ends). */
505
+ interacted() {
506
+ const props = this.prop();
507
+ const keys = typeof props === "object" && props !== null ? Object.keys(props) : [];
508
+ const unexpected = keys.filter((key) => !this.interactedKeys.includes(key));
509
+ assert(
510
+ unexpected.length === 0,
511
+ this.path === void 0 ? "Unexpected properties were found on the root level." : `Unexpected properties were found in scope [${this.path}].`,
512
+ { actual: unexpected, expected: [] }
513
+ );
514
+ }
515
+ /** Allow the properties this scope didn't check. */
516
+ etc() {
517
+ const props = this.prop();
518
+ this.interactedKeys = typeof props === "object" && props !== null ? Object.keys(props) : [];
519
+ return this;
520
+ }
521
+ // Has ------------------------------------------------------------------------------------------------------
522
+ /** has('key'), has('key', 3), has('key', json => …), has('key', 3, first => …), or has(3) for the root size. */
523
+ has(key, length, callback) {
524
+ if (typeof key === "number" && length === void 0) return this.count(key);
525
+ const name = String(key);
526
+ assert(this.exists(name), `Property [${this.dotPath(name)}] does not exist.`);
527
+ this.interactsWith(name);
528
+ if (callback !== void 0) {
529
+ return this.has(name, (scope) => {
530
+ if (typeof length === "number") scope.count(length);
531
+ scope.first(callback).etc();
532
+ });
533
+ }
534
+ if (typeof length === "function") return this.scope(name, length);
535
+ if (typeof length === "number") return this.count(name, length);
536
+ return this;
537
+ }
538
+ /** hasAll(['a', 'b']) or hasAll({ items: 3 }). */
539
+ hasAll(keys) {
540
+ if (typeof keys === "string" || Array.isArray(keys)) {
541
+ for (const key of [keys].flat()) this.has(key);
542
+ return this;
543
+ }
544
+ for (const [key, length] of Object.entries(keys)) this.has(key, length);
545
+ return this;
546
+ }
547
+ hasAny(keys) {
548
+ const list = [keys].flat();
549
+ const present = list.filter((key) => this.exists(key));
550
+ assert(present.length > 0, `None of properties [${list.map((key) => this.dotPath(key)).join(", ")}] exist.`);
551
+ for (const key of present) this.interactsWith(key);
552
+ return this;
553
+ }
554
+ missing(key) {
555
+ assert(!this.exists(key), `Property [${this.dotPath(key)}] was found while it was expected to be missing.`);
556
+ return this;
557
+ }
558
+ missingAll(keys) {
559
+ for (const key of [keys].flat()) this.missing(key);
560
+ return this;
561
+ }
562
+ /** count(3) checks this scope's size; count('items', 3) a property's. */
563
+ count(key, length) {
564
+ if (typeof key === "number") {
565
+ const size2 = sizeOf(this.prop());
566
+ assert(size2 === key, this.path === void 0 ? "Root level does not have the expected size." : `Property [${this.path}] does not have the expected size.`, { actual: size2, expected: key });
567
+ return this;
568
+ }
569
+ this.has(key);
570
+ const size = sizeOf(this.prop(key));
571
+ assert(size === length, `Property [${this.dotPath(key)}] does not have the expected size.`, { actual: size, expected: length });
572
+ return this;
573
+ }
574
+ countBetween(key, min, max) {
575
+ this.has(key);
576
+ const size = sizeOf(this.prop(key));
577
+ assert(size >= min && size <= max, `Property [${this.dotPath(key)}] size is not between ${min} and ${max}.`, { actual: size });
578
+ return this;
579
+ }
580
+ // Matching -------------------------------------------------------------------------------------------------
581
+ /** where('name', 'Ann'), or where('name', value => value.startsWith('A')). Objects compare ignoring key order. */
582
+ where(key, expected) {
583
+ this.has(key);
584
+ const actual = this.prop(key);
585
+ if (typeof expected === "function") {
586
+ assert(expected(actual), `Property [${this.dotPath(key)}] was marked as invalid using a closure.`);
587
+ return this;
588
+ }
589
+ const normalized = toPlain(expected);
590
+ assert(equals(normalized, actual), `Property [${this.dotPath(key)}] does not match the expected value.`, { actual, expected: normalized });
591
+ return this;
592
+ }
593
+ whereNot(key, expected) {
594
+ this.has(key);
595
+ const actual = this.prop(key);
596
+ if (typeof expected === "function") {
597
+ assert(!expected(actual), `Property [${this.dotPath(key)}] was marked as invalid using a closure.`);
598
+ return this;
599
+ }
600
+ assert(!equals(toPlain(expected), actual), `Property [${this.dotPath(key)}] contains a value that should be missing: [${key}, ${format(expected)}]`);
601
+ return this;
602
+ }
603
+ whereNull(key) {
604
+ this.has(key);
605
+ const actual = this.prop(key);
606
+ assert(actual === null, `Property [${this.dotPath(key)}] should be null.`, { actual, expected: null });
607
+ return this;
608
+ }
609
+ whereNotNull(key) {
610
+ this.has(key);
611
+ assert(this.prop(key) !== null, `Property [${this.dotPath(key)}] should not be null.`);
612
+ return this;
613
+ }
614
+ whereAll(bindings) {
615
+ for (const [key, value] of Object.entries(bindings)) this.where(key, value);
616
+ return this;
617
+ }
618
+ /** whereType('id', 'integer'), whereType('name', 'string|null'), whereType('tags', ['array', 'null']). */
619
+ whereType(key, expected) {
620
+ this.has(key);
621
+ const types = typeof expected === "string" ? expected.split("|") : expected;
622
+ const actual = typeOf(this.prop(key));
623
+ assert(
624
+ types.some((type) => actual.includes(type)),
625
+ `Property [${this.dotPath(key)}] is not of expected type [${types.join("|")}].`,
626
+ { actual: actual[0], expected: types.join("|") }
627
+ );
628
+ return this;
629
+ }
630
+ whereAllType(bindings) {
631
+ for (const [key, type] of Object.entries(bindings)) this.whereType(key, type);
632
+ return this;
633
+ }
634
+ /** The list contains every expected value (or one passing the callback); a string contains the substring. */
635
+ whereContains(key, expected) {
636
+ this.has(key);
637
+ const actual = this.prop(key);
638
+ if (typeof actual === "string") {
639
+ assert(actual.includes(String(expected)), `Property [${this.dotPath(key)}] does not contain [${format(expected)}].`);
640
+ return this;
641
+ }
642
+ const values = typeof actual === "object" && actual !== null ? Object.values(actual) : [actual];
643
+ const wanted = Array.isArray(expected) ? expected : [expected];
644
+ const missing = wanted.filter(
645
+ (item) => typeof item === "function" ? !values.some((value) => item(value)) : !values.some((value) => equals(toPlain(item), value))
646
+ );
647
+ assert(missing.length === 0, `Property [${this.dotPath(key)}] does not contain [${missing.map(format).join(", ")}].`, { actual });
648
+ return this;
649
+ }
650
+ // Scoping --------------------------------------------------------------------------------------------------
651
+ scope(key, callback) {
652
+ const props = this.prop(key);
653
+ const path = this.dotPath(key);
654
+ assert(typeof props === "object" && props !== null, `Property [${path}] is not scopeable.`);
655
+ const scope = this.newScope(props, path);
656
+ callback(scope);
657
+ scope.interacted();
658
+ return this;
659
+ }
660
+ first(callback) {
661
+ const props = this.prop();
662
+ const keys = typeof props === "object" && props !== null ? Object.keys(props) : [];
663
+ if (keys.length === 0) {
664
+ fail(this.path === void 0 ? "Cannot scope directly onto the first element of the root level because it is empty." : `Cannot scope directly onto the first element of property [${this.path}] because it is empty.`);
665
+ }
666
+ this.interactsWith(keys[0]);
667
+ return this.scope(keys[0], callback);
668
+ }
669
+ each(callback) {
670
+ const props = this.prop();
671
+ const keys = typeof props === "object" && props !== null ? Object.keys(props) : [];
672
+ if (keys.length === 0) {
673
+ fail(this.path === void 0 ? "Cannot scope directly onto each element of the root level because it is empty." : `Cannot scope directly onto each element of property [${this.path}] because it is empty.`);
674
+ }
675
+ for (const key of keys) {
676
+ this.interactsWith(key);
677
+ this.scope(key, callback);
678
+ }
679
+ return this;
680
+ }
681
+ // Helpers --------------------------------------------------------------------------------------------------
682
+ when(condition, callback, otherwise) {
683
+ if (condition) callback(this);
684
+ else otherwise?.(this);
685
+ return this;
686
+ }
687
+ dump(key) {
688
+ console.log(format(this.prop(key)));
689
+ return this;
690
+ }
691
+ toArray() {
692
+ return this.prop();
693
+ }
694
+ };
695
+ function sizeOf(value) {
696
+ if (Array.isArray(value)) return value.length;
697
+ if (typeof value === "object" && value !== null) return Object.keys(value).length;
698
+ if (typeof value === "string") return value.length;
699
+ return 0;
700
+ }
701
+ function toPlain(value) {
702
+ return value === void 0 ? void 0 : JSON.parse(JSON.stringify(value));
703
+ }
704
+
705
+ // Fluent/AssertableInertia.ts
706
+ function inertiaPageOf(response) {
707
+ let page;
708
+ try {
709
+ if (response.headers.has("X-Inertia")) page = JSON.parse(response.content);
710
+ else {
711
+ const match = /<script data-page="[^"]*" type="application\/json">([\s\S]*?)<\/script>/.exec(response.content);
712
+ page = match === null ? void 0 : JSON.parse(match[1]);
713
+ }
714
+ } catch {
715
+ page = void 0;
716
+ }
717
+ const valid = typeof page === "object" && page !== null && ["component", "props", "url", "version"].every((key) => Object.hasOwn(page, key));
718
+ if (!valid) fail("Not a valid Inertia response.");
719
+ return page;
720
+ }
721
+ var AssertableInertia = class _AssertableInertia extends AssertableJson {
722
+ #page;
723
+ #response;
724
+ static fromTestResponse(response) {
725
+ const page = inertiaPageOf(response);
726
+ const instance = new _AssertableInertia(page.props);
727
+ instance.#page = page;
728
+ instance.#response = response;
729
+ return instance;
730
+ }
731
+ /** Scopes are plain AssertableJson: the page-level methods only make sense at the root. */
732
+ newScope(props, path) {
733
+ return new AssertableJson(props, path);
734
+ }
735
+ get page() {
736
+ if (this.#page === void 0) fail("This assertion is only available on the page root.");
737
+ return this.#page;
738
+ }
739
+ /** The component name; the page file must exist unless `shouldExist` is false (inertia.testing.ensure_pages_exist). */
740
+ component(value, shouldExist) {
741
+ const actual = this.page.component;
742
+ assert(actual === value, "Unexpected Inertia page component.", { actual, expected: value });
743
+ const app = this.#app();
744
+ const config = app?.bound(ConfigRepository2) ? app.make(ConfigRepository2) : void 0;
745
+ if (shouldExist === true || shouldExist === void 0 && config?.get("inertia.testing.ensure_pages_exist", true) !== false) {
746
+ const paths = config?.get("inertia.pages.paths", []) ?? [];
747
+ const extensions = config?.get("inertia.pages.extensions", []) ?? [];
748
+ const exists = paths.some((path) => extensions.some((extension) => existsSync(join(path, `${value}.${extension}`))));
749
+ if (!exists) fail(`Inertia page component file [${value}] does not exist.`);
750
+ }
751
+ return this;
752
+ }
753
+ url(value) {
754
+ assert(this.page.url === value, "Unexpected Inertia page url.", { actual: this.page.url, expected: value });
755
+ return this;
756
+ }
757
+ version(value) {
758
+ assert(this.page.version === value, "Unexpected Inertia asset version.", { actual: this.page.version, expected: value });
759
+ return this;
760
+ }
761
+ /** The flash data has `key` (dot paths allowed), equal to `expected` when given. */
762
+ hasFlash(key, ...expected) {
763
+ _AssertableInertia.assertFlashHas(this.page.flash ?? {}, key, ...expected);
764
+ return this;
765
+ }
766
+ missingFlash(key) {
767
+ _AssertableInertia.assertFlashMissing(this.page.flash ?? {}, key);
768
+ return this;
769
+ }
770
+ static assertFlashHas(flash, key, ...expected) {
771
+ assert(Arr2.has(flash, key), `Inertia Flash Data is missing key [${key}].`);
772
+ if (expected.length > 0) {
773
+ const actual = Arr2.get(flash, key);
774
+ assert(equals(actual, expected[0]), `Inertia Flash Data [${key}] does not match expected value.`, { actual, expected: expected[0] });
775
+ }
776
+ }
777
+ static assertFlashMissing(flash, key) {
778
+ assert(!Arr2.has(flash, key), `Inertia Flash Data has unexpected key [${key}].`);
779
+ }
780
+ /**
781
+ * Requests the page again as a partial reload (only/except) and checks it is the same page. Uses the test's
782
+ * HTTP client, so the session and cookies carry over.
783
+ */
784
+ async reload(callback, only, except) {
785
+ const client = this.#response?.context.client;
786
+ if (client === void 0) fail("reload() needs a response from the test HTTP client.");
787
+ const headers = {
788
+ "X-Inertia": "true",
789
+ "X-Requested-With": "XMLHttpRequest",
790
+ "X-Inertia-Version": this.page.version
791
+ };
792
+ const onlyList = only === void 0 ? void 0 : [only].flat().join(",");
793
+ const exceptList = except === void 0 ? void 0 : [except].flat().join(",");
794
+ if (onlyList !== void 0 || exceptList !== void 0) headers["X-Inertia-Partial-Component"] = this.page.component;
795
+ if (onlyList !== void 0) headers["X-Inertia-Partial-Data"] = onlyList;
796
+ if (exceptList !== void 0) headers["X-Inertia-Partial-Except"] = exceptList;
797
+ const response = await client.request("GET", this.page.url, { headers });
798
+ const reloaded = _AssertableInertia.fromTestResponse(response);
799
+ reloaded.component(this.page.component, false).url(this.page.url).version(this.page.version);
800
+ await callback?.(reloaded);
801
+ return this;
802
+ }
803
+ reloadOnly(only, callback) {
804
+ return this.reload(
805
+ async (page) => {
806
+ page.hasAll(typeof only === "string" ? only.split(",") : only);
807
+ await callback?.(page);
808
+ },
809
+ only
810
+ );
811
+ }
812
+ reloadExcept(except, callback) {
813
+ return this.reload(
814
+ async (page) => {
815
+ page.missingAll(typeof except === "string" ? except.split(",") : except);
816
+ await callback?.(page);
817
+ },
818
+ void 0,
819
+ except
820
+ );
821
+ }
822
+ /** Loads the deferred props of every group (or the given groups) in one partial reload. */
823
+ loadDeferredProps(groupsOrCallback, callback) {
824
+ const deferred = this.page.deferredProps ?? {};
825
+ const groups = typeof groupsOrCallback === "function" ? Object.keys(deferred) : [groupsOrCallback].flat();
826
+ const props = groups.flatMap((group) => deferred[group] ?? []);
827
+ return this.reloadOnly(props.join(","), typeof groupsOrCallback === "function" ? groupsOrCallback : callback);
828
+ }
829
+ toArray() {
830
+ return {
831
+ component: this.page.component,
832
+ props: this.prop(),
833
+ url: this.page.url,
834
+ version: this.page.version,
835
+ flash: this.page.flash ?? {},
836
+ ...this.page.encryptHistory === true ? { encryptHistory: true } : {},
837
+ ...this.page.clearHistory === true ? { clearHistory: true } : {}
838
+ };
839
+ }
840
+ #app() {
841
+ return this.#response?.context.app;
842
+ }
843
+ };
317
844
 
318
845
  // Http/cookies.ts
319
846
  import { createHmac } from "crypto";
@@ -413,7 +940,7 @@ var TestResponse = class _TestResponse {
413
940
  ${this.excerpt()}`);
414
941
  }
415
942
  }
416
- return Arr.get(this.decoded.value, path);
943
+ return Arr3.get(this.decoded.value, path);
417
944
  }
418
945
  dump(path) {
419
946
  console.log(path === void 0 ? this.content : this.json(path));
@@ -591,12 +1118,44 @@ ${this.excerpt(text)}`);
591
1118
  return this.inOrder(stripTags(this.content), this.needles(values, escape));
592
1119
  }
593
1120
  // JSON --------------------------------------------------------------------------------------------------
594
- /** The response JSON contains `data` (a subset match: extra keys in the response are fine). */
1121
+ /**
1122
+ * The response JSON contains `data` (a subset match: extra keys in the response are fine), or fluent
1123
+ * assertions: assertJson(json => json.has('data', 3).etc()).
1124
+ */
595
1125
  assertJson(data) {
1126
+ if (typeof data === "function") {
1127
+ const json = AssertableJson.fromJson(this.json());
1128
+ data(json);
1129
+ if (!Array.isArray(json.toArray())) json.interacted();
1130
+ return this;
1131
+ }
596
1132
  const actual = this.json();
597
1133
  assert(isSubset(data, actual), "Unable to find the expected JSON subset in the response.", { actual, expected: data });
598
1134
  return this;
599
1135
  }
1136
+ assertInertia(callback) {
1137
+ const page = AssertableInertia.fromTestResponse(this);
1138
+ const result = callback?.(page);
1139
+ if (typeof result?.then === "function") return Promise.resolve(result).then(() => this);
1140
+ return this;
1141
+ }
1142
+ /** The Inertia page object of this response. */
1143
+ inertiaPage() {
1144
+ return inertiaPageOf(this);
1145
+ }
1146
+ /** The page props, or one prop by dot path. */
1147
+ inertiaProps(key) {
1148
+ return Arr3.get(inertiaPageOf(this).props, key);
1149
+ }
1150
+ /** Inertia flash data waiting in the session for the next page (after a redirect). */
1151
+ assertInertiaFlash(key, ...expected) {
1152
+ AssertableInertia.assertFlashHas(this.session().get("inertia.flash_data", {}), key, ...expected);
1153
+ return this;
1154
+ }
1155
+ assertInertiaFlashMissing(key) {
1156
+ AssertableInertia.assertFlashMissing(this.session().get("inertia.flash_data", {}), key);
1157
+ return this;
1158
+ }
600
1159
  /** The response JSON equals `data` exactly (object key order is ignored). */
601
1160
  assertExactJson(data) {
602
1161
  const actual = this.json();
@@ -605,7 +1164,7 @@ ${this.excerpt(text)}`);
605
1164
  }
606
1165
  /** The value at `path` equals `expected` (strictly), or passes the predicate. */
607
1166
  assertJsonPath(path, expected) {
608
- assert(Arr.has(this.json(), path), `Failed asserting that the JSON has the path [${path}].`, { actual: this.json() });
1167
+ assert(Arr3.has(this.json(), path), `Failed asserting that the JSON has the path [${path}].`, { actual: this.json() });
609
1168
  const actual = this.json(path);
610
1169
  if (typeof expected === "function") {
611
1170
  assert(expected(actual) === true, `Failed asserting that the value at [${path}] passes the given check (got ${format(actual)}).`);
@@ -615,7 +1174,7 @@ ${this.excerpt(text)}`);
615
1174
  return this;
616
1175
  }
617
1176
  assertJsonMissingPath(path) {
618
- assert(!Arr.has(this.json(), path), `Failed asserting that the JSON does not have the path [${path}].`);
1177
+ assert(!Arr3.has(this.json(), path), `Failed asserting that the JSON does not have the path [${path}].`);
619
1178
  return this;
620
1179
  }
621
1180
  /** Each key/value pair appears somewhere in the JSON (Laravel's assertJsonFragment). */
@@ -665,7 +1224,7 @@ ${this.excerpt()}`);
665
1224
  /** No validation errors in the JSON (or none for these keys). */
666
1225
  assertJsonMissingValidationErrors(keys, responseKey = "errors") {
667
1226
  if (this.content === "") return this;
668
- const errors = Arr.get(this.json(), responseKey);
1227
+ const errors = Arr3.get(this.json(), responseKey);
669
1228
  if (errors === void 0 || errors === null) return this;
670
1229
  const unexpected = keys === void 0 ? Object.keys(errors) : [keys].flat().filter((key) => Object.hasOwn(errors, key));
671
1230
  assert(unexpected.length === 0, `Found unexpected validation error(s) for [${unexpected.join(", ")}]: ${format(errors)}`);
@@ -827,8 +1386,8 @@ ${JSON.stringify(errors, null, 2)}`, { actual: errors, expected: {} });
827
1386
  assertViewHas(key, value) {
828
1387
  if (typeof key !== "string") return this.assertViewHasAll(key);
829
1388
  const data = this.viewDataOf(this.ensureView());
830
- assert(Arr.has(data, key), `Failed asserting that the view has key [${key}].`, { actual: Object.keys(data) });
831
- const actual = Arr.get(data, key);
1389
+ assert(Arr3.has(data, key), `Failed asserting that the view has key [${key}].`, { actual: Object.keys(data) });
1390
+ const actual = Arr3.get(data, key);
832
1391
  if (typeof value === "function") assert(value(actual) === true, `View data [${key}] does not pass the given check.`);
833
1392
  else if (value !== void 0) assert(equals(actual, value), `View data [${key}] does not match the expected value.`, { actual, expected: value });
834
1393
  return this;
@@ -839,12 +1398,12 @@ ${JSON.stringify(errors, null, 2)}`, { actual: errors, expected: {} });
839
1398
  return this;
840
1399
  }
841
1400
  assertViewMissing(key) {
842
- assert(!Arr.has(this.viewDataOf(this.ensureView()), key), `Failed asserting that the view does not have key [${key}].`);
1401
+ assert(!Arr3.has(this.viewDataOf(this.ensureView()), key), `Failed asserting that the view does not have key [${key}].`);
843
1402
  return this;
844
1403
  }
845
1404
  /** The data the view received (dot path), or all of it. */
846
1405
  viewData(key) {
847
- return Arr.get(this.viewDataOf(this.ensureView()), key);
1406
+ return Arr3.get(this.viewDataOf(this.ensureView()), key);
848
1407
  }
849
1408
  // Internals ---------------------------------------------------------------------------------------------
850
1409
  absolute(url) {
@@ -990,6 +1549,11 @@ var HttpClient = class {
990
1549
  defaultGuard;
991
1550
  /** Session attributes carried from one request to the next (Laravel keeps one session store per test). */
992
1551
  session;
1552
+ /**
1553
+ * withSession() and flushSession() since the last started session: applied to the stored session (the one the
1554
+ * session cookie points to) once the next request starts it, so they win over what it holds, as in Laravel.
1555
+ */
1556
+ sessionChanges = [];
993
1557
  /** from(url): the session's previous URL for the next request only (Laravel sets it once). */
994
1558
  previousUrl;
995
1559
  /** Requests whose actingAs users reached the guards (the AuthFactory they went through). */
@@ -1012,13 +1576,39 @@ var HttpClient = class {
1012
1576
  return fn(scope);
1013
1577
  });
1014
1578
  }
1579
+ /**
1580
+ * Runs `run` in a request scope like this client's requests have (a request for `method uri` bound, the carried
1581
+ * session, actingAs users), then carries the session and the users on, as after a request. Live.test() runs its
1582
+ * mount and updates through it.
1583
+ */
1584
+ async withinRequest(run, method = "GET", uri = "/") {
1585
+ await this.app.boot();
1586
+ const request = this.buildRequest(method, uri, {});
1587
+ setClientAddress(request, "127.0.0.1");
1588
+ const scope = this.app.createScope();
1589
+ const context = { request, app: this.app, client: this };
1590
+ const result = await scope.run(async () => {
1591
+ this.beforeRequest(scope, context);
1592
+ if (context.session !== void 0) this.applyPending(context.session);
1593
+ scope.instance(HttpRequest, new IncomingRequest(request));
1594
+ if (scope.bound(AuthFactory)) {
1595
+ try {
1596
+ await scope.make(AuthFactory).guard().check();
1597
+ } catch {
1598
+ }
1599
+ }
1600
+ return run();
1601
+ });
1602
+ await scope.run(() => this.afterRequest(scope, context));
1603
+ return result;
1604
+ }
1015
1605
  /** Runs the request through the app's real HttpKernel, in a request scope this client owns. */
1016
1606
  async send(request) {
1017
1607
  const app = this.app;
1018
1608
  await app.boot();
1019
1609
  setClientAddress(request, "127.0.0.1");
1020
1610
  const scope = app.createScope();
1021
- const context = { request, app };
1611
+ const context = { request, app, client: this };
1022
1612
  const response = await scope.run(async () => {
1023
1613
  await this.beforeRequest(scope, context);
1024
1614
  this.previousUrl = void 0;
@@ -1040,6 +1630,7 @@ var HttpClient = class {
1040
1630
  const session = this.scopeSession(scope);
1041
1631
  if (session !== void 0) {
1042
1632
  if (this.session !== void 0) session.put(clonePlain(this.session));
1633
+ if (this.sessionChanges.length > 0) this.applyOnStart(session);
1043
1634
  if (this.previousUrl !== void 0) session.setPreviousUrl(this.previousUrl);
1044
1635
  context.session = session;
1045
1636
  }
@@ -1072,6 +1663,20 @@ var HttpClient = class {
1072
1663
  else this.users.set(guard, user);
1073
1664
  }
1074
1665
  }
1666
+ /** Applies the pending withSession()/flushSession() changes once the session has loaded what it stored. */
1667
+ applyOnStart(session) {
1668
+ const start = session.start.bind(session);
1669
+ session.start = async () => {
1670
+ await start();
1671
+ this.applyPending(session);
1672
+ };
1673
+ }
1674
+ /** Applies the pending withSession()/flushSession() changes to the session, once. */
1675
+ applyPending(session) {
1676
+ if (this.sessionChanges.length === 0) return;
1677
+ for (const change of this.sessionChanges.splice(0)) change(session);
1678
+ if (!session.has("_token")) session.regenerateToken();
1679
+ }
1075
1680
  /** The request's (scoped) Session, created now so the carried attributes are in place before StartSession. */
1076
1681
  scopeSession(scope) {
1077
1682
  if (!scope.bound(Session)) return void 0;
@@ -1110,7 +1715,7 @@ var HttpClient = class {
1110
1715
  return new Request(url, { method: verb, headers, body });
1111
1716
  }
1112
1717
  baseUrl() {
1113
- const configured = this.app.bound(ConfigRepository2) ? this.app.make(ConfigRepository2).get("app.url") : void 0;
1718
+ const configured = this.app.bound(ConfigRepository3) ? this.app.make(ConfigRepository3).get("app.url") : void 0;
1114
1719
  return typeof configured === "string" && configured !== "" ? configured : "http://localhost";
1115
1720
  }
1116
1721
  cookieHeader() {
@@ -1156,7 +1761,7 @@ import {
1156
1761
  DatabaseManager as DatabaseManager2
1157
1762
  } from "@orieljs/contracts";
1158
1763
  import { Container } from "@orieljs/container";
1159
- import { Application as FoundationApplication } from "@orieljs/foundation";
1764
+ import { Application as FoundationApplication, Vite, ViteHtml } from "@orieljs/foundation";
1160
1765
  var globalHooks = () => {
1161
1766
  const g = globalThis;
1162
1767
  return typeof g.beforeEach === "function" && typeof g.afterEach === "function" ? { beforeEach: g.beforeEach, afterEach: g.afterEach } : void 0;
@@ -1237,11 +1842,43 @@ var InteractsWithApplication = class {
1237
1842
  if (global === app) Container.setInstance(void 0);
1238
1843
  }
1239
1844
  }
1845
+ /**
1846
+ * Laravel's withoutVite(): in this test's requests vite([...]) and viteReactRefresh() render nothing, so feature
1847
+ * tests of pages pass before `vite build` has written public/build/manifest.json.
1848
+ */
1849
+ withoutVite() {
1850
+ const app = this.app;
1851
+ app.scoped(Vite, () => new WithoutVite(app));
1852
+ return this;
1853
+ }
1240
1854
  /** Runs in tearDown(), before the application is thrown away (in registration order). */
1241
1855
  beforeApplicationDestroyed(callback) {
1242
1856
  this.destroying.push(callback);
1243
1857
  }
1244
1858
  };
1859
+ var WithoutVite = class extends Vite {
1860
+ tags() {
1861
+ return new ViteHtml("");
1862
+ }
1863
+ reactRefresh() {
1864
+ return void 0;
1865
+ }
1866
+ asset() {
1867
+ return "";
1868
+ }
1869
+ content() {
1870
+ return "";
1871
+ }
1872
+ manifestHash() {
1873
+ return void 0;
1874
+ }
1875
+ preloadedAssets() {
1876
+ return {};
1877
+ }
1878
+ toHtml() {
1879
+ return "";
1880
+ }
1881
+ };
1245
1882
  async function disconnectAll(db) {
1246
1883
  const manager = db;
1247
1884
  if (typeof manager.disconnectAll === "function") await manager.disconnectAll();
@@ -1258,6 +1895,11 @@ var MakesHttpRequests = class extends InteractsWithApplication {
1258
1895
  createHttpClient() {
1259
1896
  return new HttpClient(this.app);
1260
1897
  }
1898
+ /** Live.test() runs in this test's request scope (Live reads the same token: no import between the packages). */
1899
+ async setUp() {
1900
+ await super.setUp();
1901
+ this.app.instance(token("Testing.RequestScope"), (run) => this.http.withinRequest(run));
1902
+ }
1261
1903
  async tearDown() {
1262
1904
  try {
1263
1905
  await super.tearDown();
@@ -1273,8 +1915,8 @@ var MakesHttpRequests = class extends InteractsWithApplication {
1273
1915
  this.http.headers[name] = value;
1274
1916
  return this;
1275
1917
  }
1276
- withToken(token, type = "Bearer") {
1277
- return this.withHeader("Authorization", `${type} ${token}`);
1918
+ withToken(token2, type = "Bearer") {
1919
+ return this.withHeader("Authorization", `${type} ${token2}`);
1278
1920
  }
1279
1921
  withBasicAuth(username, password) {
1280
1922
  return this.withToken(Buffer.from(`${username}:${password}`).toString("base64"), "Basic");
@@ -1309,14 +1951,17 @@ var MakesHttpRequests = class extends InteractsWithApplication {
1309
1951
  this.http.previousUrl = url;
1310
1952
  return this.withHeader("Referer", url);
1311
1953
  }
1312
- /** Puts data in the session for the following requests (Laravel's withSession()). */
1954
+ /** Puts data in the session for the following requests, over what the stored session holds (Laravel's withSession()). */
1313
1955
  withSession(data) {
1314
- this.http.session = { ...this.http.session, ...data };
1956
+ const values = clonePlain(data);
1957
+ this.http.session = { ...this.http.session, ...values };
1958
+ this.http.sessionChanges.push((session) => session.put(clonePlain(values)));
1315
1959
  return this;
1316
1960
  }
1317
- /** Empties the session carried between requests. */
1961
+ /** Empties the session, the stored one included, so the next request starts with none (Laravel's flushSession()). */
1318
1962
  flushSession() {
1319
1963
  this.http.session = {};
1964
+ this.http.sessionChanges.splice(0, Infinity, (session) => session.flush());
1320
1965
  return this;
1321
1966
  }
1322
1967
  /** Every following request is authenticated as `user` on `guard` (which also becomes the default guard). */
@@ -1460,20 +2105,46 @@ var InteractsWithConsole = class extends InteractsWithDatabase {
1460
2105
  }
1461
2106
  };
1462
2107
 
2108
+ // Concerns/InteractsWithTime.ts
2109
+ var InteractsWithTime = class extends InteractsWithConsole {
2110
+ travelTo(date, callback) {
2111
+ return callback ? travelTo(date, callback) : travelTo(date);
2112
+ }
2113
+ travel(value) {
2114
+ return travel(value);
2115
+ }
2116
+ travelBack() {
2117
+ return travelBack();
2118
+ }
2119
+ freezeTime(callback) {
2120
+ return callback ? freezeTime(callback) : freezeTime();
2121
+ }
2122
+ freezeSecond(callback) {
2123
+ return callback ? freezeSecond(callback) : freezeSecond();
2124
+ }
2125
+ async tearDown() {
2126
+ try {
2127
+ await super.tearDown();
2128
+ } finally {
2129
+ travelBack();
2130
+ }
2131
+ }
2132
+ };
2133
+
1463
2134
  // TestCase.ts
1464
- var TestCase = class extends InteractsWithConsole {
2135
+ var TestCase = class extends InteractsWithTime {
1465
2136
  };
1466
2137
 
1467
2138
  // Fakes/support.ts
1468
2139
  import { currentContainer } from "@orieljs/container";
1469
2140
  import { facade } from "@orieljs/support";
1470
- function install(token, fake) {
1471
- facade(token).swap(fake);
2141
+ function install2(token2, fake) {
2142
+ facade(token2).swap(fake);
1472
2143
  return fake;
1473
2144
  }
1474
- function bound(token) {
2145
+ function bound(token2) {
1475
2146
  const container = currentContainer();
1476
- return container !== void 0 && container.bound(token) ? container.make(token) : void 0;
2147
+ return container !== void 0 && container.bound(token2) ? container.make(token2) : void 0;
1477
2148
  }
1478
2149
  function nameOf(target2) {
1479
2150
  if (typeof target2 === "string") return target2;
@@ -1496,13 +2167,31 @@ var QUEUE_OPTIONS = ["connection", "queue", "delay", "tries", "backoff", "timeou
1496
2167
  function isQueueable(job) {
1497
2168
  if (typeof job !== "object" || job === null) return false;
1498
2169
  const members = job;
1499
- if (members[SHOULD_QUEUE] === true) return true;
2170
+ if (members.shouldQueue === true || members[SHOULD_QUEUE] === true) return true;
1500
2171
  if (QUEUE_OPTIONS.some((option) => members[option] !== void 0)) return true;
1501
2172
  return typeof members.uniqueId === "function" || typeof members.retryUntil === "function";
1502
2173
  }
1503
2174
 
1504
2175
  // Fakes/EventFake.ts
1505
2176
  import { EventDispatcher } from "@orieljs/contracts";
2177
+ import { Str } from "@orieljs/support";
2178
+ var isClass = (value) => typeof value === "function" && typeof value.prototype?.handle === "function";
2179
+ var asPair = (listener) => {
2180
+ if (Array.isArray(listener) && listener.length === 2 && typeof listener[1] === "string") return [listener[0], listener[1]];
2181
+ return isClass(listener) ? [listener, "handle"] : void 0;
2182
+ };
2183
+ function listenerMatches(registered, expected) {
2184
+ if (expected === Function) return typeof registered === "function" && !isClass(registered);
2185
+ const [left, right] = [asPair(registered), asPair(expected)];
2186
+ if (left && right) return left[0] === right[0] && left[1] === right[1];
2187
+ return registered === expected;
2188
+ }
2189
+ function listenerName(listener) {
2190
+ const pair = asPair(listener);
2191
+ if (pair === void 0) return "Closure";
2192
+ const [owner, method] = pair;
2193
+ return Array.isArray(listener) ? `${owner.name}@${method}` : owner.name;
2194
+ }
1506
2195
  var EventFake = class _EventFake {
1507
2196
  constructor(dispatcher, eventsToFake = [], eventsToDispatch = []) {
1508
2197
  this.dispatcher = dispatcher;
@@ -1515,11 +2204,11 @@ var EventFake = class _EventFake {
1515
2204
  events = [];
1516
2205
  /** Installs the fake (on the current container) and returns it: `const events = EventFake.fake([OrderShipped])`. */
1517
2206
  static fake(eventsToFake = []) {
1518
- return install(EventDispatcher, new _EventFake(_EventFake.original(), [eventsToFake].flat()));
2207
+ return install2(EventDispatcher, new _EventFake(_EventFake.original(), [eventsToFake].flat()));
1519
2208
  }
1520
2209
  /** Fakes every event except these. */
1521
2210
  static fakeExcept(eventsToDispatch) {
1522
- return install(EventDispatcher, new _EventFake(_EventFake.original(), [], [eventsToDispatch].flat()));
2211
+ return install2(EventDispatcher, new _EventFake(_EventFake.original(), [], [eventsToDispatch].flat()));
1523
2212
  }
1524
2213
  static original() {
1525
2214
  const current = bound(EventDispatcher);
@@ -1576,9 +2265,20 @@ var EventFake = class _EventFake {
1576
2265
 
1577
2266
  - ${names.join("\n- ")}`);
1578
2267
  }
1579
- /** The original dispatcher has a listener for the event. */
1580
- assertListening(event) {
1581
- assert(this.hasListeners(event), `Event [${nameOf(event)}] does not have any listeners.`);
2268
+ /**
2269
+ * Laravel's assertListening(event, listener): the original dispatcher has that listener for the event (a class, a
2270
+ * [class, method] pair, the same closure, or Function for any closure; wildcard listeners count for a string event).
2271
+ * With only the event, any listener will do.
2272
+ */
2273
+ assertListening(event, listener) {
2274
+ if (listener === void 0) {
2275
+ assert(this.hasListeners(event), `Event [${nameOf(event)}] does not have any listeners.`);
2276
+ return;
2277
+ }
2278
+ assert(
2279
+ this.listenersFor(event).some((registered) => listenerMatches(registered, listener)),
2280
+ `Event [${nameOf(event)}] does not have the [${listenerName(listener)}] listener attached to it`
2281
+ );
1582
2282
  }
1583
2283
  /** The recorded events (objects, or names for string events) that match. */
1584
2284
  dispatched(event, callback) {
@@ -1587,6 +2287,17 @@ var EventFake = class _EventFake {
1587
2287
  hasDispatched(event) {
1588
2288
  return this.dispatched(event).length > 0;
1589
2289
  }
2290
+ /** The original dispatcher's listeners for the event, as registered, wildcard ones included for a string event. */
2291
+ listenersFor(event) {
2292
+ const raw = this.dispatcher?.getRawListeners?.();
2293
+ if (raw === void 0) return [];
2294
+ const listeners = [...raw.get(event) ?? []];
2295
+ if (typeof event !== "string") return listeners;
2296
+ for (const [key, list] of raw) {
2297
+ if (typeof key === "string" && key !== event && key.includes("*") && Str.is(key, event)) listeners.push(...list);
2298
+ }
2299
+ return listeners;
2300
+ }
1590
2301
  shouldFake(event) {
1591
2302
  if (matchesAny(event, this.eventsToDispatch)) return false;
1592
2303
  return this.eventsToFake.length === 0 || matchesAny(event, this.eventsToFake);
@@ -1644,10 +2355,10 @@ var BusFake = class _BusFake {
1644
2355
  /** The rest of the chain, by the first job (Bus.chain([a, b, c]) records a with [b, c]). */
1645
2356
  chains = /* @__PURE__ */ new Map();
1646
2357
  static fake(jobsToFake = []) {
1647
- return install(BusDispatcher, new _BusFake(_BusFake.original(), [jobsToFake].flat()));
2358
+ return install2(BusDispatcher, new _BusFake(_BusFake.original(), [jobsToFake].flat()));
1648
2359
  }
1649
2360
  static fakeExcept(jobsToDispatch) {
1650
- return install(BusDispatcher, new _BusFake(_BusFake.original(), [], [jobsToDispatch].flat()));
2361
+ return install2(BusDispatcher, new _BusFake(_BusFake.original(), [], [jobsToDispatch].flat()));
1651
2362
  }
1652
2363
  static original() {
1653
2364
  const current = bound(BusDispatcher);
@@ -1856,10 +2567,10 @@ var QueueFake = class _QueueFake {
1856
2567
  jobsToPush;
1857
2568
  jobs = [];
1858
2569
  static fake(jobsToFake = []) {
1859
- return install(QueueManager, new _QueueFake(_QueueFake.original(), [jobsToFake].flat()));
2570
+ return install2(QueueManager, new _QueueFake(_QueueFake.original(), [jobsToFake].flat()));
1860
2571
  }
1861
2572
  static fakeExcept(jobsToPush) {
1862
- return install(QueueManager, new _QueueFake(_QueueFake.original(), [], [jobsToPush].flat()));
2573
+ return install2(QueueManager, new _QueueFake(_QueueFake.original(), [], [jobsToPush].flat()));
1863
2574
  }
1864
2575
  static original() {
1865
2576
  const current = bound(QueueManager);
@@ -2041,13 +2752,14 @@ var MailFake = class _MailFake {
2041
2752
  records = [];
2042
2753
  static fake() {
2043
2754
  const current = bound(MailManager);
2044
- return install(MailManager, new _MailFake(current instanceof _MailFake ? current.manager : current));
2755
+ return install2(MailManager, new _MailFake(current instanceof _MailFake ? current.manager : current));
2045
2756
  }
2046
2757
  // MailManager ----------------------------------------------------------------------------------------------
2047
2758
  mailer(name) {
2048
2759
  return {
2049
2760
  to: (recipients) => this.pending(name, recipients),
2050
2761
  send: (mailable) => this.sendVia(name, mailable, empty()),
2762
+ sendNow: (mailable) => this.sendNowVia(name, mailable, empty()),
2051
2763
  queue: (mailable) => this.queueVia(name, mailable, empty(), void 0)
2052
2764
  };
2053
2765
  }
@@ -2057,6 +2769,10 @@ var MailFake = class _MailFake {
2057
2769
  send(mailable) {
2058
2770
  return this.sendVia(void 0, mailable, empty());
2059
2771
  }
2772
+ /** Recorded as sent, never queued, like the real sendNow(). */
2773
+ sendNow(mailable) {
2774
+ return this.sendNowVia(void 0, mailable, empty());
2775
+ }
2060
2776
  queue(mailable) {
2061
2777
  return this.queueVia(void 0, mailable, empty(), void 0);
2062
2778
  }
@@ -2140,6 +2856,7 @@ var MailFake = class _MailFake {
2140
2856
  return pending;
2141
2857
  },
2142
2858
  send: (mailable) => this.sendVia(mailer, mailable, overrides),
2859
+ sendNow: (mailable) => this.sendNowVia(mailer, mailable, overrides),
2143
2860
  queue: (mailable) => this.queueVia(mailer, mailable, overrides, void 0),
2144
2861
  later: (delay, mailable) => this.queueVia(mailer, mailable, overrides, delay)
2145
2862
  };
@@ -2149,6 +2866,10 @@ var MailFake = class _MailFake {
2149
2866
  await this.record(mailer, mailable, overrides, isQueueable(mailable), void 0);
2150
2867
  return void 0;
2151
2868
  }
2869
+ async sendNowVia(mailer, mailable, overrides) {
2870
+ await this.record(mailer, mailable, overrides, false, void 0);
2871
+ return void 0;
2872
+ }
2152
2873
  async queueVia(mailer, mailable, overrides, delay) {
2153
2874
  await this.record(mailer, mailable, overrides, true, delay);
2154
2875
  }
@@ -2223,7 +2944,7 @@ var NotificationFake = class _NotificationFake {
2223
2944
  notifications = [];
2224
2945
  static fake() {
2225
2946
  const current = bound(NotificationDispatcher);
2226
- return install(NotificationDispatcher, new _NotificationFake(current instanceof _NotificationFake ? current.dispatcher : current));
2947
+ return install2(NotificationDispatcher, new _NotificationFake(current instanceof _NotificationFake ? current.dispatcher : current));
2227
2948
  }
2228
2949
  // NotificationDispatcher -------------------------------------------------------------------------------------
2229
2950
  async send(notifiables, notification) {
@@ -2306,7 +3027,8 @@ var NotificationFake = class _NotificationFake {
2306
3027
 
2307
3028
  // Fakes/StorageFake.ts
2308
3029
  import { randomBytes } from "crypto";
2309
- import { ConfigRepository as ConfigRepository3, FilesystemManager } from "@orieljs/contracts";
3030
+ import { posix } from "path";
3031
+ import { ConfigRepository as ConfigRepository4, FilesystemManager } from "@orieljs/contracts";
2310
3032
  var FakeDiskError = class extends Error {
2311
3033
  constructor(name, message, path) {
2312
3034
  super(message);
@@ -2336,8 +3058,74 @@ var MIME = {
2336
3058
  mp4: "video/mp4"
2337
3059
  };
2338
3060
  function guessMimeType(path) {
2339
- const extension = path.split(".").pop()?.toLowerCase() ?? "";
2340
- return MIME[extension];
3061
+ const base = path.slice(path.lastIndexOf("/") + 1);
3062
+ const dot = base.lastIndexOf(".");
3063
+ const extension = dot === -1 ? "" : base.slice(dot + 1).toLowerCase();
3064
+ return Object.hasOwn(MIME, extension) ? MIME[extension] : void 0;
3065
+ }
3066
+ var DISK_TYPES = {
3067
+ txt: "text/plain",
3068
+ html: "text/html",
3069
+ htm: "text/html",
3070
+ css: "text/css",
3071
+ csv: "text/csv",
3072
+ md: "text/markdown",
3073
+ js: "text/javascript",
3074
+ mjs: "text/javascript",
3075
+ json: "application/json",
3076
+ xml: "application/xml",
3077
+ pdf: "application/pdf",
3078
+ zip: "application/zip",
3079
+ gz: "application/gzip",
3080
+ tar: "application/x-tar",
3081
+ "7z": "application/x-7z-compressed",
3082
+ rar: "application/vnd.rar",
3083
+ epub: "application/epub+zip",
3084
+ rtf: "application/rtf",
3085
+ doc: "application/msword",
3086
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
3087
+ xls: "application/vnd.ms-excel",
3088
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
3089
+ ppt: "application/vnd.ms-powerpoint",
3090
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
3091
+ odt: "application/vnd.oasis.opendocument.text",
3092
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
3093
+ odp: "application/vnd.oasis.opendocument.presentation",
3094
+ png: "image/png",
3095
+ jpg: "image/jpeg",
3096
+ jpeg: "image/jpeg",
3097
+ gif: "image/gif",
3098
+ webp: "image/webp",
3099
+ avif: "image/avif",
3100
+ svg: "image/svg+xml",
3101
+ ico: "image/x-icon",
3102
+ bmp: "image/bmp",
3103
+ tif: "image/tiff",
3104
+ tiff: "image/tiff",
3105
+ heic: "image/heic",
3106
+ heif: "image/heif",
3107
+ mp3: "audio/mpeg",
3108
+ m4a: "audio/mp4",
3109
+ wav: "audio/wav",
3110
+ ogg: "audio/ogg",
3111
+ oga: "audio/ogg",
3112
+ opus: "audio/ogg",
3113
+ flac: "audio/flac",
3114
+ aac: "audio/aac",
3115
+ mp4: "video/mp4",
3116
+ mov: "video/quicktime",
3117
+ webm: "video/webm",
3118
+ ogv: "video/ogg",
3119
+ avi: "video/x-msvideo",
3120
+ woff: "font/woff",
3121
+ woff2: "font/woff2",
3122
+ ttf: "font/ttf",
3123
+ otf: "font/otf",
3124
+ wasm: "application/wasm"
3125
+ };
3126
+ function diskType(extension) {
3127
+ const key = extension.replace(/^\./, "").toLowerCase();
3128
+ return Object.hasOwn(DISK_TYPES, key) ? DISK_TYPES[key] : void 0;
2341
3129
  }
2342
3130
  function hashName(file) {
2343
3131
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -2393,17 +3181,24 @@ var FakeDisk = class {
2393
3181
  async put(path, contents, options = {}) {
2394
3182
  const key = normalize(path);
2395
3183
  const bytes = typeof contents === "string" ? new TextEncoder().encode(contents) : contents instanceof Uint8Array ? contents.slice() : await collect(contents);
2396
- this.stored.set(key, { bytes, visibility: options.visibility ?? "private", mimeType: options.mimeType ?? guessMimeType(key), modified: /* @__PURE__ */ new Date() });
3184
+ this.write(key, bytes, options.mimeType ?? diskType(posix.extname(key)), options);
2397
3185
  return true;
2398
3186
  }
2399
3187
  putFile(directory, file, options = {}) {
2400
3188
  return this.putFileAs(directory, file, hashName(file), options);
2401
3189
  }
3190
+ /**
3191
+ * The upload's own type, as the S3 disk sends it: its extension(), never the MIME type the client sent as such nor
3192
+ * the stored name's type.
3193
+ */
2402
3194
  async putFileAs(directory, file, name, options = {}) {
2403
3195
  const path = normalize(`${directory}/${name}`);
2404
- await this.put(path, new Uint8Array(await file.arrayBuffer()), { ...options, mimeType: options.mimeType ?? file.mimeType });
3196
+ this.write(path, new Uint8Array(await file.arrayBuffer()), options.mimeType ?? diskType(file.extension()), options);
2405
3197
  return path;
2406
3198
  }
3199
+ write(key, bytes, mimeType, options) {
3200
+ this.stored.set(key, { bytes, visibility: options.visibility ?? "private", mimeType, modified: /* @__PURE__ */ new Date() });
3201
+ }
2407
3202
  async delete(paths) {
2408
3203
  for (const path of [paths].flat()) this.stored.delete(normalize(path));
2409
3204
  return true;
@@ -2516,8 +3311,8 @@ var StorageFake = class _StorageFake {
2516
3311
  disks = /* @__PURE__ */ new Map();
2517
3312
  static fake(disk) {
2518
3313
  const current = bound(FilesystemManager);
2519
- const config = bound(ConfigRepository3);
2520
- const fake = current instanceof _StorageFake ? current : install(FilesystemManager, new _StorageFake(current, config?.get("filesystems.default", "local") ?? "local"));
3314
+ const config = bound(ConfigRepository4);
3315
+ const fake = current instanceof _StorageFake ? current : install2(FilesystemManager, new _StorageFake(current, config?.get("filesystems.default", "local") ?? "local"));
2521
3316
  const name = disk ?? fake.defaultDisk;
2522
3317
  const faked = new FakeDisk(name);
2523
3318
  fake.disks.set(name, faked);
@@ -2600,6 +3395,37 @@ var StorageFake = class _StorageFake {
2600
3395
 
2601
3396
  // FakeFile.ts
2602
3397
  import { deflateSync } from "zlib";
3398
+ var ascii = (text) => [...text].map((char) => char.charCodeAt(0));
3399
+ var u16be = (n) => [n >>> 8 & 255, n & 255];
3400
+ var u16le = (n) => [n & 255, n >>> 8 & 255];
3401
+ var u32le = (n) => [n & 255, n >>> 8 & 255, n >>> 16 & 255, n >>> 24 & 255];
3402
+ function concat(...parts) {
3403
+ const out = new Uint8Array(parts.reduce((n, part) => n + part.length, 0));
3404
+ let offset = 0;
3405
+ for (const part of parts) {
3406
+ out.set(part, offset);
3407
+ offset += part.length;
3408
+ }
3409
+ return out;
3410
+ }
3411
+ var BitWriter = class {
3412
+ bytes = [];
3413
+ buffer = 0;
3414
+ count = 0;
3415
+ write(value, bits) {
3416
+ this.buffer |= value << this.count;
3417
+ this.count += bits;
3418
+ while (this.count >= 8) {
3419
+ this.bytes.push(this.buffer & 255);
3420
+ this.buffer >>>= 8;
3421
+ this.count -= 8;
3422
+ }
3423
+ }
3424
+ finish() {
3425
+ if (this.count > 0) this.bytes.push(this.buffer & 255);
3426
+ return Uint8Array.from(this.bytes);
3427
+ }
3428
+ };
2603
3429
  var CRC_TABLE = Array.from({ length: 256 }, (_, n) => {
2604
3430
  let c = n;
2605
3431
  for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
@@ -2627,27 +3453,181 @@ function png(width, height) {
2627
3453
  header.set([8, 2, 0, 0, 0], 8);
2628
3454
  const rows = new Uint8Array((width * 3 + 1) * height).fill(255);
2629
3455
  for (let y = 0; y < height; y++) rows[y * (width * 3 + 1)] = 0;
2630
- const parts = [new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", header), chunk("IDAT", deflateSync(rows)), chunk("IEND", new Uint8Array())];
2631
- const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
2632
- let offset = 0;
2633
- for (const part of parts) {
2634
- out.set(part, offset);
2635
- offset += part.length;
2636
- }
3456
+ return concat([137, 80, 78, 71, 13, 10, 26, 10], chunk("IHDR", header), chunk("IDAT", deflateSync(rows)), chunk("IEND", new Uint8Array()));
3457
+ }
3458
+ var oneCodeTable = (tableClass) => [255, 196, ...u16be(20), tableClass, 1, ...new Array(15).fill(0), 0];
3459
+ function jpeg(width, height) {
3460
+ const bits = Math.ceil(width / 8) * Math.ceil(height / 8) * 2;
3461
+ const scan = new Uint8Array(Math.ceil(bits / 8));
3462
+ const padding = scan.length * 8 - bits;
3463
+ if (padding > 0) scan[scan.length - 1] = (1 << padding) - 1;
3464
+ return concat(
3465
+ [255, 216],
3466
+ // SOI
3467
+ [255, 224, ...u16be(16), ...ascii("JFIF"), 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
3468
+ // APP0
3469
+ [255, 219, ...u16be(67), 0, ...new Array(64).fill(1)],
3470
+ // DQT: table 0, all ones
3471
+ [255, 192, ...u16be(11), 8, ...u16be(height), ...u16be(width), 1, 1, 17, 0],
3472
+ // SOF0: one component
3473
+ oneCodeTable(0),
3474
+ // DHT: DC table 0
3475
+ oneCodeTable(16),
3476
+ // DHT: AC table 0
3477
+ [255, 218, ...u16be(8), 1, 1, 0, 0, 63, 0],
3478
+ // SOS
3479
+ scan,
3480
+ [255, 217]
3481
+ // EOI
3482
+ );
3483
+ }
3484
+ function lzwZeros(pixels, minCodeSize) {
3485
+ const clear = 1 << minCodeSize;
3486
+ const end = clear + 1;
3487
+ const out = new BitWriter();
3488
+ const table = /* @__PURE__ */ new Map();
3489
+ let codeSize = minCodeSize + 1;
3490
+ let next = end + 1;
3491
+ let current = 0;
3492
+ out.write(clear, codeSize);
3493
+ for (let i = 1; i < pixels; i++) {
3494
+ const key = current << 8;
3495
+ const known = table.get(key);
3496
+ if (known !== void 0) {
3497
+ current = known;
3498
+ continue;
3499
+ }
3500
+ out.write(current, codeSize);
3501
+ if (next === 4096) {
3502
+ out.write(clear, codeSize);
3503
+ table.clear();
3504
+ codeSize = minCodeSize + 1;
3505
+ next = end + 1;
3506
+ } else {
3507
+ if (next >= 1 << codeSize) codeSize++;
3508
+ table.set(key, next++);
3509
+ }
3510
+ current = 0;
3511
+ }
3512
+ out.write(current, codeSize);
3513
+ out.write(end, codeSize);
3514
+ return out.finish();
3515
+ }
3516
+ function gif(width, height) {
3517
+ const data = lzwZeros(width * height, 2);
3518
+ const blocks = [];
3519
+ for (let offset = 0; offset < data.length; offset += 255) {
3520
+ const block = data.subarray(offset, offset + 255);
3521
+ blocks.push(block.length, ...block);
3522
+ }
3523
+ return concat(
3524
+ ascii("GIF89a"),
3525
+ [...u16le(width), ...u16le(height), 128, 0, 0],
3526
+ // a global palette of two colours
3527
+ [255, 255, 255, 0, 0, 0],
3528
+ [44, 0, 0, 0, 0, ...u16le(width), ...u16le(height), 0],
3529
+ // the image descriptor
3530
+ [2],
3531
+ blocks,
3532
+ [0, 59]
3533
+ // the end of the data, the trailer
3534
+ );
3535
+ }
3536
+ function webp(width, height) {
3537
+ const bits = new BitWriter();
3538
+ bits.write(47, 8);
3539
+ bits.write(width - 1, 14);
3540
+ bits.write(height - 1, 14);
3541
+ bits.write(0, 4);
3542
+ bits.write(0, 3);
3543
+ for (const symbol of [255, 255, 255, 255, 0]) {
3544
+ bits.write(1, 1);
3545
+ bits.write(0, 1);
3546
+ bits.write(1, 1);
3547
+ bits.write(symbol, 8);
3548
+ }
3549
+ const data = bits.finish();
3550
+ const padded = data.length % 2 === 0 ? data : concat(data, [0]);
3551
+ return concat(ascii("RIFF"), u32le(12 + padded.length), ascii("WEBP"), ascii("VP8L"), u32le(data.length), padded);
3552
+ }
3553
+ function bmp(width, height) {
3554
+ const row = Math.ceil(width * 3 / 4) * 4;
3555
+ const out = new Uint8Array(54 + row * height);
3556
+ const view = new DataView(out.buffer);
3557
+ out.set(ascii("BM"));
3558
+ view.setUint32(2, out.length, true);
3559
+ view.setUint32(10, 54, true);
3560
+ view.setUint32(14, 40, true);
3561
+ view.setInt32(18, width, true);
3562
+ view.setInt32(22, height, true);
3563
+ view.setUint16(26, 1, true);
3564
+ view.setUint16(28, 24, true);
3565
+ view.setUint32(34, row * height, true);
3566
+ for (let y = 0; y < height; y++) out.fill(255, 54 + y * row, 54 + y * row + width * 3);
3567
+ return out;
3568
+ }
3569
+ var IMAGE_FORMATS = {
3570
+ png: { type: "image/png", encode: png },
3571
+ jpg: { type: "image/jpeg", encode: jpeg },
3572
+ jpeg: { type: "image/jpeg", encode: jpeg },
3573
+ gif: { type: "image/gif", encode: gif },
3574
+ webp: { type: "image/webp", encode: webp },
3575
+ bmp: { type: "image/bmp", encode: bmp }
3576
+ };
3577
+ var extensionOf = (name) => name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toLowerCase() : "";
3578
+ var MORE_MIME_TYPES = {
3579
+ bmp: "image/bmp",
3580
+ avif: "image/avif",
3581
+ xml: "text/xml",
3582
+ htm: "text/html",
3583
+ md: "text/markdown",
3584
+ tsv: "text/tab-separated-values",
3585
+ text: "text/plain"
3586
+ };
3587
+ var LEADING_BYTES = {
3588
+ "image/jpeg": { bytes: [255, 216, 255, 224, ...u16be(16), ...ascii("JFIF"), 0, 1, 1, 0, 0, 1, 0, 1, 0, 0] },
3589
+ "image/png": { bytes: [137, 80, 78, 71, 13, 10, 26, 10] },
3590
+ "image/gif": { bytes: "GIF89a" },
3591
+ "image/webp": { bytes: "RIFF\0\0\0\0WEBP" },
3592
+ "image/avif": { bytes: [0, 0, 0, 20, ...ascii("ftypavif"), 0, 0, 0, 0, ...ascii("avifmif1")] },
3593
+ "image/bmp": { bytes: [...ascii("BM"), 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0] },
3594
+ "application/pdf": { bytes: "%PDF-1.4\n" },
3595
+ "image/svg+xml": { bytes: '<svg xmlns="http://www.w3.org/2000/svg"/>\n', text: true },
3596
+ "text/html": { bytes: "<!doctype html>\n", text: true },
3597
+ "text/xml": { bytes: '<?xml version="1.0"?>\n', text: true }
3598
+ };
3599
+ function contentFor(type, size) {
3600
+ const text = type.startsWith("text/") || type === "application/json";
3601
+ const leading = LEADING_BYTES[type] ?? { bytes: text ? "\n" : [], text };
3602
+ const head = typeof leading.bytes === "string" ? new TextEncoder().encode(leading.bytes) : Uint8Array.from(leading.bytes);
3603
+ const out = new Uint8Array(Math.max(size, head.length, 1)).fill(leading.text ? 32 : 0);
3604
+ out.set(head);
2637
3605
  return out;
2638
3606
  }
2639
3607
  var FakeFile = {
2640
- /** A file of `kilobytes` KiB (zero bytes), typed by `mimeType` or the extension. */
3608
+ /**
3609
+ * A file of `kilobytes` KiB typed by `mimeType` or the name's extension. Validation reads a file's bytes, so the
3610
+ * file starts like its type (a PDF's `%PDF-`, a PNG's signature, text for text types) and passes `mimes` for its
3611
+ * name, as Laravel's fakes do. It is at least its type's leading bytes and never empty, whatever the size asked for.
3612
+ * An image made this way has no readable size: use image() for `dimensions`.
3613
+ */
2641
3614
  create(name, kilobytes = 0, mimeType) {
2642
- return new File([new Uint8Array(Math.round(kilobytes * 1024))], name, { type: mimeType ?? guessMimeType(name) ?? "application/octet-stream" });
3615
+ const type = mimeType ?? guessMimeType(name) ?? MORE_MIME_TYPES[extensionOf(name)] ?? "application/octet-stream";
3616
+ return new File([contentFor(type, Math.round(kilobytes * 1024))], name, { type });
2643
3617
  },
2644
- /** A real PNG image of the given size (typed by the name's extension, like Laravel's image()). */
3618
+ /**
3619
+ * A real white image of the given size in the format the name's extension asks for: png, jpg/jpeg, gif, webp or
3620
+ * bmp (any other name gets a JPEG, as Laravel's fakes do), so image, mimes and dimensions pass on it.
3621
+ */
2645
3622
  image(name, width = 10, height = 10) {
2646
- return new File([png(width, height)], name, { type: guessMimeType(name) ?? "image/png" });
3623
+ const format2 = IMAGE_FORMATS[extensionOf(name)] ?? IMAGE_FORMATS.jpeg;
3624
+ return new File([format2.encode(width, height)], name, { type: guessMimeType(name) ?? format2.type });
2647
3625
  }
2648
3626
  };
2649
3627
  export {
2650
3628
  AnonymousNotifiable,
3629
+ AssertableInertia,
3630
+ AssertableJson,
2651
3631
  BusFake,
2652
3632
  DatabaseMigrations,
2653
3633
  DatabaseTransactions,
@@ -2658,6 +3638,7 @@ export {
2658
3638
  InteractsWithApplication,
2659
3639
  InteractsWithConsole,
2660
3640
  InteractsWithDatabase,
3641
+ InteractsWithTime,
2661
3642
  MailFake,
2662
3643
  MailRecord,
2663
3644
  MakesHttpRequests,
@@ -2671,6 +3652,7 @@ export {
2671
3652
  TESTING_ENVIRONMENT,
2672
3653
  TestCase,
2673
3654
  TestResponse,
3655
+ Wormhole,
2674
3656
  actingAsAuthFactory,
2675
3657
  addresses,
2676
3658
  applyEnvironment,
@@ -2679,8 +3661,11 @@ export {
2679
3661
  decryptCookie,
2680
3662
  encryptCookie,
2681
3663
  flatten,
3664
+ freezeSecond,
3665
+ freezeTime,
2682
3666
  guessMimeType,
2683
- install,
3667
+ inertiaPageOf,
3668
+ install2 as install,
2684
3669
  isExpired,
2685
3670
  isQueueable,
2686
3671
  matches,
@@ -2690,6 +3675,9 @@ export {
2690
3675
  recordingViewFactory,
2691
3676
  responseCookies,
2692
3677
  runCommand,
3678
+ travel,
3679
+ travelBack,
3680
+ travelTo,
2693
3681
  usingInMemoryDatabase
2694
3682
  };
2695
3683
  //# sourceMappingURL=index.js.map