-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
lib.deno.ns.d.ts
6660 lines (6379 loc) · 212 KB
/
lib.deno.ns.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="deno.net" />
/** Deno provides extra properties on `import.meta`. These are included here
* to ensure that these are still available when using the Deno namespace in
* conjunction with other type libs, like `dom`.
*
* @category Platform
*/
declare interface ImportMeta {
/** A string representation of the fully qualified module URL. When the
* module is loaded locally, the value will be a file URL (e.g.
* `file:///path/module.ts`).
*
* You can also parse the string as a URL to determine more information about
* how the current module was loaded. For example to determine if a module was
* local or not:
*
* ```ts
* const url = new URL(import.meta.url);
* if (url.protocol === "file:") {
* console.log("this module was loaded locally");
* }
* ```
*/
url: string;
/** The absolute path of the current module.
*
* This property is only provided for local modules (ie. using `file://` URLs).
*
* Example:
* ```
* // Unix
* console.log(import.meta.filename); // /home/alice/my_module.ts
*
* // Windows
* console.log(import.meta.filename); // C:\alice\my_module.ts
* ```
*/
filename?: string;
/** The absolute path of the directory containing the current module.
*
* This property is only provided for local modules (ie. using `file://` URLs).
*
* * Example:
* ```
* // Unix
* console.log(import.meta.dirname); // /home/alice
*
* // Windows
* console.log(import.meta.dirname); // C:\alice
* ```
*/
dirname?: string;
/** A flag that indicates if the current module is the main module that was
* called when starting the program under Deno.
*
* ```ts
* if (import.meta.main) {
* // this was loaded as the main module, maybe do some bootstrapping
* }
* ```
*/
main: boolean;
/** A function that returns resolved specifier as if it would be imported
* using `import(specifier)`.
*
* ```ts
* console.log(import.meta.resolve("./foo.js"));
* // file:///dev/foo.js
* ```
*/
resolve(specifier: string): string;
}
/** Deno supports [User Timing Level 3](https://w3c.github.io/user-timing)
* which is not widely supported yet in other runtimes.
*
* Check out the
* [Performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)
* documentation on MDN for further information about how to use the API.
*
* @category Performance
*/
declare interface Performance {
/** Stores a timestamp with the associated name (a "mark"). */
mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark;
/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
* associated name (a "measure"). */
measure(
measureName: string,
options?: PerformanceMeasureOptions,
): PerformanceMeasure;
}
/**
* Options which are used in conjunction with `performance.mark`. Check out the
* MDN
* [`performance.mark()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark#markoptions)
* documentation for more details.
*
* @category Performance
*/
declare interface PerformanceMarkOptions {
/** Metadata to be included in the mark. */
// deno-lint-ignore no-explicit-any
detail?: any;
/** Timestamp to be used as the mark time. */
startTime?: number;
}
/**
* Options which are used in conjunction with `performance.measure`. Check out the
* MDN
* [`performance.mark()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure#measureoptions)
* documentation for more details.
*
* @category Performance
*/
declare interface PerformanceMeasureOptions {
/** Metadata to be included in the measure. */
// deno-lint-ignore no-explicit-any
detail?: any;
/** Timestamp to be used as the start time or string to be used as start
* mark. */
start?: string | number;
/** Duration between the start and end times. */
duration?: number;
/** Timestamp to be used as the end time or string to be used as end mark. */
end?: string | number;
}
/** The global namespace where Deno specific, non-standard APIs are located. */
declare namespace Deno {
/** A set of error constructors that are raised by Deno APIs.
*
* Can be used to provide more specific handling of failures within code
* which is using Deno APIs. For example, handling attempting to open a file
* which does not exist:
*
* ```ts
* try {
* const file = await Deno.open("./some/file.txt");
* } catch (error) {
* if (error instanceof Deno.errors.NotFound) {
* console.error("the file was not found");
* } else {
* // otherwise re-throw
* throw error;
* }
* }
* ```
*
* @category Errors
*/
export namespace errors {
/**
* Raised when the underlying operating system indicates that the file
* was not found.
*
* @category Errors */
export class NotFound extends Error {}
/**
* Raised when the underlying operating system indicates the current user
* which the Deno process is running under does not have the appropriate
* permissions to a file or resource, or the user _did not_ provide required
* `--allow-*` flag.
*
* @category Errors */
export class PermissionDenied extends Error {}
/**
* Raised when the underlying operating system reports that a connection to
* a resource is refused.
*
* @category Errors */
export class ConnectionRefused extends Error {}
/**
* Raised when the underlying operating system reports that a connection has
* been reset. With network servers, it can be a _normal_ occurrence where a
* client will abort a connection instead of properly shutting it down.
*
* @category Errors */
export class ConnectionReset extends Error {}
/**
* Raised when the underlying operating system reports an `ECONNABORTED`
* error.
*
* @category Errors */
export class ConnectionAborted extends Error {}
/**
* Raised when the underlying operating system reports an `ENOTCONN` error.
*
* @category Errors */
export class NotConnected extends Error {}
/**
* Raised when attempting to open a server listener on an address and port
* that already has a listener.
*
* @category Errors */
export class AddrInUse extends Error {}
/**
* Raised when the underlying operating system reports an `EADDRNOTAVAIL`
* error.
*
* @category Errors */
export class AddrNotAvailable extends Error {}
/**
* Raised when trying to write to a resource and a broken pipe error occurs.
* This can happen when trying to write directly to `stdout` or `stderr`
* and the operating system is unable to pipe the output for a reason
* external to the Deno runtime.
*
* @category Errors */
export class BrokenPipe extends Error {}
/**
* Raised when trying to create a resource, like a file, that already
* exits.
*
* @category Errors */
export class AlreadyExists extends Error {}
/**
* Raised when an operation to returns data that is invalid for the
* operation being performed.
*
* @category Errors */
export class InvalidData extends Error {}
/**
* Raised when the underlying operating system reports that an I/O operation
* has timed out (`ETIMEDOUT`).
*
* @category Errors */
export class TimedOut extends Error {}
/**
* Raised when the underlying operating system reports an `EINTR` error. In
* many cases, this underlying IO error will be handled internally within
* Deno, or result in an @{link BadResource} error instead.
*
* @category Errors */
export class Interrupted extends Error {}
/**
* Raised when the underlying operating system would need to block to
* complete but an asynchronous (non-blocking) API is used.
*
* @category Errors */
export class WouldBlock extends Error {}
/**
* Raised when expecting to write to a IO buffer resulted in zero bytes
* being written.
*
* @category Errors */
export class WriteZero extends Error {}
/**
* Raised when attempting to read bytes from a resource, but the EOF was
* unexpectedly encountered.
*
* @category Errors */
export class UnexpectedEof extends Error {}
/**
* The underlying IO resource is invalid or closed, and so the operation
* could not be performed.
*
* @category Errors */
export class BadResource extends Error {}
/**
* Raised in situations where when attempting to load a dynamic import,
* too many redirects were encountered.
*
* @category Errors */
export class Http extends Error {}
/**
* Raised when the underlying IO resource is not available because it is
* being awaited on in another block of code.
*
* @category Errors */
export class Busy extends Error {}
/**
* Raised when the underlying Deno API is asked to perform a function that
* is not currently supported.
*
* @category Errors */
export class NotSupported extends Error {}
/**
* Raised when too many symbolic links were encountered when resolving the
* filename.
*
* @category Errors */
export class FilesystemLoop extends Error {}
/**
* Raised when trying to open, create or write to a directory.
*
* @category Errors */
export class IsADirectory extends Error {}
/**
* Raised when performing a socket operation but the remote host is
* not reachable.
*
* @category Errors */
export class NetworkUnreachable extends Error {}
/**
* Raised when trying to perform an operation on a path that is not a
* directory, when directory is required.
*
* @category Errors */
export class NotADirectory extends Error {}
}
/** The current process ID of this instance of the Deno CLI.
*
* ```ts
* console.log(Deno.pid);
* ```
*
* @category Runtime
*/
export const pid: number;
/**
* The process ID of parent process of this instance of the Deno CLI.
*
* ```ts
* console.log(Deno.ppid);
* ```
*
* @category Runtime
*/
export const ppid: number;
/** @category Runtime */
export interface MemoryUsage {
/** The number of bytes of the current Deno's process resident set size,
* which is the amount of memory occupied in main memory (RAM). */
rss: number;
/** The total size of the heap for V8, in bytes. */
heapTotal: number;
/** The amount of the heap used for V8, in bytes. */
heapUsed: number;
/** Memory, in bytes, associated with JavaScript objects outside of the
* JavaScript isolate. */
external: number;
}
/**
* Returns an object describing the memory usage of the Deno process and the
* V8 subsystem measured in bytes.
*
* @category Runtime
*/
export function memoryUsage(): MemoryUsage;
/**
* Get the `hostname` of the machine the Deno process is running on.
*
* ```ts
* console.log(Deno.hostname());
* ```
*
* Requires `allow-sys` permission.
*
* @tags allow-sys
* @category Runtime
*/
export function hostname(): string;
/**
* Returns an array containing the 1, 5, and 15 minute load averages. The
* load average is a measure of CPU and IO utilization of the last one, five,
* and 15 minute periods expressed as a fractional number. Zero means there
* is no load. On Windows, the three values are always the same and represent
* the current load, not the 1, 5 and 15 minute load averages.
*
* ```ts
* console.log(Deno.loadavg()); // e.g. [ 0.71, 0.44, 0.44 ]
* ```
*
* Requires `allow-sys` permission.
*
* On Windows there is no API available to retrieve this information and this method returns `[ 0, 0, 0 ]`.
*
* @tags allow-sys
* @category Runtime
*/
export function loadavg(): number[];
/**
* The information for a network interface returned from a call to
* {@linkcode Deno.networkInterfaces}.
*
* @category Network
*/
export interface NetworkInterfaceInfo {
/** The network interface name. */
name: string;
/** The IP protocol version. */
family: "IPv4" | "IPv6";
/** The IP address bound to the interface. */
address: string;
/** The netmask applied to the interface. */
netmask: string;
/** The IPv6 scope id or `null`. */
scopeid: number | null;
/** The CIDR range. */
cidr: string;
/** The MAC address. */
mac: string;
}
/**
* Returns an array of the network interface information.
*
* ```ts
* console.log(Deno.networkInterfaces());
* ```
*
* Requires `allow-sys` permission.
*
* @tags allow-sys
* @category Network
*/
export function networkInterfaces(): NetworkInterfaceInfo[];
/**
* Displays the total amount of free and used physical and swap memory in the
* system, as well as the buffers and caches used by the kernel.
*
* This is similar to the `free` command in Linux
*
* ```ts
* console.log(Deno.systemMemoryInfo());
* ```
*
* Requires `allow-sys` permission.
*
* @tags allow-sys
* @category Runtime
*/
export function systemMemoryInfo(): SystemMemoryInfo;
/**
* Information returned from a call to {@linkcode Deno.systemMemoryInfo}.
*
* @category Runtime
*/
export interface SystemMemoryInfo {
/** Total installed memory in bytes. */
total: number;
/** Unused memory in bytes. */
free: number;
/** Estimation of how much memory, in bytes, is available for starting new
* applications, without swapping. Unlike the data provided by the cache or
* free fields, this field takes into account page cache and also that not
* all reclaimable memory will be reclaimed due to items being in use.
*/
available: number;
/** Memory used by kernel buffers. */
buffers: number;
/** Memory used by the page cache and slabs. */
cached: number;
/** Total swap memory. */
swapTotal: number;
/** Unused swap memory. */
swapFree: number;
}
/** Reflects the `NO_COLOR` environment variable at program start.
*
* When the value is `true`, the Deno CLI will attempt to not send color codes
* to `stderr` or `stdout` and other command line programs should also attempt
* to respect this value.
*
* See: https://no-color.org/
*
* @category Runtime
*/
export const noColor: boolean;
/**
* Returns the release version of the Operating System.
*
* ```ts
* console.log(Deno.osRelease());
* ```
*
* Requires `allow-sys` permission.
* Under consideration to possibly move to Deno.build or Deno.versions and if
* it should depend sys-info, which may not be desirable.
*
* @tags allow-sys
* @category Runtime
*/
export function osRelease(): string;
/**
* Returns the Operating System uptime in number of seconds.
*
* ```ts
* console.log(Deno.osUptime());
* ```
*
* Requires `allow-sys` permission.
*
* @tags allow-sys
* @category Runtime
*/
export function osUptime(): number;
/**
* Options which define the permissions within a test or worker context.
*
* `"inherit"` ensures that all permissions of the parent process will be
* applied to the test context. `"none"` ensures the test context has no
* permissions. A `PermissionOptionsObject` provides a more specific
* set of permissions to the test context.
*
* @category Permissions */
export type PermissionOptions =
| "inherit"
| "none"
| PermissionOptionsObject;
/**
* A set of options which can define the permissions within a test or worker
* context at a highly specific level.
*
* @category Permissions */
export interface PermissionOptionsObject {
/** Specifies if the `env` permission should be requested or revoked.
* If set to `"inherit"`, the current `env` permission will be inherited.
* If set to `true`, the global `env` permission will be requested.
* If set to `false`, the global `env` permission will be revoked.
*
* @default {false}
*/
env?: "inherit" | boolean | string[];
/** Specifies if the `sys` permission should be requested or revoked.
* If set to `"inherit"`, the current `sys` permission will be inherited.
* If set to `true`, the global `sys` permission will be requested.
* If set to `false`, the global `sys` permission will be revoked.
*
* @default {false}
*/
sys?: "inherit" | boolean | string[];
/** Specifies if the `hrtime` permission should be requested or revoked.
* If set to `"inherit"`, the current `hrtime` permission will be inherited.
* If set to `true`, the global `hrtime` permission will be requested.
* If set to `false`, the global `hrtime` permission will be revoked.
*
* @default {false}
*/
hrtime?: "inherit" | boolean;
/** Specifies if the `net` permission should be requested or revoked.
* if set to `"inherit"`, the current `net` permission will be inherited.
* if set to `true`, the global `net` permission will be requested.
* if set to `false`, the global `net` permission will be revoked.
* if set to `string[]`, the `net` permission will be requested with the
* specified host strings with the format `"<host>[:<port>]`.
*
* @default {false}
*
* Examples:
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "inherit",
* permissions: {
* net: "inherit",
* },
* async fn() {
* const status = await Deno.permissions.query({ name: "net" })
* assertEquals(status.state, "granted");
* },
* });
* ```
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "true",
* permissions: {
* net: true,
* },
* async fn() {
* const status = await Deno.permissions.query({ name: "net" });
* assertEquals(status.state, "granted");
* },
* });
* ```
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "false",
* permissions: {
* net: false,
* },
* async fn() {
* const status = await Deno.permissions.query({ name: "net" });
* assertEquals(status.state, "denied");
* },
* });
* ```
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "localhost:8080",
* permissions: {
* net: ["localhost:8080"],
* },
* async fn() {
* const status = await Deno.permissions.query({ name: "net", host: "localhost:8080" });
* assertEquals(status.state, "granted");
* },
* });
* ```
*/
net?: "inherit" | boolean | string[];
/** Specifies if the `ffi` permission should be requested or revoked.
* If set to `"inherit"`, the current `ffi` permission will be inherited.
* If set to `true`, the global `ffi` permission will be requested.
* If set to `false`, the global `ffi` permission will be revoked.
*
* @default {false}
*/
ffi?: "inherit" | boolean | Array<string | URL>;
/** Specifies if the `read` permission should be requested or revoked.
* If set to `"inherit"`, the current `read` permission will be inherited.
* If set to `true`, the global `read` permission will be requested.
* If set to `false`, the global `read` permission will be revoked.
* If set to `Array<string | URL>`, the `read` permission will be requested with the
* specified file paths.
*
* @default {false}
*/
read?: "inherit" | boolean | Array<string | URL>;
/** Specifies if the `run` permission should be requested or revoked.
* If set to `"inherit"`, the current `run` permission will be inherited.
* If set to `true`, the global `run` permission will be requested.
* If set to `false`, the global `run` permission will be revoked.
*
* @default {false}
*/
run?: "inherit" | boolean | Array<string | URL>;
/** Specifies if the `write` permission should be requested or revoked.
* If set to `"inherit"`, the current `write` permission will be inherited.
* If set to `true`, the global `write` permission will be requested.
* If set to `false`, the global `write` permission will be revoked.
* If set to `Array<string | URL>`, the `write` permission will be requested with the
* specified file paths.
*
* @default {false}
*/
write?: "inherit" | boolean | Array<string | URL>;
}
/**
* Context that is passed to a testing function, which can be used to either
* gain information about the current test, or register additional test
* steps within the current test.
*
* @category Testing */
export interface TestContext {
/** The current test name. */
name: string;
/** The string URL of the current test. */
origin: string;
/** If the current test is a step of another test, the parent test context
* will be set here. */
parent?: TestContext;
/** Run a sub step of the parent test or step. Returns a promise
* that resolves to a boolean signifying if the step completed successfully.
*
* The returned promise never rejects unless the arguments are invalid.
*
* If the test was ignored the promise returns `false`.
*
* ```ts
* Deno.test({
* name: "a parent test",
* async fn(t) {
* console.log("before the step");
* await t.step({
* name: "step 1",
* fn(t) {
* console.log("current step:", t.name);
* }
* });
* console.log("after the step");
* }
* });
* ```
*/
step(definition: TestStepDefinition): Promise<boolean>;
/** Run a sub step of the parent test or step. Returns a promise
* that resolves to a boolean signifying if the step completed successfully.
*
* The returned promise never rejects unless the arguments are invalid.
*
* If the test was ignored the promise returns `false`.
*
* ```ts
* Deno.test(
* "a parent test",
* async (t) => {
* console.log("before the step");
* await t.step(
* "step 1",
* (t) => {
* console.log("current step:", t.name);
* }
* );
* console.log("after the step");
* }
* );
* ```
*/
step(
name: string,
fn: (t: TestContext) => void | Promise<void>,
): Promise<boolean>;
/** Run a sub step of the parent test or step. Returns a promise
* that resolves to a boolean signifying if the step completed successfully.
*
* The returned promise never rejects unless the arguments are invalid.
*
* If the test was ignored the promise returns `false`.
*
* ```ts
* Deno.test(async function aParentTest(t) {
* console.log("before the step");
* await t.step(function step1(t) {
* console.log("current step:", t.name);
* });
* console.log("after the step");
* });
* ```
*/
step(fn: (t: TestContext) => void | Promise<void>): Promise<boolean>;
}
/** @category Testing */
export interface TestStepDefinition {
/** The test function that will be tested when this step is executed. The
* function can take an argument which will provide information about the
* current step's context. */
fn: (t: TestContext) => void | Promise<void>;
/** The name of the step. */
name: string;
/** If truthy the current test step will be ignored.
*
* This is a quick way to skip over a step, but also can be used for
* conditional logic, like determining if an environment feature is present.
*/
ignore?: boolean;
/** Check that the number of async completed operations after the test step
* is the same as number of dispatched operations. This ensures that the
* code tested does not start async operations which it then does
* not await. This helps in preventing logic errors and memory leaks
* in the application code.
*
* Defaults to the parent test or step's value. */
sanitizeOps?: boolean;
/** Ensure the test step does not "leak" resources - like open files or
* network connections - by ensuring the open resources at the start of the
* step match the open resources at the end of the step.
*
* Defaults to the parent test or step's value. */
sanitizeResources?: boolean;
/** Ensure the test step does not prematurely cause the process to exit,
* for example via a call to {@linkcode Deno.exit}.
*
* Defaults to the parent test or step's value. */
sanitizeExit?: boolean;
}
/** @category Testing */
export interface TestDefinition {
fn: (t: TestContext) => void | Promise<void>;
/** The name of the test. */
name: string;
/** If truthy the current test step will be ignored.
*
* It is a quick way to skip over a step, but also can be used for
* conditional logic, like determining if an environment feature is present.
*/
ignore?: boolean;
/** If at least one test has `only` set to `true`, only run tests that have
* `only` set to `true` and fail the test suite. */
only?: boolean;
/** Check that the number of async completed operations after the test step
* is the same as number of dispatched operations. This ensures that the
* code tested does not start async operations which it then does
* not await. This helps in preventing logic errors and memory leaks
* in the application code.
*
* @default {true} */
sanitizeOps?: boolean;
/** Ensure the test step does not "leak" resources - like open files or
* network connections - by ensuring the open resources at the start of the
* test match the open resources at the end of the test.
*
* @default {true} */
sanitizeResources?: boolean;
/** Ensure the test case does not prematurely cause the process to exit,
* for example via a call to {@linkcode Deno.exit}.
*
* @default {true} */
sanitizeExit?: boolean;
/** Specifies the permissions that should be used to run the test.
*
* Set this to "inherit" to keep the calling runtime permissions, set this
* to "none" to revoke all permissions, or set a more specific set of
* permissions using a {@linkcode PermissionOptionsObject}.
*
* @default {"inherit"} */
permissions?: PermissionOptions;
}
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.
*
* `fn` can be async if required.
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "example test",
* fn() {
* assertEquals("world", "world");
* },
* });
*
* Deno.test({
* name: "example ignored test",
* ignore: Deno.build.os === "windows",
* fn() {
* // This test is ignored only on Windows machines
* },
* });
*
* Deno.test({
* name: "example async test",
* async fn() {
* const decoder = new TextDecoder("utf-8");
* const data = await Deno.readFile("hello_world.txt");
* assertEquals(decoder.decode(data), "Hello world");
* }
* });
* ```
*
* @category Testing
*/
export const test: DenoTest;
/**
* @category Testing
*/
export interface DenoTest {
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.
*
* `fn` can be async if required.
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test({
* name: "example test",
* fn() {
* assertEquals("world", "world");
* },
* });
*
* Deno.test({
* name: "example ignored test",
* ignore: Deno.build.os === "windows",
* fn() {
* // This test is ignored only on Windows machines
* },
* });
*
* Deno.test({
* name: "example async test",
* async fn() {
* const decoder = new TextDecoder("utf-8");
* const data = await Deno.readFile("hello_world.txt");
* assertEquals(decoder.decode(data), "Hello world");
* }
* });
* ```
*
* @category Testing
*/
(t: TestDefinition): void;
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.
*
* `fn` can be async if required.
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test("My test description", () => {
* assertEquals("hello", "hello");
* });
*
* Deno.test("My async test description", async () => {
* const decoder = new TextDecoder("utf-8");
* const data = await Deno.readFile("hello_world.txt");
* assertEquals(decoder.decode(data), "Hello world");
* });
* ```
*
* @category Testing
*/
(
name: string,
fn: (t: TestContext) => void | Promise<void>,
): void;
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.
*
* `fn` can be async if required. Declared function must have a name.
*
* ```ts
* import { assertEquals } from "jsr:@std/assert";
*
* Deno.test(function myTestName() {
* assertEquals("hello", "hello");
* });
*
* Deno.test(async function myOtherTestName() {
* const decoder = new TextDecoder("utf-8");
* const data = await Deno.readFile("hello_world.txt");
* assertEquals(decoder.decode(data), "Hello world");
* });
* ```
*
* @category Testing
*/
(fn: (t: TestContext) => void | Promise<void>): void;
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.
*
* `fn` can be async if required.
*
* ```ts
* import { assert, fail, assertEquals } from "jsr:@std/assert";
*
* Deno.test("My test description", { permissions: { read: true } }, (): void => {
* assertEquals("hello", "hello");
* });
*
* Deno.test("My async test description", { permissions: { read: false } }, async (): Promise<void> => {
* const decoder = new TextDecoder("utf-8");
* const data = await Deno.readFile("hello_world.txt");
* assertEquals(decoder.decode(data), "Hello world");
* });
* ```
*
* @category Testing
*/
(
name: string,
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
/** Register a test which will be run when `deno test` is used on the command
* line and the containing module looks like a test module.