@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/NOTICE CHANGED
@@ -7,3 +7,6 @@ This product includes software developed by the Oriel project
7
7
  Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
8
8
  The Oriel name and logo are not covered by that license; see TRADEMARKS.md
9
9
  (https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
10
+
11
+ @orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
12
+ voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,68 @@
1
1
  import { Application, ModelInstance, InertiaPage, Encrypter, Session, View, Authenticatable, Container, AuthFactory, ServiceProvider, ServiceProviderClass, DatabaseManager, Row, ExceptionHandler, ViewFactory, Class, Token, EventDispatcher, Listener, PendingBatchOptions, Job, BusDispatcher, PendingChain, PendingBatch, Batch, QueuePayload, QueueManager, Queue, QueueJob, MailManager, Mailable, Address, MailRecipient, Mailer, PendingMail, SentMessage, MailTransport, Notifiable, NotificationDispatcher, Notification, NotificationChannel, Filesystem, PutOptions, UploadedFile, FilesystemManager } from '@orieljs/contracts';
2
2
 
3
+ /** A date the tests travel to: a Date, an ISO string or milliseconds since the epoch. */
4
+ type TravelDate = Date | string | number;
5
+ /**
6
+ * Laravel's travelTo(): the clock stands at `date` (new Date(), Date.now() and now() all read it) until travelBack().
7
+ * With a callback, it runs there and the clock travels back after it; its result is returned.
8
+ */
9
+ declare function travelTo(date: TravelDate): void;
10
+ declare function travelTo<R>(date: TravelDate, callback: (date: Date) => R): R;
11
+ /** Laravel's travelBack(): the real clock again. Returns the real time. */
12
+ declare function travelBack(): Date;
13
+ /** Laravel's freezeTime(): holds the clock where it is now. Returns that time, or the callback's result. */
14
+ declare function freezeTime(): Date;
15
+ declare function freezeTime<R>(callback: (date: Date) => R): R;
16
+ /** Laravel's freezeSecond(): freezeTime() at the start of the current second. */
17
+ declare function freezeSecond(): Date;
18
+ declare function freezeSecond<R>(callback: (date: Date) => R): R;
19
+ /** Laravel's travel(5).minutes(): moves the clock on (a negative value moves it back) from where it stands. */
20
+ declare function travel(value: number): Wormhole;
21
+ /**
22
+ * Laravel's Wormhole: each unit moves the clock by `value` of it (months and years overflow as Carbon's do: 31 January
23
+ * plus a month is 3 March), in UTC. With a callback, it runs there, the clock travels back after it, and its result is
24
+ * returned. JavaScript dates hold milliseconds, so there are no microseconds.
25
+ */
26
+ declare class Wormhole {
27
+ #private;
28
+ readonly value: number;
29
+ constructor(value: number);
30
+ millisecond(): void;
31
+ millisecond<R>(callback: () => R): R;
32
+ milliseconds(): void;
33
+ milliseconds<R>(callback: () => R): R;
34
+ second(): void;
35
+ second<R>(callback: () => R): R;
36
+ seconds(): void;
37
+ seconds<R>(callback: () => R): R;
38
+ minute(): void;
39
+ minute<R>(callback: () => R): R;
40
+ minutes(): void;
41
+ minutes<R>(callback: () => R): R;
42
+ hour(): void;
43
+ hour<R>(callback: () => R): R;
44
+ hours(): void;
45
+ hours<R>(callback: () => R): R;
46
+ day(): void;
47
+ day<R>(callback: () => R): R;
48
+ days(): void;
49
+ days<R>(callback: () => R): R;
50
+ week(): void;
51
+ week<R>(callback: () => R): R;
52
+ weeks(): void;
53
+ weeks<R>(callback: () => R): R;
54
+ month(): void;
55
+ month<R>(callback: () => R): R;
56
+ months(): void;
57
+ months<R>(callback: () => R): R;
58
+ year(): void;
59
+ year<R>(callback: () => R): R;
60
+ years(): void;
61
+ years<R>(callback: () => R): R;
62
+ /** Laravel's Wormhole::back(). */
63
+ static back(): Date;
64
+ }
65
+
3
66
  /**
4
67
  * Laravel's PendingCommand: `await t.artisan('inspire').expectsOutput('…').assertExitCode(0)`.
5
68
  * It runs through ConsoleKernel.call() when awaited (or run()), then checks every expectation against the
@@ -536,11 +599,28 @@ declare abstract class InteractsWithConsole extends InteractsWithDatabase {
536
599
  artisan(command: string, parameters?: Record<string, unknown>): PendingCommand;
537
600
  }
538
601
 
602
+ /**
603
+ * Laravel's InteractsWithTime: `t.travelTo(date)`, `t.travel(5).minutes()`, `t.freezeTime()`, `t.travelBack()`.
604
+ * The functions of the same names do the same outside a test case. A test case's tearDown travels back, so each of its
605
+ * tests ends in the real time; with the plain functions, call `travelBack()` in your own `afterEach()` or pass a callback.
606
+ */
607
+ declare abstract class InteractsWithTime extends InteractsWithConsole {
608
+ travelTo(date: TravelDate): void;
609
+ travelTo<R>(date: TravelDate, callback: (date: Date) => R): R;
610
+ travel(value: number): Wormhole;
611
+ travelBack(): Date;
612
+ freezeTime(): Date;
613
+ freezeTime<R>(callback: (date: Date) => R): R;
614
+ freezeSecond(): Date;
615
+ freezeSecond<R>(callback: (date: Date) => R): R;
616
+ tearDown(): Promise<void>;
617
+ }
618
+
539
619
  /**
540
620
  * Laravel's TestCase. Extend it in tests/TestCase.ts (override createApplication() and set `static hooks`),
541
621
  * then in each file: `const t = TestCase.boot()`, or `TestCase.boot({ uses: [RefreshDatabase] })`.
542
622
  */
543
- declare abstract class TestCase extends InteractsWithConsole {
623
+ declare abstract class TestCase extends InteractsWithTime {
544
624
  }
545
625
 
546
626
  /**
@@ -605,11 +685,11 @@ declare function install<T extends object, F extends T>(token: Token<T>, fake: F
605
685
  declare function nameOf(target: Target | object): string;
606
686
  /** A recorded object (or string event) matches a target: same constructor, or the same (class) name. */
607
687
  declare function matches(item: unknown, target: Target): boolean;
608
- /** Bus's ShouldQueue marker (the Queueable base class sets it on its prototype); the same Symbol.for key as 06. */
688
+ /** Bus's ShouldQueue marker (the Queueable base class sets it on its prototype); the same Symbol.for key as Bus's. */
609
689
  declare const SHOULD_QUEUE: unique symbol;
610
690
  /**
611
- * A verbatim copy of Bus's isQueueable() (06-queue-bus.md; Testing can't import Bus). The rule is read on the
612
- * instance: the ShouldQueue marker, a value for any ShouldQueue option, or uniqueId()/retryUntil().
691
+ * A copy of Bus's isQueueable(), read on the instance: ShouldQueue's `shouldQueue: true` (own field or prototype),
692
+ * the SHOULD_QUEUE symbol, a value for any ShouldQueue option, or uniqueId()/retryUntil().
613
693
  */
614
694
  declare function isQueueable(job: unknown): boolean;
615
695
 
@@ -619,6 +699,8 @@ interface DispatchedEvent {
619
699
  payload: unknown[];
620
700
  }
621
701
  type EventFilter<E> = (event: E, payload: unknown[]) => boolean;
702
+ /** A listener as assertListening() expects it: a class, a [class, method] pair, a closure, or Function for any closure. */
703
+ type ExpectedListener = Listener<never> | readonly [Class<object>, string] | FunctionConstructor;
622
704
  /**
623
705
  * Laravel's Event::fake(): records dispatched events instead of running listeners. With a list, only those
624
706
  * events are faked and everything else reaches the original dispatcher (so model events keep working).
@@ -649,11 +731,17 @@ declare class EventFake implements EventDispatcher {
649
731
  assertDispatchedTimes<E>(event: Class<E> | string, times?: number): void;
650
732
  assertNotDispatched<E>(event: Class<E> | string, callback?: EventFilter<E>): void;
651
733
  assertNothingDispatched(): void;
652
- /** The original dispatcher has a listener for the event. */
653
- assertListening(event: Class<unknown> | string): void;
734
+ /**
735
+ * Laravel's assertListening(event, listener): the original dispatcher has that listener for the event (a class, a
736
+ * [class, method] pair, the same closure, or Function for any closure; wildcard listeners count for a string event).
737
+ * With only the event, any listener will do.
738
+ */
739
+ assertListening(event: Class<unknown> | string, listener?: ExpectedListener): void;
654
740
  /** The recorded events (objects, or names for string events) that match. */
655
741
  dispatched<E>(event: Class<E> | string, callback?: EventFilter<E>): E[];
656
742
  hasDispatched(event: Class<unknown> | string): boolean;
743
+ /** The original dispatcher's listeners for the event, as registered, wildcard ones included for a string event. */
744
+ private listenersFor;
657
745
  private shouldFake;
658
746
  }
659
747
 
@@ -807,6 +895,8 @@ declare class MailFake implements MailManager {
807
895
  mailer(name?: string): Mailer;
808
896
  to(recipients: MailRecipient | MailRecipient[]): PendingMail;
809
897
  send(mailable: Mailable): Promise<SentMessage | undefined>;
898
+ /** Recorded as sent, never queued, like the real sendNow(). */
899
+ sendNow(mailable: Mailable): Promise<SentMessage | undefined>;
810
900
  queue(mailable: Mailable): Promise<void>;
811
901
  extend(_transport: string, _factory: (config: Record<string, unknown>) => MailTransport): void;
812
902
  /** Sent (not queued) at least once; a number asserts the count; a filter gets (mailable, record). */
@@ -828,6 +918,7 @@ declare class MailFake implements MailManager {
828
918
  hasQueued(mailable: Target<Mailable>): boolean;
829
919
  private pending;
830
920
  private sendVia;
921
+ private sendNowVia;
831
922
  private queueVia;
832
923
  private record;
833
924
  private matching;
@@ -887,6 +978,7 @@ interface StoredFile {
887
978
  mimeType: string | undefined;
888
979
  modified: Date;
889
980
  }
981
+ /** By the extension as PHP's pathinfo() reads it: after the last dot of the base name ('.pdf' is a PDF, 'pdf' isn't). */
890
982
  declare function guessMimeType(path: string): string | undefined;
891
983
  /**
892
984
  * An in-memory disk implementing the Filesystem contract, with Laravel's fake-disk assertions. (Laravel's fake
@@ -907,7 +999,12 @@ declare class FakeDisk implements Filesystem {
907
999
  readStream(path: string): Promise<ReadableStream<Uint8Array>>;
908
1000
  put(path: string, contents: string | Uint8Array | ReadableStream<Uint8Array>, options?: PutOptions): Promise<boolean>;
909
1001
  putFile(directory: string, file: UploadedFile, options?: PutOptions): Promise<string>;
1002
+ /**
1003
+ * The upload's own type, as the S3 disk sends it: its extension(), never the MIME type the client sent as such nor
1004
+ * the stored name's type.
1005
+ */
910
1006
  putFileAs(directory: string, file: UploadedFile, name: string, options?: PutOptions): Promise<string>;
1007
+ private write;
911
1008
  delete(paths: string | string[]): Promise<boolean>;
912
1009
  copy(from: string, to: string): Promise<boolean>;
913
1010
  move(from: string, to: string): Promise<boolean>;
@@ -967,10 +1064,18 @@ declare class StorageFake implements FilesystemManager {
967
1064
 
968
1065
  /** Laravel's UploadedFile::fake(): File objects to post as multipart uploads (t.post(uri, { avatar: file })). */
969
1066
  declare const FakeFile: {
970
- /** A file of `kilobytes` KiB (zero bytes), typed by `mimeType` or the extension. */
1067
+ /**
1068
+ * A file of `kilobytes` KiB typed by `mimeType` or the name's extension. Validation reads a file's bytes, so the
1069
+ * file starts like its type (a PDF's `%PDF-`, a PNG's signature, text for text types) and passes `mimes` for its
1070
+ * name, as Laravel's fakes do. It is at least its type's leading bytes and never empty, whatever the size asked for.
1071
+ * An image made this way has no readable size: use image() for `dimensions`.
1072
+ */
971
1073
  create(name: string, kilobytes?: number, mimeType?: string): File;
972
- /** A real PNG image of the given size (typed by the name's extension, like Laravel's image()). */
1074
+ /**
1075
+ * A real white image of the given size in the format the name's extension asks for: png, jpg/jpeg, gif, webp or
1076
+ * bmp (any other name gets a JPEG, as Laravel's fakes do), so image, mimes and dimensions pass on it.
1077
+ */
973
1078
  image(name: string, width?: number, height?: number): File;
974
1079
  };
975
1080
 
976
- export { AnonymousNotifiable, AssertableInertia, AssertableJson, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, guessMimeType, inertiaPageOf, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, usingInMemoryDatabase };
1081
+ export { AnonymousNotifiable, AssertableInertia, AssertableJson, type BatchRecord, type BootOptions, BusFake, type CountOrFilter, DatabaseMigrations, type DatabaseTestOptions, DatabaseTransactions, type DispatchedEvent, EventFake, type ExpectedErrors, type ExpectedListener, FakeDisk, FakeFile, HttpClient, InteractsWithApplication, InteractsWithConsole, InteractsWithDatabase, InteractsWithTime, type JsonStructure, MailFake, MailRecord, MakesHttpRequests, NotificationFake, PendingCommand, type PushedJob, QueueFake, RefreshDatabase, RefreshDatabaseState, type RequestData, type RequestOptions, type ResponseContext, type ResponseCookie, SHOULD_QUEUE, type SentNotification, StorageFake, TESTING_ENVIRONMENT, type TableOrModel, type Target, TestCase, type TestHooks, TestResponse, type TestTrait, type TravelDate, Wormhole, actingAsAuthFactory, addresses, applyEnvironment, cookieHeader, cookiePrefix, decryptCookie, encryptCookie, flatten, freezeSecond, freezeTime, guessMimeType, inertiaPageOf, install, isExpired, isQueueable, matches, nameOf, parseSetCookie, recordingExceptionHandler, recordingViewFactory, responseCookies, runCommand, travel, travelBack, travelTo, usingInMemoryDatabase };