mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
* Add bun-types to packages * Improve typing * Fix types in tests * Fix dts tests * Run formatter * Fix all type errors * Add strict mode, fix type errors * Add ffi changes * Move workflows to root * Add workflows * Remove labeler * Add child_process types * Fix synthetic defaults issue * Remove docs * Move scripts * Run prettier * Include examples in typechecking * captureStackTrace types * moved captureStackTrace types to globals * Address reviews Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
173 lines
4.3 KiB
TypeScript
173 lines
4.3 KiB
TypeScript
type AnyFunction = (...args: any[]) => any;
|
|
export function wrap({
|
|
test: test_,
|
|
it: it_,
|
|
describe: describe_,
|
|
beforeEach: beforeEach_ = undefined,
|
|
beforeAll: beforeAll_ = undefined,
|
|
afterEach: afterEach_ = undefined,
|
|
afterAll: afterAll_ = undefined,
|
|
}: any) {
|
|
if (it_ === undefined) {
|
|
it_ = test_;
|
|
}
|
|
|
|
var describe = (label, cb: AnyFunction) => {
|
|
return describe_(
|
|
label,
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`DESCRIBE [Enter] ${label}`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`DESCRIBE [Exit] ${label}`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`DESCRIBE [Enter] ${label}`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`DESCRIBE [Exit] ${label}`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
|
|
var it = (label, cb: AnyFunction) => {
|
|
console.log("Before", label);
|
|
return it_(
|
|
label,
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`TEST [Enter] ${label}`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`TEST [Exit] ${label}`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`TEST [Enter] ${label}`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`TEST [Exit] ${label}`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
|
|
var beforeEach = (cb: AnyFunction) => {
|
|
return beforeEach_(
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`BEFORE EACH [Enter]`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`BEFORE EACH [Exit]`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`BEFORE EACH [Enter]`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`BEFORE EACH [Exit]`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
var beforeAll = (cb: AnyFunction) => {
|
|
return beforeAll_(
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`BEFORE ALL [Enter]`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`BEFORE ALL [Exit]`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`BEFORE ALL [Enter]`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`BEFORE ALL [Exit]`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
var afterEach = (cb: AnyFunction) => {
|
|
return afterEach_(
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`AFTER EACH [Enter]`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`AFTER EACH [Exit]`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`AFTER EACH [Enter]`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`AFTER EACH [Exit]`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
var afterAll = (cb: AnyFunction) => {
|
|
return afterAll_(
|
|
cb instanceof async function () {}.constructor
|
|
? async () => {
|
|
console.log(`AFTER ALL [Enter]`);
|
|
try {
|
|
return await cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`AFTER ALL [Exit]`);
|
|
}
|
|
}
|
|
: () => {
|
|
console.log(`AFTER ALL [Enter]`);
|
|
try {
|
|
return cb();
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
console.log(`AFTER ALL [Exit]`);
|
|
}
|
|
},
|
|
);
|
|
};
|
|
|
|
return { describe, it, beforeEach, beforeAll, afterEach, afterAll };
|
|
}
|