0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

Compare commits

...

4 commits

Author SHA1 Message Date
Marvin Hagemeister
81b4c74c84
Merge 83272f7e8b into e4a16e91fa 2025-01-20 10:33:35 +05:30
ryu
e4a16e91fa
docs(readme): update redirected links (#27726) 2025-01-20 03:01:25 +00:00
Satya Rohith
83272f7e8b
Merge branch 'main' into fix-internal-test-types 2024-11-02 15:09:34 +05:30
Marvin Hagemeister
2a10023fef chore: improve internal test code typings 2024-10-10 14:07:54 +02:00
3 changed files with 53 additions and 19 deletions

View file

@ -6,8 +6,8 @@
<img align="right" src="https://deno.land/logo.svg" height="150px" alt="the deno mascot dinosaur standing in the rain">
[Deno](https://www.deno.com)
([/ˈdiːnoʊ/](http://ipa-reader.xyz/?text=%CB%88di%CB%90no%CA%8A), pronounced
[Deno](https://deno.com)
([/ˈdiːnoʊ/](https://ipa-reader.com/?text=%CB%88di%CB%90no%CA%8A), pronounced
`dee-no`) is a JavaScript, TypeScript, and WebAssembly runtime with secure
defaults and a great developer experience. It's built on [V8](https://v8.dev/),
[Rust](https://www.rust-lang.org/), and [Tokio](https://tokio.rs/).

View file

@ -1,5 +1,7 @@
// Copyright 2018-2025 the Deno authors. MIT license.
// @ts-check
import { core, primordials } from "ext:core/mod.js";
import { escapeName, withPermissions } from "ext:cli/40_test_common.js";
@ -33,6 +35,14 @@ import { setExitHandler } from "ext:deno_os/30_os.js";
const DenoNs = globalThis.Deno;
/**
* @typedef {() => Promise<"ignored" | "ok" | { failed: any}>} TestFunction
*
* @typedef {{
* fileName: string,
* lineNumber: number,
* columnNumber: number
* }} TestLocation
*
* @typedef {{
* id: number,
* name: string,
@ -40,17 +50,17 @@ const DenoNs = globalThis.Deno;
* origin: string,
* location: TestLocation,
* ignore: boolean,
* only: boolean.
* only: boolean,
* sanitizeOps: boolean,
* sanitizeResources: boolean,
* sanitizeExit: boolean,
* permissions: PermissionOptions,
* permissions: Deno.PermissionOptions,
* }} TestDescription
*
* @typedef {{
* id: number,
* name: string,
* fn: TestFunction
* fn: TestFunction,
* origin: string,
* location: TestLocation,
* ignore: boolean,
@ -79,12 +89,12 @@ const DenoNs = globalThis.Deno;
* @typedef {{
* id: number,
* name: string,
* fn: BenchFunction
* fn: BenchFunction,
* origin: string,
* ignore: boolean,
* only: boolean.
* only: boolean,
* sanitizeExit: boolean,
* permissions: PermissionOptions,
* permissions: Deno.PermissionOptions,
* }} BenchDescription
*/
@ -125,6 +135,11 @@ function assertExit(fn, isTest) {
};
}
/**
* @param {*} fn
* @param {TestDescription | TestStepDescription} desc
* @returns {() => Promise<"ignored" | "ok" | { failed: any}>}
*/
function wrapOuter(fn, desc) {
return async function outerWrapped() {
try {
@ -145,9 +160,10 @@ function wrapOuter(fn, desc) {
}
function wrapInner(fn) {
/** @param desc {TestDescription | TestStepDescription} */
/** @param {TestDescription | TestStepDescription} desc */
return async function innerWrapped(desc) {
function getRunningStepDescs() {
/** @type {TestStepDescription[]} */
const results = [];
let childDesc = desc;
while (childDesc.parent != null) {
@ -206,7 +222,11 @@ function wrapInner(fn) {
const registerTestIdRetBuf = new Uint32Array(1);
const registerTestIdRetBufU8 = new Uint8Array(registerTestIdRetBuf.buffer);
// As long as we're using one isolate per test, we can cache the origin since it won't change
/**
* As long as we're using one isolate per test, we can cache the origin
* since it won't change.
* @type {string | undefined}
*/
let cachedOrigin = undefined;
function testInner(
@ -355,6 +375,10 @@ test.only = function (
return testInner(nameOrFnOrOptions, optionsOrFn, maybeFn, { only: true });
};
/**
* @param {TestDescription | TestStepDescription} desc
* @returns {string}
*/
function getFullName(desc) {
if ("parent" in desc) {
return `${getFullName(desc.parent)} ... ${desc.name}`;
@ -362,10 +386,19 @@ function getFullName(desc) {
return desc.name;
}
/**
* @param {TestDescription | TestStepDescription} desc
* @returns {boolean}
*/
function usesSanitizer(desc) {
return desc.sanitizeResources || desc.sanitizeOps || desc.sanitizeExit;
}
/**
* @param {TestStepDescription} desc
* @param {*} result
* @param {number} elapsed
*/
function stepReportResult(desc, result, elapsed) {
const state = MapPrototypeGet(testStates, desc.id);
for (const childDesc of state.children) {
@ -380,7 +413,9 @@ function stepReportResult(desc, result, elapsed) {
}
}
/** @param desc {TestDescription | TestStepDescription} */
/**
* @param {TestDescription | TestStepDescription} desc
*/
function createTestContext(desc) {
let parent;
let level;
@ -412,8 +447,8 @@ function createTestContext(desc) {
*/
origin: desc.origin,
/**
* @param nameOrFnOrOptions {string | TestStepDefinition | ((t: TestContext) => void | Promise<void>)}
* @param maybeFn {((t: TestContext) => void | Promise<void>) | undefined}
* @param {string | TestStepDescription | ((t: TestContext) => void | Promise<void>)} nameOrFnOrOptions
* @param {((t: TestContext) => void | Promise<void>) | undefined} maybeFn
*/
async step(nameOrFnOrOptions, maybeFn) {
if (MapPrototypeGet(testStates, desc.id).completed) {
@ -423,6 +458,7 @@ function createTestContext(desc) {
);
}
/** @type {TestStepDescription & { fn: any }} */
let stepDesc;
if (typeof nameOrFnOrOptions === "string") {
if (typeof maybeFn !== "function") {
@ -500,10 +536,8 @@ function createTestContext(desc) {
/**
* Wrap a user test function in one which returns a structured result.
* @template T {Function}
* @param testFn {T}
* @param desc {TestDescription | TestStepDescription}
* @returns {T}
* @param {TestDescription | TestStepDescription} desc
* @returns {TestFunction}
*/
function wrapTest(desc) {
let testFn = wrapInner(desc.fn);

View file

@ -48,8 +48,8 @@ const packages: Package[] = [{
const markdownText = `# Deno
[Deno](https://www.deno.com)
([/ˈdiːnoʊ/](http://ipa-reader.xyz/?text=%CB%88di%CB%90no%CA%8A), pronounced
[Deno](https://deno.com)
([/ˈdiːnoʊ/](https://ipa-reader.com/?text=%CB%88di%CB%90no%CA%8A), pronounced
\`dee-no\`) is a JavaScript, TypeScript, and WebAssembly runtime with secure
defaults and a great developer experience. It's built on [V8](https://v8.dev/),
[Rust](https://www.rust-lang.org/), and [Tokio](https://tokio.rs/).