diff --git a/CHANGELOG.md b/CHANGELOG.md index 27378af4..98fe60ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - fixed sourcemap if range in a comment - added cache for sourcemap conversion - fixed ECONNREFUSED on NodeJS 18 + - added new API `WSSession` for custom CDPSession * 2.7.5 - fixed special generated codes for original coverage diff --git a/lib/client/cdp-client.js b/lib/client/cdp-client.js index 3ae2befb..485bb523 100644 --- a/lib/client/cdp-client.js +++ b/lib/client/cdp-client.js @@ -4,7 +4,7 @@ const EC = require('eight-colors'); const { WebSocket } = require('../packages/monocart-coverage-vendor.js'); const Util = require('../utils/util.js'); -const CDPSession = require('./cdp-session.js'); +const WSSession = require('./ws-session.js'); const CoverageClient = require('./coverage-client.js'); const getDebuggerUrl = async (options) => { @@ -85,7 +85,7 @@ const getCDPSession = async (options) => { ws.once('open', () => { clearTimeout(timeoutId); Util.logDebug(`${EC.green('Connected')} ${url}`); - const session = new CDPSession(ws); + const session = new WSSession(ws); resolve([null, session]); }); diff --git a/lib/client/cdp-session.js b/lib/client/ws-session.js similarity index 95% rename from lib/client/cdp-session.js rename to lib/client/ws-session.js index fc2cc2f4..cb35ad3c 100644 --- a/lib/client/cdp-session.js +++ b/lib/client/ws-session.js @@ -1,6 +1,6 @@ const { EventEmitter } = require('events'); -class CDPSession extends EventEmitter { +class WSSession extends EventEmitter { constructor(ws) { super(); this.ws = ws; @@ -60,4 +60,4 @@ class CDPSession extends EventEmitter { } } -module.exports = CDPSession; +module.exports = WSSession; diff --git a/lib/index.d.ts b/lib/index.d.ts index 07b7ea5d..6246b7df 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -452,6 +452,14 @@ declare namespace MCR { detach: () => Promise } + /** custom websocket CDPSession */ + export class WSSession implements CDPSession { + constructor(ws: any); + send: (method: string, params?: any) => Promise; + on: (type: string, handler: (e: any) => void) => void; + detach: () => Promise + } + export interface CDPOptions { /** Adapt to the CDPSession of Playwright or Puppeteer */ session?: CDPSession; diff --git a/lib/index.js b/lib/index.js index 2c3cd897..52f8fa6c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,6 +11,8 @@ const { getInputData, readFromDir, generateCoverageReports } = require('./generate.js'); const { getSnapshot, diffSnapshot } = require('./utils/snapshot.js'); + +const WSSession = require('./client/ws-session.js'); const CDPClient = require('./client/cdp-client.js'); const resolveConfigOptions = async (configPath) => { @@ -286,6 +288,7 @@ const MCR = function(options) { MCR.CoverageReport = CoverageReport; MCR.getSnapshot = getSnapshot; MCR.diffSnapshot = diffSnapshot; +MCR.WSSession = WSSession; MCR.CDPClient = CDPClient; module.exports = MCR; diff --git a/lib/index.mjs b/lib/index.mjs index 0ffc8078..a8efd563 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -3,4 +3,6 @@ export default MCR; export const CoverageReport = MCR.CoverageReport; export const getSnapshot = MCR.getSnapshot; export const diffSnapshot = MCR.diffSnapshot; + +export const WSSession = MCR.WSSession; export const CDPClient = MCR.CDPClient; diff --git a/scripts/template/markdown.html b/scripts/template/markdown.html index cd1ec301..d0883995 100644 --- a/scripts/template/markdown.html +++ b/scripts/template/markdown.html @@ -6,11 +6,10 @@ {placeholder_title} - -
+
{placeholder_content}