@jsenv/core 27.0.0-alpha.5 → 27.0.0-alpha.52
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/dist/event_source_client.js +545 -0
- package/dist/event_source_client.js.map +187 -0
- package/dist/html_supervisor_installer.js +1236 -0
- package/dist/html_supervisor_installer.js.map +337 -0
- package/dist/html_supervisor_setup.js +95 -0
- package/dist/html_supervisor_setup.js.map +57 -0
- package/dist/import_meta_hot.js +86 -0
- package/dist/import_meta_hot.js.map +42 -0
- package/main.js +8 -1
- package/package.json +22 -21
- package/readme.md +4 -12
- package/src/build/build.js +750 -438
- package/src/build/build_urls_generator.js +56 -22
- package/src/build/graph_utils.js +31 -0
- package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
- package/src/build/inject_service_worker_urls.js +79 -0
- package/src/build/resync_ressource_hints.js +68 -0
- package/src/build/start_build_server.js +255 -0
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
- package/src/dev/start_dev_server.js +136 -30
- package/src/execute/execute.js +31 -6
- package/src/execute/run.js +19 -56
- package/src/execute/runtimes/browsers/from_playwright.js +204 -147
- package/src/execute/runtimes/node/controllable_file.mjs +26 -10
- package/src/execute/runtimes/node/node_execution_performance.js +67 -0
- package/src/execute/runtimes/node/node_process.js +280 -39
- package/src/jsenv_root_directory_url.js +1 -0
- package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
- package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
- package/src/omega/compat/runtime_compat.js +50 -0
- package/src/omega/errors.js +51 -58
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/file_url_converter.js +8 -50
- package/src/omega/kitchen.js +482 -292
- package/src/omega/omega_server.js +2 -3
- package/src/omega/server/file_service.js +38 -25
- package/src/omega/server/user_agent.js +4 -2
- package/src/omega/url_graph/url_graph_load.js +14 -7
- package/src/omega/url_graph/url_graph_report.js +17 -15
- package/src/omega/url_graph/url_info_transformations.js +26 -9
- package/src/omega/url_graph.js +91 -16
- package/src/omega/web_workers.js +42 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +46 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +27 -0
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
- package/src/plugins/bundling/css/bundle_css.js +140 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +150 -79
- package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -41
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
- package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +8 -5
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +242 -0
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +79 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +83 -61
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +105 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -8
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
- package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +39 -33
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +67 -0
- package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
- package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +65 -44
- package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +296 -0
- package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
- package/src/plugins/minification/css/minify_css.js +9 -0
- package/src/plugins/minification/html/minify_html.js +15 -0
- package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
- package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
- package/src/plugins/minification/json/minify_json.js +8 -0
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +146 -0
- package/src/{omega → plugins}/plugin_controller.js +42 -11
- package/src/plugins/plugins.js +91 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
- package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
- package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +183 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +256 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +55 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +4 -22
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +37 -21
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
- package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +181 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +70 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
- package/src/plugins/url_analysis/css/css_urls.js +49 -0
- package/src/plugins/url_analysis/html/html_urls.js +273 -0
- package/src/plugins/url_analysis/js/js_urls.js +67 -0
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +18 -0
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +17 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
- package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +12 -15
- package/src/test/execute_plan.js +30 -18
- package/src/test/execute_test_plan.js +23 -8
- package/src/test/logs_file_execution.js +9 -8
- package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
- package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
- package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
- package/src/dev/plugins/autoreload/sse_service.js +0 -149
- package/src/execute/runtimes/node/controlled_process.js +0 -316
- package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
- package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
- package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
- package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
- package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
- package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
- package/src/omega/core_plugins.js +0 -39
- package/src/omega/runtime_support/runtime_support.js +0 -20
- package/src/omega/url_graph/url_graph_sort.js +0 -29
- package/src/omega/url_mentions/css_url_mentions.js +0 -63
- package/src/omega/url_mentions/html_url_mentions.js +0 -185
- package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
- package/src/omega/url_mentions/parse_url_mentions.js +0 -37
- package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Abort,
|
|
5
5
|
createCallbackListNotifiedOnce,
|
|
6
6
|
raceProcessTeardownEvents,
|
|
7
|
+
raceCallbacks,
|
|
7
8
|
} from "@jsenv/abort"
|
|
8
9
|
import { moveUrl } from "@jsenv/filesystem"
|
|
9
10
|
|
|
@@ -34,7 +35,7 @@ export const createRuntimeFromPlaywright = ({
|
|
|
34
35
|
server,
|
|
35
36
|
|
|
36
37
|
// measurePerformance,
|
|
37
|
-
|
|
38
|
+
collectPerformance,
|
|
38
39
|
collectCoverage = false,
|
|
39
40
|
coverageForceIstanbul,
|
|
40
41
|
urlShouldBeCovered,
|
|
@@ -42,10 +43,7 @@ export const createRuntimeFromPlaywright = ({
|
|
|
42
43
|
stopAfterAllSignal,
|
|
43
44
|
stopSignal,
|
|
44
45
|
keepRunning,
|
|
45
|
-
onStop,
|
|
46
|
-
onError,
|
|
47
46
|
onConsole,
|
|
48
|
-
onResult,
|
|
49
47
|
|
|
50
48
|
executablePath,
|
|
51
49
|
headful = false,
|
|
@@ -74,11 +72,27 @@ export const createRuntimeFromPlaywright = ({
|
|
|
74
72
|
}
|
|
75
73
|
const { browser, browserContext } = await browserAndContextPromise
|
|
76
74
|
const closeBrowser = async () => {
|
|
75
|
+
const disconnected = browser.isConnected()
|
|
76
|
+
? new Promise((resolve) => {
|
|
77
|
+
const disconnectedCallback = () => {
|
|
78
|
+
browser.removeListener("disconnected", disconnectedCallback)
|
|
79
|
+
resolve()
|
|
80
|
+
}
|
|
81
|
+
browser.on("disconnected", disconnectedCallback)
|
|
82
|
+
})
|
|
83
|
+
: Promise.resolve()
|
|
84
|
+
// for some reason without this 100ms timeout
|
|
85
|
+
// browser.close() never resolves (playwright does not like something)
|
|
86
|
+
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
77
87
|
try {
|
|
78
|
-
await
|
|
88
|
+
await browser.close()
|
|
79
89
|
} catch (e) {
|
|
80
|
-
|
|
90
|
+
if (isTargetClosedError(e)) {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
throw e
|
|
81
94
|
}
|
|
95
|
+
await disconnected
|
|
82
96
|
}
|
|
83
97
|
const page = await browserContext.newPage()
|
|
84
98
|
const closePage = async () => {
|
|
@@ -88,44 +102,9 @@ export const createRuntimeFromPlaywright = ({
|
|
|
88
102
|
if (isTargetClosedError(e)) {
|
|
89
103
|
return
|
|
90
104
|
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-disconnected
|
|
95
|
-
if (isBrowserDedicatedToExecution) {
|
|
96
|
-
browser.on("disconnected", async () => {
|
|
97
|
-
await cleanup("browser disconnected")
|
|
98
|
-
onStop({ reason: "browser disconnected" })
|
|
99
|
-
})
|
|
100
|
-
cleanupCallbackList.add(closePage)
|
|
101
|
-
cleanupCallbackList.add(closeBrowser)
|
|
102
|
-
} else {
|
|
103
|
-
const disconnectedCallback = async () => {
|
|
104
|
-
await cleanup("browser disconnected")
|
|
105
|
-
onError(new Error("browser disconnected during execution"))
|
|
106
|
-
}
|
|
107
|
-
browser.on("disconnected", disconnectedCallback)
|
|
108
|
-
page.on("close", () => {
|
|
109
|
-
onStop({ reason: "page closed" })
|
|
110
|
-
})
|
|
111
|
-
cleanupCallbackList.add(closePage)
|
|
112
|
-
const notifyPrevious = stopAfterAllSignal.notify
|
|
113
|
-
stopAfterAllSignal.notify = async () => {
|
|
114
|
-
await notifyPrevious()
|
|
115
|
-
browser.removeListener("disconnected", disconnectedCallback)
|
|
116
|
-
await closeBrowser()
|
|
105
|
+
throw e
|
|
117
106
|
}
|
|
118
107
|
}
|
|
119
|
-
const stopTrackingToNotify = trackPageToNotify(page, {
|
|
120
|
-
onError: (error) => {
|
|
121
|
-
error = transformErrorHook(error)
|
|
122
|
-
if (!ignoreErrorHook(error)) {
|
|
123
|
-
onError(error)
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
onConsole,
|
|
127
|
-
})
|
|
128
|
-
cleanupCallbackList.add(stopTrackingToNotify)
|
|
129
108
|
|
|
130
109
|
let resultTransformer = (result) => result
|
|
131
110
|
if (collectCoverage) {
|
|
@@ -169,30 +148,200 @@ export const createRuntimeFromPlaywright = ({
|
|
|
169
148
|
resultTransformer = composeTransformer(
|
|
170
149
|
resultTransformer,
|
|
171
150
|
async (result) => {
|
|
172
|
-
|
|
151
|
+
const scriptExecutionResults = result.namespace
|
|
152
|
+
if (scriptExecutionResults) {
|
|
153
|
+
result.coverage = generateCoverageForPage(scriptExecutionResults)
|
|
154
|
+
}
|
|
173
155
|
return result
|
|
174
156
|
},
|
|
175
157
|
)
|
|
176
158
|
}
|
|
177
159
|
} else {
|
|
178
160
|
resultTransformer = composeTransformer(resultTransformer, (result) => {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
161
|
+
const scriptExecutionResults = result.namespace
|
|
162
|
+
if (scriptExecutionResults) {
|
|
163
|
+
Object.keys(scriptExecutionResults).forEach((fileRelativeUrl) => {
|
|
164
|
+
delete scriptExecutionResults[fileRelativeUrl].coverage
|
|
165
|
+
})
|
|
166
|
+
}
|
|
183
167
|
return result
|
|
184
168
|
})
|
|
185
169
|
}
|
|
170
|
+
|
|
171
|
+
if (collectPerformance) {
|
|
172
|
+
resultTransformer = composeTransformer(
|
|
173
|
+
resultTransformer,
|
|
174
|
+
async (result) => {
|
|
175
|
+
const performance = await page.evaluate(
|
|
176
|
+
/* eslint-disable no-undef */
|
|
177
|
+
/* istanbul ignore next */
|
|
178
|
+
() => {
|
|
179
|
+
const { performance } = window
|
|
180
|
+
if (!performance) {
|
|
181
|
+
return null
|
|
182
|
+
}
|
|
183
|
+
const measures = {}
|
|
184
|
+
const measurePerfEntries = performance.getEntriesByType("measure")
|
|
185
|
+
measurePerfEntries.forEach((measurePerfEntry) => {
|
|
186
|
+
measures[measurePerfEntry.name] = measurePerfEntry.duration
|
|
187
|
+
})
|
|
188
|
+
return {
|
|
189
|
+
timeOrigin: performance.timeOrigin,
|
|
190
|
+
timing: performance.timing.toJSON(),
|
|
191
|
+
navigation: performance.navigation.toJSON(),
|
|
192
|
+
measures,
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
/* eslint-enable no-undef */
|
|
196
|
+
)
|
|
197
|
+
result.performance = performance
|
|
198
|
+
return result
|
|
199
|
+
},
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
186
203
|
const fileClientUrl = new URL(fileRelativeUrl, `${server.origin}/`).href
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
|
|
205
|
+
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-console
|
|
206
|
+
const removeConsoleListener = registerEvent({
|
|
207
|
+
object: page,
|
|
208
|
+
eventType: "console",
|
|
209
|
+
// https://github.com/microsoft/playwright/blob/master/docs/api.md#event-console
|
|
210
|
+
callback: async (consoleMessage) => {
|
|
211
|
+
onConsole({
|
|
212
|
+
type: consoleMessage.type(),
|
|
213
|
+
text: `${extractTextFromConsoleMessage(consoleMessage)}
|
|
214
|
+
`,
|
|
215
|
+
})
|
|
216
|
+
},
|
|
193
217
|
})
|
|
194
|
-
|
|
195
|
-
|
|
218
|
+
cleanupCallbackList.add(removeConsoleListener)
|
|
219
|
+
const winnerPromise = new Promise((resolve, reject) => {
|
|
220
|
+
raceCallbacks(
|
|
221
|
+
{
|
|
222
|
+
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-error
|
|
223
|
+
error: (cb) => {
|
|
224
|
+
return registerEvent({
|
|
225
|
+
object: page,
|
|
226
|
+
eventType: "error",
|
|
227
|
+
callback: (error) => {
|
|
228
|
+
if (ignoreErrorHook(error)) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
cb(transformErrorHook(error))
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
},
|
|
235
|
+
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-pageerror
|
|
236
|
+
pageerror: (cb) => {
|
|
237
|
+
return registerEvent({
|
|
238
|
+
object: page,
|
|
239
|
+
eventType: "pageerror",
|
|
240
|
+
callback: (error) => {
|
|
241
|
+
if (ignoreErrorHook(error)) {
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
cb(transformErrorHook(error))
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
},
|
|
248
|
+
closed: (cb) => {
|
|
249
|
+
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-disconnected
|
|
250
|
+
if (isBrowserDedicatedToExecution) {
|
|
251
|
+
browser.on("disconnected", async () => {
|
|
252
|
+
cb({ reason: "browser disconnected" })
|
|
253
|
+
})
|
|
254
|
+
cleanupCallbackList.add(closePage)
|
|
255
|
+
cleanupCallbackList.add(closeBrowser)
|
|
256
|
+
} else {
|
|
257
|
+
const disconnectedCallback = async () => {
|
|
258
|
+
throw new Error("browser disconnected during execution")
|
|
259
|
+
}
|
|
260
|
+
browser.on("disconnected", disconnectedCallback)
|
|
261
|
+
page.on("close", () => {
|
|
262
|
+
cb({ reason: "page closed" })
|
|
263
|
+
})
|
|
264
|
+
cleanupCallbackList.add(closePage)
|
|
265
|
+
cleanupCallbackList.add(() => {
|
|
266
|
+
browser.removeListener("disconnected", disconnectedCallback)
|
|
267
|
+
})
|
|
268
|
+
const notifyPrevious = stopAfterAllSignal.notify
|
|
269
|
+
stopAfterAllSignal.notify = async () => {
|
|
270
|
+
await notifyPrevious()
|
|
271
|
+
browser.removeListener("disconnected", disconnectedCallback)
|
|
272
|
+
await closeBrowser()
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
response: async (cb) => {
|
|
277
|
+
try {
|
|
278
|
+
await page.goto(fileClientUrl, { timeout: 0 })
|
|
279
|
+
const result = await page.evaluate(
|
|
280
|
+
/* eslint-disable no-undef */
|
|
281
|
+
/* istanbul ignore next */
|
|
282
|
+
() => {
|
|
283
|
+
return window.__html_supervisor__.getScriptExecutionResults()
|
|
284
|
+
},
|
|
285
|
+
/* eslint-enable no-undef */
|
|
286
|
+
)
|
|
287
|
+
const { status, scriptExecutionResults } = result
|
|
288
|
+
if (status === "errored") {
|
|
289
|
+
const { exceptionSource } = result
|
|
290
|
+
const error = evalException(exceptionSource, {
|
|
291
|
+
rootDirectoryUrl,
|
|
292
|
+
server,
|
|
293
|
+
transformErrorHook,
|
|
294
|
+
})
|
|
295
|
+
cb({
|
|
296
|
+
status: "errored",
|
|
297
|
+
error,
|
|
298
|
+
namespace: scriptExecutionResults,
|
|
299
|
+
})
|
|
300
|
+
} else {
|
|
301
|
+
cb({
|
|
302
|
+
status: "completed",
|
|
303
|
+
namespace: scriptExecutionResults,
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
} catch (e) {
|
|
307
|
+
reject(e)
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
resolve,
|
|
312
|
+
)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
const getResult = async () => {
|
|
316
|
+
const winner = await winnerPromise
|
|
317
|
+
if (winner.name === "error" || winner.name === "pageerror") {
|
|
318
|
+
const error = winner.data
|
|
319
|
+
return {
|
|
320
|
+
status: "errored",
|
|
321
|
+
error,
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (winner.name === "closed") {
|
|
325
|
+
return {
|
|
326
|
+
status: "errored",
|
|
327
|
+
error: isBrowserDedicatedToExecution
|
|
328
|
+
? new Error(`browser disconnected during execution`)
|
|
329
|
+
: new Error(`page closed during execution`),
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return winner.data
|
|
333
|
+
}
|
|
334
|
+
let result
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
result = await getResult()
|
|
338
|
+
result = await resultTransformer(result)
|
|
339
|
+
} catch (e) {
|
|
340
|
+
result = {
|
|
341
|
+
status: "errored",
|
|
342
|
+
error: e,
|
|
343
|
+
}
|
|
344
|
+
}
|
|
196
345
|
if (keepRunning) {
|
|
197
346
|
stopSignal.notify = cleanup
|
|
198
347
|
} else {
|
|
@@ -214,40 +363,6 @@ export const createRuntimeFromPlaywright = ({
|
|
|
214
363
|
return runtime
|
|
215
364
|
}
|
|
216
365
|
|
|
217
|
-
const getResult = async ({
|
|
218
|
-
page,
|
|
219
|
-
rootDirectoryUrl,
|
|
220
|
-
server,
|
|
221
|
-
transformErrorHook,
|
|
222
|
-
}) => {
|
|
223
|
-
const result = await page.evaluate(
|
|
224
|
-
/* eslint-disable no-undef */
|
|
225
|
-
/* istanbul ignore next */
|
|
226
|
-
() => {
|
|
227
|
-
return window.__html_supervisor__.getScriptExecutionResults()
|
|
228
|
-
},
|
|
229
|
-
/* eslint-enable no-undef */
|
|
230
|
-
)
|
|
231
|
-
const { status, scriptExecutionResults } = result
|
|
232
|
-
if (status === "errored") {
|
|
233
|
-
const { exceptionSource } = result
|
|
234
|
-
const error = evalException(exceptionSource, {
|
|
235
|
-
rootDirectoryUrl,
|
|
236
|
-
server,
|
|
237
|
-
transformErrorHook,
|
|
238
|
-
})
|
|
239
|
-
return {
|
|
240
|
-
status: "errored",
|
|
241
|
-
error,
|
|
242
|
-
namespace: scriptExecutionResults,
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
status: "completed",
|
|
247
|
-
namespace: scriptExecutionResults,
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
366
|
const generateCoverageForPage = (scriptExecutionResults) => {
|
|
252
367
|
let istanbulCoverageComposed = null
|
|
253
368
|
Object.keys(scriptExecutionResults).forEach((fileRelativeUrl) => {
|
|
@@ -262,31 +377,6 @@ const generateCoverageForPage = (scriptExecutionResults) => {
|
|
|
262
377
|
return istanbulCoverageComposed
|
|
263
378
|
}
|
|
264
379
|
|
|
265
|
-
const stopBrowser = async (browser) => {
|
|
266
|
-
const disconnected = browser.isConnected()
|
|
267
|
-
? new Promise((resolve) => {
|
|
268
|
-
const disconnectedCallback = () => {
|
|
269
|
-
browser.removeListener("disconnected", disconnectedCallback)
|
|
270
|
-
resolve()
|
|
271
|
-
}
|
|
272
|
-
browser.on("disconnected", disconnectedCallback)
|
|
273
|
-
})
|
|
274
|
-
: Promise.resolve()
|
|
275
|
-
|
|
276
|
-
// for some reason without this 100ms timeout
|
|
277
|
-
// browser.close() never resolves (playwright does not like something)
|
|
278
|
-
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
279
|
-
try {
|
|
280
|
-
await browser.close()
|
|
281
|
-
} catch (e) {
|
|
282
|
-
if (isTargetClosedError(e)) {
|
|
283
|
-
return
|
|
284
|
-
}
|
|
285
|
-
throw e
|
|
286
|
-
}
|
|
287
|
-
await disconnected
|
|
288
|
-
}
|
|
289
|
-
|
|
290
380
|
const launchBrowserUsingPlaywright = async ({
|
|
291
381
|
signal,
|
|
292
382
|
browserName,
|
|
@@ -366,39 +456,6 @@ const isTargetClosedError = (error) => {
|
|
|
366
456
|
return false
|
|
367
457
|
}
|
|
368
458
|
|
|
369
|
-
const trackPageToNotify = (page, { onError, onConsole }) => {
|
|
370
|
-
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-error
|
|
371
|
-
const removeErrorListener = registerEvent({
|
|
372
|
-
object: page,
|
|
373
|
-
eventType: "error",
|
|
374
|
-
callback: onError,
|
|
375
|
-
})
|
|
376
|
-
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-pageerror
|
|
377
|
-
const removePageErrorListener = registerEvent({
|
|
378
|
-
object: page,
|
|
379
|
-
eventType: "pageerror",
|
|
380
|
-
callback: onError,
|
|
381
|
-
})
|
|
382
|
-
// https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-console
|
|
383
|
-
const removeConsoleListener = registerEvent({
|
|
384
|
-
object: page,
|
|
385
|
-
eventType: "console",
|
|
386
|
-
// https://github.com/microsoft/playwright/blob/master/docs/api.md#event-console
|
|
387
|
-
callback: async (consoleMessage) => {
|
|
388
|
-
onConsole({
|
|
389
|
-
type: consoleMessage.type(),
|
|
390
|
-
text: `${extractTextFromConsoleMessage(consoleMessage)}
|
|
391
|
-
`,
|
|
392
|
-
})
|
|
393
|
-
},
|
|
394
|
-
})
|
|
395
|
-
return () => {
|
|
396
|
-
removeErrorListener()
|
|
397
|
-
removePageErrorListener()
|
|
398
|
-
removeConsoleListener()
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
459
|
const composeTransformer = (previousTransformer, transformer) => {
|
|
403
460
|
return async (value) => {
|
|
404
461
|
const transformedValue = await previousTransformer(value)
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
import v8 from "node:v8"
|
|
2
2
|
import { uneval } from "@jsenv/uneval"
|
|
3
|
+
import { startObservingPerformances } from "./node_execution_performance.js"
|
|
3
4
|
|
|
4
5
|
const ACTIONS_AVAILABLE = {
|
|
5
|
-
"execute-using-dynamic-import": async ({ fileUrl }) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
"execute-using-dynamic-import": async ({ fileUrl, collectPerformance }) => {
|
|
7
|
+
const getNamespace = async () => {
|
|
8
|
+
const namespace = await import(fileUrl)
|
|
9
|
+
const namespaceResolved = {}
|
|
10
|
+
await Promise.all([
|
|
11
|
+
...Object.keys(namespace).map(async (key) => {
|
|
12
|
+
const value = await namespace[key]
|
|
13
|
+
namespaceResolved[key] = value
|
|
14
|
+
}),
|
|
15
|
+
])
|
|
16
|
+
return namespaceResolved
|
|
17
|
+
}
|
|
18
|
+
if (collectPerformance) {
|
|
19
|
+
const getPerformance = startObservingPerformances()
|
|
20
|
+
const namespace = await getNamespace()
|
|
21
|
+
const performance = await getPerformance()
|
|
22
|
+
return {
|
|
23
|
+
namespace,
|
|
24
|
+
performance,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const namespace = await getNamespace()
|
|
28
|
+
return {
|
|
29
|
+
namespace,
|
|
30
|
+
}
|
|
15
31
|
},
|
|
16
32
|
"execute-using-require": async ({ fileUrl }) => {
|
|
17
33
|
const { createRequire } = await import("module")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PerformanceObserver, performance } from "node:perf_hooks"
|
|
2
|
+
|
|
3
|
+
export const startObservingPerformances = () => {
|
|
4
|
+
const measureEntries = []
|
|
5
|
+
// https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html
|
|
6
|
+
const perfObserver = new PerformanceObserver(
|
|
7
|
+
(
|
|
8
|
+
// https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceobserverentrylist
|
|
9
|
+
list,
|
|
10
|
+
) => {
|
|
11
|
+
const perfMeasureEntries = list.getEntriesByType("measure")
|
|
12
|
+
measureEntries.push(...perfMeasureEntries)
|
|
13
|
+
},
|
|
14
|
+
)
|
|
15
|
+
perfObserver.observe({
|
|
16
|
+
entryTypes: ["measure"],
|
|
17
|
+
})
|
|
18
|
+
return async () => {
|
|
19
|
+
// wait for node to call the performance observer
|
|
20
|
+
await new Promise((resolve) => {
|
|
21
|
+
setTimeout(resolve)
|
|
22
|
+
})
|
|
23
|
+
performance.clearMarks()
|
|
24
|
+
perfObserver.disconnect()
|
|
25
|
+
return {
|
|
26
|
+
...readNodePerformance(),
|
|
27
|
+
measures: measuresFromMeasureEntries(measureEntries),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const readNodePerformance = () => {
|
|
33
|
+
const nodePerformance = {
|
|
34
|
+
nodeTiming: asPlainObject(performance.nodeTiming),
|
|
35
|
+
timeOrigin: performance.timeOrigin,
|
|
36
|
+
eventLoopUtilization: performance.eventLoopUtilization(),
|
|
37
|
+
}
|
|
38
|
+
return nodePerformance
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// remove getters that cannot be stringified
|
|
42
|
+
const asPlainObject = (objectWithGetters) => {
|
|
43
|
+
const objectWithoutGetters = {}
|
|
44
|
+
Object.keys(objectWithGetters).forEach((key) => {
|
|
45
|
+
objectWithoutGetters[key] = objectWithGetters[key]
|
|
46
|
+
})
|
|
47
|
+
return objectWithoutGetters
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const measuresFromMeasureEntries = (measureEntries) => {
|
|
51
|
+
const measures = {}
|
|
52
|
+
// Sort to ensure measures order is predictable
|
|
53
|
+
// It seems to be already predictable on Node 16+ but
|
|
54
|
+
// it's not the case on Node 14.
|
|
55
|
+
measureEntries.sort((a, b) => {
|
|
56
|
+
return a.startTime - b.startTime
|
|
57
|
+
})
|
|
58
|
+
measureEntries.forEach(
|
|
59
|
+
(
|
|
60
|
+
// https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceentry
|
|
61
|
+
perfMeasureEntry,
|
|
62
|
+
) => {
|
|
63
|
+
measures[perfMeasureEntry.name] = perfMeasureEntry.duration
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
return measures
|
|
67
|
+
}
|