browser-ava 2.3.41 → 2.3.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-ava",
3
- "version": "2.3.41",
3
+ "version": "2.3.42",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -41,14 +41,13 @@
41
41
  "commander": "^14.0.1",
42
42
  "es-module-lexer": "^1.7.0",
43
43
  "globby": "^15.0.0",
44
- "json-cyclic": "^1.0.2",
45
44
  "koa": "^3.0.1",
46
45
  "koa-static": "^5.0.0",
47
46
  "playwright": "^1.56.0",
48
47
  "ws": "^8.18.3"
49
48
  },
50
49
  "devDependencies": {
51
- "@types/node": "^24.7.2",
50
+ "@types/node": "^24.8.0",
52
51
  "ava": "^6.4.1",
53
52
  "c8": "^10.1.3",
54
53
  "documentation": "^14.0.3",
@@ -0,0 +1,170 @@
1
+ /*
2
+ cycle.js
3
+ 2021-05-31
4
+
5
+ Public Domain.
6
+
7
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+
9
+ This code should be minified before deployment.
10
+ See https://www.crockford.com/jsmin.html
11
+
12
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
13
+ NOT CONTROL.
14
+ */
15
+
16
+ // The file uses the WeakMap feature of ES6.
17
+
18
+ /*jslint eval */
19
+
20
+ /*property
21
+ $ref, decycle, forEach, get, indexOf, isArray, keys, length, push,
22
+ retrocycle, set, stringify, test
23
+ */
24
+
25
+ export function decycle(object, replacer) {
26
+ // Make a deep copy of an object or array, assuring that there is at most
27
+ // one instance of each object or array in the resulting structure. The
28
+ // duplicate references (which might be forming cycles) are replaced with
29
+ // an object of the form
30
+
31
+ // {"$ref": PATH}
32
+
33
+ // where the PATH is a JSONPath string that locates the first occurance.
34
+
35
+ // So,
36
+
37
+ // var a = [];
38
+ // a[0] = a;
39
+ // return JSON.stringify(JSON.decycle(a));
40
+
41
+ // produces the string '[{"$ref":"$"}]'.
42
+
43
+ // If a replacer function is provided, then it will be called for each value.
44
+ // A replacer function receives a value and returns a replacement value.
45
+
46
+ // JSONPath is used to locate the unique object. $ indicates the top level of
47
+ // the object or array. [NUMBER] or [STRING] indicates a child element or
48
+ // property.
49
+
50
+ var objects = new WeakMap(); // object to path mappings
51
+
52
+ return (function derez(value, path) {
53
+ // The derez function recurses through the object, producing the deep copy.
54
+
55
+ var old_path; // The path of an earlier occurance of value
56
+ var nu; // The new object or array
57
+
58
+ // If a replacer function was provided, then call it to get a replacement value.
59
+
60
+ if (replacer !== undefined) {
61
+ value = replacer(value);
62
+ }
63
+
64
+ // typeof null === "object", so go on if this value is really an object but not
65
+ // one of the weird builtin objects.
66
+
67
+ if (
68
+ typeof value === "object" &&
69
+ value !== null &&
70
+ !(value instanceof Boolean) &&
71
+ !(value instanceof Date) &&
72
+ !(value instanceof Number) &&
73
+ !(value instanceof RegExp) &&
74
+ !(value instanceof String)
75
+ ) {
76
+ // If the value is an object or array, look to see if we have already
77
+ // encountered it. If so, return a {"$ref":PATH} object. This uses an
78
+ // ES6 WeakMap.
79
+
80
+ old_path = objects.get(value);
81
+ if (old_path !== undefined) {
82
+ return { $ref: old_path };
83
+ }
84
+
85
+ // Otherwise, accumulate the unique value and its path.
86
+
87
+ objects.set(value, path);
88
+
89
+ // If it is an array, replicate the array.
90
+
91
+ if (Array.isArray(value)) {
92
+ nu = [];
93
+ value.forEach(function (element, i) {
94
+ nu[i] = derez(element, path + "[" + i + "]");
95
+ });
96
+ } else {
97
+ // If it is an object, replicate the object.
98
+
99
+ nu = {};
100
+ Object.keys(value).forEach(function (name) {
101
+ nu[name] = derez(
102
+ value[name],
103
+ path + "[" + JSON.stringify(name) + "]"
104
+ );
105
+ });
106
+ }
107
+ return nu;
108
+ }
109
+ return value;
110
+ })(object, "$");
111
+ }
112
+
113
+ export function retrocycle($) {
114
+ // Restore an object that was reduced by decycle. Members whose values are
115
+ // objects of the form
116
+ // {$ref: PATH}
117
+ // are replaced with references to the value found by the PATH. This will
118
+ // restore cycles. The object will be mutated.
119
+
120
+ // The eval function is used to locate the values described by a PATH. The
121
+ // root object is kept in a $ variable. A regular expression is used to
122
+ // assure that the PATH is extremely well formed. The regexp contains nested
123
+ // * quantifiers. That has been known to have extremely bad performance
124
+ // problems on some browsers for very long strings. A PATH is expected to be
125
+ // reasonably short. A PATH is allowed to belong to a very restricted subset of
126
+ // Goessner's JSONPath.
127
+
128
+ // So,
129
+ // var s = '[{"$ref":"$"}]';
130
+ // return JSON.retrocycle(JSON.parse(s));
131
+ // produces an array containing a single element which is the array itself.
132
+
133
+ var px =
134
+ /^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\(?:[\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*")\])*$/;
135
+
136
+ (function rez(value) {
137
+ // The rez function walks recursively through the object looking for $ref
138
+ // properties. When it finds one that has a value that is a path, then it
139
+ // replaces the $ref object with a reference to the value that is found by
140
+ // the path.
141
+
142
+ if (value && typeof value === "object") {
143
+ if (Array.isArray(value)) {
144
+ value.forEach(function (element, i) {
145
+ if (typeof element === "object" && element !== null) {
146
+ var path = element.$ref;
147
+ if (typeof path === "string" && px.test(path)) {
148
+ value[i] = eval(path);
149
+ } else {
150
+ rez(element);
151
+ }
152
+ }
153
+ });
154
+ } else {
155
+ Object.keys(value).forEach(function (name) {
156
+ var item = value[name];
157
+ if (typeof item === "object" && item !== null) {
158
+ var path = item.$ref;
159
+ if (typeof path === "string" && px.test(path)) {
160
+ value[name] = eval(path);
161
+ } else {
162
+ rez(item);
163
+ }
164
+ }
165
+ });
166
+ }
167
+ }
168
+ })($);
169
+ return $;
170
+ }
@@ -1,4 +1,4 @@
1
- import { decycle } from "./json-cyclic.mjs";
1
+ import { decycle } from "./cycle.mjs";
2
2
  import { testModules, test } from "./ava.mjs";
3
3
  import {
4
4
  calculateSummary,
@@ -9,10 +9,10 @@ import Cors from "@koa/cors";
9
9
  import { WebSocketServer } from "ws";
10
10
  import { program, Option } from "commander";
11
11
  import { calculateSummary, summaryMessages } from "./browser/util.mjs";
12
+ import { retrocycle } from "./browser/cycle.mjs";
12
13
  import { resolveImport, utf8EncodingOptions } from "./resolver.mjs";
13
14
  import { globby } from "globby";
14
15
  import chalk from "chalk";
15
- import { encycle } from "json-cyclic";
16
16
  import pkg from "../package.json" with { type: "json" };
17
17
 
18
18
  const knownBrowsers = {
@@ -107,7 +107,7 @@ program
107
107
 
108
108
  wss.on("connection", ws => {
109
109
  ws.on("message", async content => {
110
- const { action, data } = encycle(JSON.parse(content));
110
+ const { action, data } = retrocycle(JSON.parse(content));
111
111
  switch (action) {
112
112
  case "info":
113
113
  console.info(...data);
@@ -1 +0,0 @@
1
- const isArray=e=>Array.isArray(e),isObject=e=>"Object"===Object.prototype.toString.call(e).slice(8,-1),validate=e=>{if(void 0===e)throw new Error("This method requires one parameter");if(!isArray(e)&&!isObject(e))throw new TypeError("This method only accepts arrays and objects")},isRef=e=>isObject(e)&&e.hasOwnProperty("$ref")&&1===Object.keys(e).length&&!!e.$ref&&"$"===e.$ref.charAt(0),encycle=arg=>{validate(arg);const recurs=value=>isArray(value)||isObject(value)?isArray(value)?value.map((elem,i)=>isRef(elem)?(value[i]=eval("arg"+elem.$ref.slice(1)),value):recurs(elem)):Object.keys(value).reduce((accum,key)=>(accum[key]=isRef(value[key])?eval("arg"+value[key].$ref.slice(1)):recurs(value[key]),accum),value):value;return recurs(arg)},findRef=(e,r)=>Object.keys(r).find(a=>r[a]===e),decycle=e=>{validate(e);let r={};const a=(e,c="$")=>{const s=findRef(e,r);return s?{$ref:s}:isArray(e)||isObject(e)?(r[c]=e,isArray(e)?e.map((e,r)=>a(e,`${c}[${r}]`)):Object.keys(e).reduce((r,s)=>(r[s]=a(e[s],`${c}.${s}`),r),{})):e};return a(e)};export{decycle,encycle};