mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
chore: use internal namespace in 40_testing.js (#21141)
Towards #21136 - [x] assign serializePermissions, setTimeout and setExitHandler APIs to internal namespace - [x] remove usage of assert
This commit is contained in:
parent
8ecb649182
commit
9f2e56ba96
5 changed files with 21 additions and 15 deletions
|
@ -7,11 +7,13 @@
|
||||||
|
|
||||||
const core = globalThis.Deno.core;
|
const core = globalThis.Deno.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
import { setExitHandler } from "ext:runtime/30_os.js";
|
|
||||||
import { Console } from "ext:deno_console/01_console.js";
|
const internals = globalThis.__bootstrap.internals;
|
||||||
import { serializePermissions } from "ext:runtime/10_permissions.js";
|
const {
|
||||||
import { setTimeout } from "ext:deno_web/02_timers.js";
|
setExitHandler,
|
||||||
import { assert } from "ext:deno_web/00_infra.js";
|
Console,
|
||||||
|
serializePermissions,
|
||||||
|
} = internals;
|
||||||
|
|
||||||
const opSanitizerDelayResolveQueue = [];
|
const opSanitizerDelayResolveQueue = [];
|
||||||
let hasSetOpSanitizerDelayMacrotask = false;
|
let hasSetOpSanitizerDelayMacrotask = false;
|
||||||
|
@ -445,8 +447,7 @@ function assertResources(fn) {
|
||||||
function assertExit(fn, isTest) {
|
function assertExit(fn, isTest) {
|
||||||
return async function exitSanitizer(...params) {
|
return async function exitSanitizer(...params) {
|
||||||
setExitHandler((exitCode) => {
|
setExitHandler((exitCode) => {
|
||||||
assert(
|
throw new Error(
|
||||||
false,
|
|
||||||
`${
|
`${
|
||||||
isTest ? "Test case" : "Bench"
|
isTest ? "Test case" : "Bench"
|
||||||
} attempted to exit with exit code: ${exitCode}`,
|
} attempted to exit with exit code: ${exitCode}`,
|
||||||
|
@ -1155,8 +1156,7 @@ function wrapBenchmark(desc) {
|
||||||
|
|
||||||
if (desc.sanitizeExit) {
|
if (desc.sanitizeExit) {
|
||||||
setExitHandler((exitCode) => {
|
setExitHandler((exitCode) => {
|
||||||
assert(
|
throw new Error(
|
||||||
false,
|
|
||||||
`Bench attempted to exit with exit code: ${exitCode}`,
|
`Bench attempted to exit with exit code: ${exitCode}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
6
cli/tests/testdata/bench/exit_sanitizer.out
vendored
6
cli/tests/testdata/bench/exit_sanitizer.out
vendored
|
@ -5,10 +5,10 @@ runtime: deno [WILDCARD] ([WILDCARD])
|
||||||
[WILDCARD]/bench/exit_sanitizer.ts
|
[WILDCARD]/bench/exit_sanitizer.ts
|
||||||
benchmark time (avg) iter/s (min … max) p75 p99 p995
|
benchmark time (avg) iter/s (min … max) p75 p99 p995
|
||||||
--------------------------------------------------------------- -----------------------------
|
--------------------------------------------------------------- -----------------------------
|
||||||
exit(0) error: AssertionError: Bench attempted to exit with exit code: 0
|
exit(0) error: Error: Bench attempted to exit with exit code: 0
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
exit(1) error: AssertionError: Bench attempted to exit with exit code: 1
|
exit(1) error: Error: Bench attempted to exit with exit code: 1
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
exit(2) error: AssertionError: Bench attempted to exit with exit code: 2
|
exit(2) error: Error: Bench attempted to exit with exit code: 2
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
error: Bench failed
|
error: Bench failed
|
||||||
|
|
6
cli/tests/testdata/test/exit_sanitizer.out
vendored
6
cli/tests/testdata/test/exit_sanitizer.out
vendored
|
@ -7,21 +7,21 @@ exit(2) ... FAILED ([WILDCARD])
|
||||||
ERRORS
|
ERRORS
|
||||||
|
|
||||||
exit(0) => ./test/exit_sanitizer.ts:[WILDCARD]
|
exit(0) => ./test/exit_sanitizer.ts:[WILDCARD]
|
||||||
error: AssertionError: Test case attempted to exit with exit code: 0
|
error: Error: Test case attempted to exit with exit code: 0
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
^
|
^
|
||||||
at [WILDCARD]
|
at [WILDCARD]
|
||||||
at [WILDCARD]/test/exit_sanitizer.ts:2:8
|
at [WILDCARD]/test/exit_sanitizer.ts:2:8
|
||||||
|
|
||||||
exit(1) => ./test/exit_sanitizer.ts:[WILDCARD]
|
exit(1) => ./test/exit_sanitizer.ts:[WILDCARD]
|
||||||
error: AssertionError: Test case attempted to exit with exit code: 1
|
error: Error: Test case attempted to exit with exit code: 1
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
^
|
^
|
||||||
at [WILDCARD]
|
at [WILDCARD]
|
||||||
at [WILDCARD]/test/exit_sanitizer.ts:6:8
|
at [WILDCARD]/test/exit_sanitizer.ts:6:8
|
||||||
|
|
||||||
exit(2) => ./test/exit_sanitizer.ts:[WILDCARD]
|
exit(2) => ./test/exit_sanitizer.ts:[WILDCARD]
|
||||||
error: AssertionError: Test case attempted to exit with exit code: 2
|
error: Error: Test case attempted to exit with exit code: 2
|
||||||
Deno.exit(2);
|
Deno.exit(2);
|
||||||
^
|
^
|
||||||
at [WILDCARD]
|
at [WILDCARD]
|
||||||
|
|
|
@ -4,6 +4,7 @@ const core = globalThis.Deno.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
import { pathFromURL } from "ext:deno_web/00_infra.js";
|
import { pathFromURL } from "ext:deno_web/00_infra.js";
|
||||||
import { Event, EventTarget } from "ext:deno_web/02_event.js";
|
import { Event, EventTarget } from "ext:deno_web/02_event.js";
|
||||||
|
const internals = globalThis.__bootstrap.internals;
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
ArrayIsArray,
|
ArrayIsArray,
|
||||||
|
@ -291,4 +292,6 @@ function serializePermissions(permissions) {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internals.serializePermissions = serializePermissions;
|
||||||
|
|
||||||
export { Permissions, permissions, PermissionStatus, serializePermissions };
|
export { Permissions, permissions, PermissionStatus, serializePermissions };
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const core = globalThis.Deno.core;
|
const core = globalThis.Deno.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
|
const internals = globalThis.__bootstrap.internals;
|
||||||
import { Event, EventTarget } from "ext:deno_web/02_event.js";
|
import { Event, EventTarget } from "ext:deno_web/02_event.js";
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
|
@ -106,6 +107,8 @@ function execPath() {
|
||||||
return ops.op_exec_path();
|
return ops.op_exec_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internals.setExitHandler = setExitHandler;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
env,
|
env,
|
||||||
execPath,
|
execPath,
|
||||||
|
|
Loading…
Reference in a new issue