1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-14 11:27:57 -05:00
denoland-deno/tests/node_compat/test/parallel/test-util-inspect-proxy.js
Matt Mastracci f5e46c9bf2
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.

This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.

While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).

And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.

For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00

172 lines
6.7 KiB
JavaScript

// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const util = require('util');
// TODO(wafuwafu13): Implement 'internal/test/binding'
// const { internalBinding } = require('internal/test/binding');
// const processUtil = internalBinding('util');
const opts = { showProxy: true };
// let proxyObj;
// let called = false;
// const target = {
// [util.inspect.custom](depth, { showProxy }) {
// if (showProxy === false) {
// called = true;
// if (proxyObj !== this) {
// throw new Error('Failed');
// }
// }
// return [1, 2, 3];
// }
// };
// // TODO(wafuwafu13): Fix Uncaught Error
// const handler = {
// getPrototypeOf() { throw new Error('getPrototypeOf'); },
// setPrototypeOf() { throw new Error('setPrototypeOf'); },
// isExtensible() { throw new Error('isExtensible'); },
// preventExtensions() { throw new Error('preventExtensions'); },
// getOwnPropertyDescriptor() { throw new Error('getOwnPropertyDescriptor'); },
// defineProperty() { throw new Error('defineProperty'); },
// has() { throw new Error('has'); },
// get() { throw new Error('get'); },
// set() { throw new Error('set'); },
// deleteProperty() { throw new Error('deleteProperty'); },
// ownKeys() { throw new Error('ownKeys'); },
// apply() { throw new Error('apply'); },
// construct() { throw new Error('construct'); }
// };
// proxyObj = new Proxy(target, handler);
// // Inspecting the proxy should not actually walk it's properties
// util.inspect(proxyObj, opts);
// // Make sure inspecting object does not trigger any proxy traps.
// util.format('%s', proxyObj);
// TODO(wafuwafu13): Implement processUtil
// // getProxyDetails is an internal method, not intended for public use.
// // This is here to test that the internals are working correctly.
// let details = processUtil.getProxyDetails(proxyObj, true);
// assert.strictEqual(target, details[0]);
// assert.strictEqual(handler, details[1]);
// details = processUtil.getProxyDetails(proxyObj);
// assert.strictEqual(target, details[0]);
// assert.strictEqual(handler, details[1]);
// details = processUtil.getProxyDetails(proxyObj, false);
// assert.strictEqual(target, details);
// assert.strictEqual(
// util.inspect(proxyObj, opts),
// 'Proxy [\n' +
// ' [ 1, 2, 3 ],\n' +
// ' {\n' +
// ' getPrototypeOf: [Function: getPrototypeOf],\n' +
// ' setPrototypeOf: [Function: setPrototypeOf],\n' +
// ' isExtensible: [Function: isExtensible],\n' +
// ' preventExtensions: [Function: preventExtensions],\n' +
// ' getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor],\n' +
// ' defineProperty: [Function: defineProperty],\n' +
// ' has: [Function: has],\n' +
// ' get: [Function: get],\n' +
// ' set: [Function: set],\n' +
// ' deleteProperty: [Function: deleteProperty],\n' +
// ' ownKeys: [Function: ownKeys],\n' +
// ' apply: [Function: apply],\n' +
// ' construct: [Function: construct]\n' +
// ' }\n' +
// ']'
// );
// TODO(wafuwafu13): Implement processUtil
// // Using getProxyDetails with non-proxy returns undefined
// assert.strictEqual(processUtil.getProxyDetails({}), undefined);
// // Inspecting a proxy without the showProxy option set to true should not
// // trigger any proxy handlers.
// assert.strictEqual(util.inspect(proxyObj), '[ 1, 2, 3 ]');
// assert(called);
// Yo dawg, I heard you liked Proxy so I put a Proxy
// inside your Proxy that proxies your Proxy's Proxy.
const proxy1 = new Proxy({}, {});
const proxy2 = new Proxy(proxy1, {});
const proxy3 = new Proxy(proxy2, proxy1);
const proxy4 = new Proxy(proxy1, proxy2);
const proxy5 = new Proxy(proxy3, proxy4);
const proxy6 = new Proxy(proxy5, proxy5);
const expected0 = '{}';
const expected1 = 'Proxy [ {}, {} ]';
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
const expected5 = 'Proxy [\n ' +
'Proxy [ Proxy [ Proxy [Array], {} ], Proxy [ {}, {} ] ],\n' +
' Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [Array], {} ] ]' +
'\n]';
const expected6 = 'Proxy [\n' +
' Proxy [\n' +
' Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ]\n' +
' ],\n' +
' Proxy [\n' +
' Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ]\n' +
' ]\n' +
']';
// assert.strictEqual(
// util.inspect(proxy1, { showProxy: 1, depth: null }),
// expected1);
// assert.strictEqual(util.inspect(proxy2, opts), expected2);
// assert.strictEqual(util.inspect(proxy3, opts), expected3);
// assert.strictEqual(util.inspect(proxy4, opts), expected4);
// assert.strictEqual(util.inspect(proxy5, opts), expected5);
// assert.strictEqual(util.inspect(proxy6, opts), expected6);
// assert.strictEqual(util.inspect(proxy1), expected0);
// assert.strictEqual(util.inspect(proxy2), expected0);
// assert.strictEqual(util.inspect(proxy3), expected0);
// assert.strictEqual(util.inspect(proxy4), expected0);
// assert.strictEqual(util.inspect(proxy5), expected0);
// assert.strictEqual(util.inspect(proxy6), expected0);
// // Just for fun, let's create a Proxy using Arrays.
// const proxy7 = new Proxy([], []);
// const expected7 = 'Proxy [ [], [] ]';
// assert.strictEqual(util.inspect(proxy7, opts), expected7);
// assert.strictEqual(util.inspect(proxy7), '[]');
// // Now we're just getting silly, right?
// const proxy8 = new Proxy(Date, []);
// const proxy9 = new Proxy(Date, String);
// const expected8 = 'Proxy [ [Function: Date], [] ]';
// const expected9 = 'Proxy [ [Function: Date], [Function: String] ]';
// assert.strictEqual(util.inspect(proxy8, opts), expected8);
// assert.strictEqual(util.inspect(proxy9, opts), expected9);
// assert.strictEqual(util.inspect(proxy8), '[Function: Date]');
// assert.strictEqual(util.inspect(proxy9), '[Function: Date]');
// const proxy10 = new Proxy(() => {}, {});
// const proxy11 = new Proxy(() => {}, {
// get() {
// return proxy11;
// },
// apply() {
// return proxy11;
// }
// });
// const expected10 = '[Function (anonymous)]';
// const expected11 = '[Function (anonymous)]';
// assert.strictEqual(util.inspect(proxy10), expected10);
// assert.strictEqual(util.inspect(proxy11), expected11);