@orieljs/testing 0.1.0-alpha.4 → 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/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 InteractsWithConsole {
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 install(token2, fake) {
2117
+ function install2(token2, fake) {
1967
2118
  facade(token2).swap(fake);
1968
2119
  return fake;
1969
2120
  }
@@ -1992,13 +2143,31 @@ var QUEUE_OPTIONS = ["connection", "queue", "delay", "tries", "backoff", "timeou
1992
2143
  function isQueueable(job) {
1993
2144
  if (typeof job !== "object" || job === null) return false;
1994
2145
  const members = job;
1995
- if (members[SHOULD_QUEUE] === true) return true;
2146
+ if (members.shouldQueue === true || members[SHOULD_QUEUE] === true) return true;
1996
2147
  if (QUEUE_OPTIONS.some((option) => members[option] !== void 0)) return true;
1997
2148
  return typeof members.uniqueId === "function" || typeof members.retryUntil === "function";
1998
2149
  }
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 install(EventDispatcher, new _EventFake(_EventFake.original(), [eventsToFake].flat()));
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 install(EventDispatcher, new _EventFake(_EventFake.original(), [], [eventsToDispatch].flat()));
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
- /** The original dispatcher has a listener for the event. */
2076
- assertListening(event) {
2077
- assert(this.hasListeners(event), `Event [${nameOf(event)}] does not have any listeners.`);
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 install(BusDispatcher, new _BusFake(_BusFake.original(), [jobsToFake].flat()));
2334
+ return install2(BusDispatcher, new _BusFake(_BusFake.original(), [jobsToFake].flat()));
2144
2335
  }
2145
2336
  static fakeExcept(jobsToDispatch) {
2146
- return install(BusDispatcher, new _BusFake(_BusFake.original(), [], [jobsToDispatch].flat()));
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 install(QueueManager, new _QueueFake(_QueueFake.original(), [jobsToFake].flat()));
2546
+ return install2(QueueManager, new _QueueFake(_QueueFake.original(), [jobsToFake].flat()));
2356
2547
  }
2357
2548
  static fakeExcept(jobsToPush) {
2358
- return install(QueueManager, new _QueueFake(_QueueFake.original(), [], [jobsToPush].flat()));
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 install(MailManager, new _MailFake(current instanceof _MailFake ? current.manager : current));
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 install(NotificationDispatcher, new _NotificationFake(current instanceof _NotificationFake ? current.dispatcher : current));
2923
+ return install2(NotificationDispatcher, new _NotificationFake(current instanceof _NotificationFake ? current.dispatcher : current));
2723
2924
  }
2724
2925
  // NotificationDispatcher -------------------------------------------------------------------------------------
2725
2926
  async send(notifiables, notification) {
@@ -2802,6 +3003,7 @@ var NotificationFake = class _NotificationFake {
2802
3003
 
2803
3004
  // Fakes/StorageFake.ts
2804
3005
  import { randomBytes } from "crypto";
3006
+ import { posix } from "path";
2805
3007
  import { ConfigRepository as ConfigRepository4, FilesystemManager } from "@orieljs/contracts";
2806
3008
  var FakeDiskError = class extends Error {
2807
3009
  constructor(name, message, path) {
@@ -2832,8 +3034,74 @@ var MIME = {
2832
3034
  mp4: "video/mp4"
2833
3035
  };
2834
3036
  function guessMimeType(path) {
2835
- const extension = path.split(".").pop()?.toLowerCase() ?? "";
2836
- return MIME[extension];
3037
+ const base = path.slice(path.lastIndexOf("/") + 1);
3038
+ const dot = base.lastIndexOf(".");
3039
+ const extension = dot === -1 ? "" : base.slice(dot + 1).toLowerCase();
3040
+ return Object.hasOwn(MIME, extension) ? MIME[extension] : void 0;
3041
+ }
3042
+ var DISK_TYPES = {
3043
+ txt: "text/plain",
3044
+ html: "text/html",
3045
+ htm: "text/html",
3046
+ css: "text/css",
3047
+ csv: "text/csv",
3048
+ md: "text/markdown",
3049
+ js: "text/javascript",
3050
+ mjs: "text/javascript",
3051
+ json: "application/json",
3052
+ xml: "application/xml",
3053
+ pdf: "application/pdf",
3054
+ zip: "application/zip",
3055
+ gz: "application/gzip",
3056
+ tar: "application/x-tar",
3057
+ "7z": "application/x-7z-compressed",
3058
+ rar: "application/vnd.rar",
3059
+ epub: "application/epub+zip",
3060
+ rtf: "application/rtf",
3061
+ doc: "application/msword",
3062
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
3063
+ xls: "application/vnd.ms-excel",
3064
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
3065
+ ppt: "application/vnd.ms-powerpoint",
3066
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
3067
+ odt: "application/vnd.oasis.opendocument.text",
3068
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
3069
+ odp: "application/vnd.oasis.opendocument.presentation",
3070
+ png: "image/png",
3071
+ jpg: "image/jpeg",
3072
+ jpeg: "image/jpeg",
3073
+ gif: "image/gif",
3074
+ webp: "image/webp",
3075
+ avif: "image/avif",
3076
+ svg: "image/svg+xml",
3077
+ ico: "image/x-icon",
3078
+ bmp: "image/bmp",
3079
+ tif: "image/tiff",
3080
+ tiff: "image/tiff",
3081
+ heic: "image/heic",
3082
+ heif: "image/heif",
3083
+ mp3: "audio/mpeg",
3084
+ m4a: "audio/mp4",
3085
+ wav: "audio/wav",
3086
+ ogg: "audio/ogg",
3087
+ oga: "audio/ogg",
3088
+ opus: "audio/ogg",
3089
+ flac: "audio/flac",
3090
+ aac: "audio/aac",
3091
+ mp4: "video/mp4",
3092
+ mov: "video/quicktime",
3093
+ webm: "video/webm",
3094
+ ogv: "video/ogg",
3095
+ avi: "video/x-msvideo",
3096
+ woff: "font/woff",
3097
+ woff2: "font/woff2",
3098
+ ttf: "font/ttf",
3099
+ otf: "font/otf",
3100
+ wasm: "application/wasm"
3101
+ };
3102
+ function diskType(extension) {
3103
+ const key = extension.replace(/^\./, "").toLowerCase();
3104
+ return Object.hasOwn(DISK_TYPES, key) ? DISK_TYPES[key] : void 0;
2837
3105
  }
2838
3106
  function hashName(file) {
2839
3107
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -2889,17 +3157,24 @@ var FakeDisk = class {
2889
3157
  async put(path, contents, options = {}) {
2890
3158
  const key = normalize(path);
2891
3159
  const bytes = typeof contents === "string" ? new TextEncoder().encode(contents) : contents instanceof Uint8Array ? contents.slice() : await collect(contents);
2892
- this.stored.set(key, { bytes, visibility: options.visibility ?? "private", mimeType: options.mimeType ?? guessMimeType(key), modified: /* @__PURE__ */ new Date() });
3160
+ this.write(key, bytes, options.mimeType ?? diskType(posix.extname(key)), options);
2893
3161
  return true;
2894
3162
  }
2895
3163
  putFile(directory, file, options = {}) {
2896
3164
  return this.putFileAs(directory, file, hashName(file), options);
2897
3165
  }
3166
+ /**
3167
+ * The upload's own type, as the S3 disk sends it: its extension(), never the MIME type the client sent as such nor
3168
+ * the stored name's type.
3169
+ */
2898
3170
  async putFileAs(directory, file, name, options = {}) {
2899
3171
  const path = normalize(`${directory}/${name}`);
2900
- await this.put(path, new Uint8Array(await file.arrayBuffer()), { ...options, mimeType: options.mimeType ?? file.mimeType });
3172
+ this.write(path, new Uint8Array(await file.arrayBuffer()), options.mimeType ?? diskType(file.extension()), options);
2901
3173
  return path;
2902
3174
  }
3175
+ write(key, bytes, mimeType, options) {
3176
+ this.stored.set(key, { bytes, visibility: options.visibility ?? "private", mimeType, modified: /* @__PURE__ */ new Date() });
3177
+ }
2903
3178
  async delete(paths) {
2904
3179
  for (const path of [paths].flat()) this.stored.delete(normalize(path));
2905
3180
  return true;
@@ -3013,7 +3288,7 @@ var StorageFake = class _StorageFake {
3013
3288
  static fake(disk) {
3014
3289
  const current = bound(FilesystemManager);
3015
3290
  const config = bound(ConfigRepository4);
3016
- const fake = current instanceof _StorageFake ? current : install(FilesystemManager, new _StorageFake(current, config?.get("filesystems.default", "local") ?? "local"));
3291
+ const fake = current instanceof _StorageFake ? current : install2(FilesystemManager, new _StorageFake(current, config?.get("filesystems.default", "local") ?? "local"));
3017
3292
  const name = disk ?? fake.defaultDisk;
3018
3293
  const faked = new FakeDisk(name);
3019
3294
  fake.disks.set(name, faked);
@@ -3096,6 +3371,37 @@ var StorageFake = class _StorageFake {
3096
3371
 
3097
3372
  // FakeFile.ts
3098
3373
  import { deflateSync } from "zlib";
3374
+ var ascii = (text) => [...text].map((char) => char.charCodeAt(0));
3375
+ var u16be = (n) => [n >>> 8 & 255, n & 255];
3376
+ var u16le = (n) => [n & 255, n >>> 8 & 255];
3377
+ var u32le = (n) => [n & 255, n >>> 8 & 255, n >>> 16 & 255, n >>> 24 & 255];
3378
+ function concat(...parts) {
3379
+ const out = new Uint8Array(parts.reduce((n, part) => n + part.length, 0));
3380
+ let offset = 0;
3381
+ for (const part of parts) {
3382
+ out.set(part, offset);
3383
+ offset += part.length;
3384
+ }
3385
+ return out;
3386
+ }
3387
+ var BitWriter = class {
3388
+ bytes = [];
3389
+ buffer = 0;
3390
+ count = 0;
3391
+ write(value, bits) {
3392
+ this.buffer |= value << this.count;
3393
+ this.count += bits;
3394
+ while (this.count >= 8) {
3395
+ this.bytes.push(this.buffer & 255);
3396
+ this.buffer >>>= 8;
3397
+ this.count -= 8;
3398
+ }
3399
+ }
3400
+ finish() {
3401
+ if (this.count > 0) this.bytes.push(this.buffer & 255);
3402
+ return Uint8Array.from(this.bytes);
3403
+ }
3404
+ };
3099
3405
  var CRC_TABLE = Array.from({ length: 256 }, (_, n) => {
3100
3406
  let c = n;
3101
3407
  for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
@@ -3123,23 +3429,175 @@ function png(width, height) {
3123
3429
  header.set([8, 2, 0, 0, 0], 8);
3124
3430
  const rows = new Uint8Array((width * 3 + 1) * height).fill(255);
3125
3431
  for (let y = 0; y < height; y++) rows[y * (width * 3 + 1)] = 0;
3126
- const parts = [new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", header), chunk("IDAT", deflateSync(rows)), chunk("IEND", new Uint8Array())];
3127
- const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
3128
- let offset = 0;
3129
- for (const part of parts) {
3130
- out.set(part, offset);
3131
- offset += part.length;
3132
- }
3432
+ return concat([137, 80, 78, 71, 13, 10, 26, 10], chunk("IHDR", header), chunk("IDAT", deflateSync(rows)), chunk("IEND", new Uint8Array()));
3433
+ }
3434
+ var oneCodeTable = (tableClass) => [255, 196, ...u16be(20), tableClass, 1, ...new Array(15).fill(0), 0];
3435
+ function jpeg(width, height) {
3436
+ const bits = Math.ceil(width / 8) * Math.ceil(height / 8) * 2;
3437
+ const scan = new Uint8Array(Math.ceil(bits / 8));
3438
+ const padding = scan.length * 8 - bits;
3439
+ if (padding > 0) scan[scan.length - 1] = (1 << padding) - 1;
3440
+ return concat(
3441
+ [255, 216],
3442
+ // SOI
3443
+ [255, 224, ...u16be(16), ...ascii("JFIF"), 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
3444
+ // APP0
3445
+ [255, 219, ...u16be(67), 0, ...new Array(64).fill(1)],
3446
+ // DQT: table 0, all ones
3447
+ [255, 192, ...u16be(11), 8, ...u16be(height), ...u16be(width), 1, 1, 17, 0],
3448
+ // SOF0: one component
3449
+ oneCodeTable(0),
3450
+ // DHT: DC table 0
3451
+ oneCodeTable(16),
3452
+ // DHT: AC table 0
3453
+ [255, 218, ...u16be(8), 1, 1, 0, 0, 63, 0],
3454
+ // SOS
3455
+ scan,
3456
+ [255, 217]
3457
+ // EOI
3458
+ );
3459
+ }
3460
+ function lzwZeros(pixels, minCodeSize) {
3461
+ const clear = 1 << minCodeSize;
3462
+ const end = clear + 1;
3463
+ const out = new BitWriter();
3464
+ const table = /* @__PURE__ */ new Map();
3465
+ let codeSize = minCodeSize + 1;
3466
+ let next = end + 1;
3467
+ let current = 0;
3468
+ out.write(clear, codeSize);
3469
+ for (let i = 1; i < pixels; i++) {
3470
+ const key = current << 8;
3471
+ const known = table.get(key);
3472
+ if (known !== void 0) {
3473
+ current = known;
3474
+ continue;
3475
+ }
3476
+ out.write(current, codeSize);
3477
+ if (next === 4096) {
3478
+ out.write(clear, codeSize);
3479
+ table.clear();
3480
+ codeSize = minCodeSize + 1;
3481
+ next = end + 1;
3482
+ } else {
3483
+ if (next >= 1 << codeSize) codeSize++;
3484
+ table.set(key, next++);
3485
+ }
3486
+ current = 0;
3487
+ }
3488
+ out.write(current, codeSize);
3489
+ out.write(end, codeSize);
3490
+ return out.finish();
3491
+ }
3492
+ function gif(width, height) {
3493
+ const data = lzwZeros(width * height, 2);
3494
+ const blocks = [];
3495
+ for (let offset = 0; offset < data.length; offset += 255) {
3496
+ const block = data.subarray(offset, offset + 255);
3497
+ blocks.push(block.length, ...block);
3498
+ }
3499
+ return concat(
3500
+ ascii("GIF89a"),
3501
+ [...u16le(width), ...u16le(height), 128, 0, 0],
3502
+ // a global palette of two colours
3503
+ [255, 255, 255, 0, 0, 0],
3504
+ [44, 0, 0, 0, 0, ...u16le(width), ...u16le(height), 0],
3505
+ // the image descriptor
3506
+ [2],
3507
+ blocks,
3508
+ [0, 59]
3509
+ // the end of the data, the trailer
3510
+ );
3511
+ }
3512
+ function webp(width, height) {
3513
+ const bits = new BitWriter();
3514
+ bits.write(47, 8);
3515
+ bits.write(width - 1, 14);
3516
+ bits.write(height - 1, 14);
3517
+ bits.write(0, 4);
3518
+ bits.write(0, 3);
3519
+ for (const symbol of [255, 255, 255, 255, 0]) {
3520
+ bits.write(1, 1);
3521
+ bits.write(0, 1);
3522
+ bits.write(1, 1);
3523
+ bits.write(symbol, 8);
3524
+ }
3525
+ const data = bits.finish();
3526
+ const padded = data.length % 2 === 0 ? data : concat(data, [0]);
3527
+ return concat(ascii("RIFF"), u32le(12 + padded.length), ascii("WEBP"), ascii("VP8L"), u32le(data.length), padded);
3528
+ }
3529
+ function bmp(width, height) {
3530
+ const row = Math.ceil(width * 3 / 4) * 4;
3531
+ const out = new Uint8Array(54 + row * height);
3532
+ const view = new DataView(out.buffer);
3533
+ out.set(ascii("BM"));
3534
+ view.setUint32(2, out.length, true);
3535
+ view.setUint32(10, 54, true);
3536
+ view.setUint32(14, 40, true);
3537
+ view.setInt32(18, width, true);
3538
+ view.setInt32(22, height, true);
3539
+ view.setUint16(26, 1, true);
3540
+ view.setUint16(28, 24, true);
3541
+ view.setUint32(34, row * height, true);
3542
+ for (let y = 0; y < height; y++) out.fill(255, 54 + y * row, 54 + y * row + width * 3);
3543
+ return out;
3544
+ }
3545
+ var IMAGE_FORMATS = {
3546
+ png: { type: "image/png", encode: png },
3547
+ jpg: { type: "image/jpeg", encode: jpeg },
3548
+ jpeg: { type: "image/jpeg", encode: jpeg },
3549
+ gif: { type: "image/gif", encode: gif },
3550
+ webp: { type: "image/webp", encode: webp },
3551
+ bmp: { type: "image/bmp", encode: bmp }
3552
+ };
3553
+ var extensionOf = (name) => name.includes(".") ? name.slice(name.lastIndexOf(".") + 1).toLowerCase() : "";
3554
+ var MORE_MIME_TYPES = {
3555
+ bmp: "image/bmp",
3556
+ avif: "image/avif",
3557
+ xml: "text/xml",
3558
+ htm: "text/html",
3559
+ md: "text/markdown",
3560
+ tsv: "text/tab-separated-values",
3561
+ text: "text/plain"
3562
+ };
3563
+ var LEADING_BYTES = {
3564
+ "image/jpeg": { bytes: [255, 216, 255, 224, ...u16be(16), ...ascii("JFIF"), 0, 1, 1, 0, 0, 1, 0, 1, 0, 0] },
3565
+ "image/png": { bytes: [137, 80, 78, 71, 13, 10, 26, 10] },
3566
+ "image/gif": { bytes: "GIF89a" },
3567
+ "image/webp": { bytes: "RIFF\0\0\0\0WEBP" },
3568
+ "image/avif": { bytes: [0, 0, 0, 20, ...ascii("ftypavif"), 0, 0, 0, 0, ...ascii("avifmif1")] },
3569
+ "image/bmp": { bytes: [...ascii("BM"), 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0] },
3570
+ "application/pdf": { bytes: "%PDF-1.4\n" },
3571
+ "image/svg+xml": { bytes: '<svg xmlns="http://www.w3.org/2000/svg"/>\n', text: true },
3572
+ "text/html": { bytes: "<!doctype html>\n", text: true },
3573
+ "text/xml": { bytes: '<?xml version="1.0"?>\n', text: true }
3574
+ };
3575
+ function contentFor(type, size) {
3576
+ const text = type.startsWith("text/") || type === "application/json";
3577
+ const leading = LEADING_BYTES[type] ?? { bytes: text ? "\n" : [], text };
3578
+ const head = typeof leading.bytes === "string" ? new TextEncoder().encode(leading.bytes) : Uint8Array.from(leading.bytes);
3579
+ const out = new Uint8Array(Math.max(size, head.length, 1)).fill(leading.text ? 32 : 0);
3580
+ out.set(head);
3133
3581
  return out;
3134
3582
  }
3135
3583
  var FakeFile = {
3136
- /** A file of `kilobytes` KiB (zero bytes), typed by `mimeType` or the extension. */
3584
+ /**
3585
+ * A file of `kilobytes` KiB typed by `mimeType` or the name's extension. Validation reads a file's bytes, so the
3586
+ * file starts like its type (a PDF's `%PDF-`, a PNG's signature, text for text types) and passes `mimes` for its
3587
+ * name, as Laravel's fakes do. It is at least its type's leading bytes and never empty, whatever the size asked for.
3588
+ * An image made this way has no readable size: use image() for `dimensions`.
3589
+ */
3137
3590
  create(name, kilobytes = 0, mimeType) {
3138
- return new File([new Uint8Array(Math.round(kilobytes * 1024))], name, { type: mimeType ?? guessMimeType(name) ?? "application/octet-stream" });
3591
+ const type = mimeType ?? guessMimeType(name) ?? MORE_MIME_TYPES[extensionOf(name)] ?? "application/octet-stream";
3592
+ return new File([contentFor(type, Math.round(kilobytes * 1024))], name, { type });
3139
3593
  },
3140
- /** A real PNG image of the given size (typed by the name's extension, like Laravel's image()). */
3594
+ /**
3595
+ * A real white image of the given size in the format the name's extension asks for: png, jpg/jpeg, gif, webp or
3596
+ * bmp (any other name gets a JPEG, as Laravel's fakes do), so image, mimes and dimensions pass on it.
3597
+ */
3141
3598
  image(name, width = 10, height = 10) {
3142
- return new File([png(width, height)], name, { type: guessMimeType(name) ?? "image/png" });
3599
+ const format2 = IMAGE_FORMATS[extensionOf(name)] ?? IMAGE_FORMATS.jpeg;
3600
+ return new File([format2.encode(width, height)], name, { type: guessMimeType(name) ?? format2.type });
3143
3601
  }
3144
3602
  };
3145
3603
  export {
@@ -3156,6 +3614,7 @@ export {
3156
3614
  InteractsWithApplication,
3157
3615
  InteractsWithConsole,
3158
3616
  InteractsWithDatabase,
3617
+ InteractsWithTime,
3159
3618
  MailFake,
3160
3619
  MailRecord,
3161
3620
  MakesHttpRequests,
@@ -3169,6 +3628,7 @@ export {
3169
3628
  TESTING_ENVIRONMENT,
3170
3629
  TestCase,
3171
3630
  TestResponse,
3631
+ Wormhole,
3172
3632
  actingAsAuthFactory,
3173
3633
  addresses,
3174
3634
  applyEnvironment,
@@ -3177,9 +3637,11 @@ export {
3177
3637
  decryptCookie,
3178
3638
  encryptCookie,
3179
3639
  flatten,
3640
+ freezeSecond,
3641
+ freezeTime,
3180
3642
  guessMimeType,
3181
3643
  inertiaPageOf,
3182
- install,
3644
+ install2 as install,
3183
3645
  isExpired,
3184
3646
  isQueueable,
3185
3647
  matches,
@@ -3189,6 +3651,9 @@ export {
3189
3651
  recordingViewFactory,
3190
3652
  responseCookies,
3191
3653
  runCommand,
3654
+ travel,
3655
+ travelBack,
3656
+ travelTo,
3192
3657
  usingInMemoryDatabase
3193
3658
  };
3194
3659
  //# sourceMappingURL=index.js.map