browser-ava 2.3.39 → 2.3.41

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.39",
3
+ "version": "2.3.41",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -41,6 +41,7 @@
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",
44
45
  "koa": "^3.0.1",
45
46
  "koa-static": "^5.0.0",
46
47
  "playwright": "^1.56.0",
@@ -0,0 +1 @@
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};
@@ -1,3 +1,4 @@
1
+ import { decycle } from "./json-cyclic.mjs";
1
2
  import { testModules, test } from "./ava.mjs";
2
3
  import {
3
4
  calculateSummary,
@@ -7,7 +8,7 @@ import {
7
8
  } from "./util.mjs";
8
9
  import { isEqual } from "./assertions.mjs";
9
10
 
10
- let ws = new WebSocket(`ws://${location.host}`);
11
+ const ws = new WebSocket(`ws://${location.host}`);
11
12
  ws.onerror = console.error;
12
13
 
13
14
  function primitiveRoString() {
@@ -33,7 +34,7 @@ for (const action of ["log", "info", "error"]) {
33
34
 
34
35
  console[action] = (...data) => {
35
36
  if (ws) {
36
- ws.send(JSON.stringify({ action, data }, allErrorProperties));
37
+ ws.send(JSON.stringify(decycle({ action, data }), allErrorProperties));
37
38
  }
38
39
  former(...data);
39
40
  };
@@ -202,7 +203,7 @@ async function runTest(parent, tm, testInstance) {
202
203
  } finally {
203
204
  ws.send(
204
205
  JSON.stringify(
205
- { action: "update", data: testInstance },
206
+ decycle({ action: "update", data: testInstance }),
206
207
  allErrorProperties
207
208
  )
208
209
  );
@@ -258,7 +259,7 @@ async function runTestModules() {
258
259
  }
259
260
 
260
261
  ws.send(
261
- JSON.stringify({ action: "result", data: testModules }, allErrorProperties)
262
+ JSON.stringify(decycle({ action: "result", data: testModules }), allErrorProperties)
262
263
  );
263
264
 
264
265
  displayTests();
@@ -12,6 +12,7 @@ import { calculateSummary, summaryMessages } from "./browser/util.mjs";
12
12
  import { resolveImport, utf8EncodingOptions } from "./resolver.mjs";
13
13
  import { globby } from "globby";
14
14
  import chalk from "chalk";
15
+ import { encycle } from "json-cyclic";
15
16
  import pkg from "../package.json" with { type: "json" };
16
17
 
17
18
  const knownBrowsers = {
@@ -106,7 +107,7 @@ program
106
107
 
107
108
  wss.on("connection", ws => {
108
109
  ws.on("message", async content => {
109
- const { action, data } = JSON.parse(content);
110
+ const { action, data } = encycle(JSON.parse(content));
110
111
  switch (action) {
111
112
  case "info":
112
113
  console.info(...data);