@jsenv/core 28.1.1 → 28.1.2
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/js/supervisor.js
CHANGED
|
@@ -7,27 +7,17 @@ window.__supervisor__ = (() => {
|
|
|
7
7
|
reportError: notImplemented,
|
|
8
8
|
superviseScript: notImplemented,
|
|
9
9
|
reloadSupervisedScript: notImplemented,
|
|
10
|
-
|
|
11
|
-
getScriptExecutionResults: () => {
|
|
12
|
-
// wait for page to load before collecting script execution results
|
|
13
|
-
const htmlReadyPromise = new Promise((resolve) => {
|
|
14
|
-
if (document.readyState === "complete") {
|
|
15
|
-
resolve()
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
const loadCallback = () => {
|
|
19
|
-
window.removeEventListener("load", loadCallback)
|
|
20
|
-
resolve()
|
|
21
|
-
}
|
|
22
|
-
window.addEventListener("load", loadCallback)
|
|
23
|
-
})
|
|
24
|
-
return htmlReadyPromise.then(() => {
|
|
25
|
-
return supervisor.collectScriptResults()
|
|
26
|
-
})
|
|
27
|
-
},
|
|
10
|
+
getDocumentExecutionResult: notImplemented,
|
|
28
11
|
executionResults,
|
|
29
12
|
}
|
|
30
13
|
|
|
14
|
+
let navigationStartTime
|
|
15
|
+
try {
|
|
16
|
+
navigationStartTime = window.performance.timing.navigationStart
|
|
17
|
+
} catch (e) {
|
|
18
|
+
navigationStartTime = Date.now()
|
|
19
|
+
}
|
|
20
|
+
|
|
31
21
|
supervisor.setupReportException = ({
|
|
32
22
|
rootDirectoryUrl,
|
|
33
23
|
errorNotification,
|
|
@@ -728,7 +718,7 @@ window.__supervisor__ = (() => {
|
|
|
728
718
|
})
|
|
729
719
|
|
|
730
720
|
const supervisedScripts = []
|
|
731
|
-
const
|
|
721
|
+
const scriptExecutionPromises = []
|
|
732
722
|
supervisor.createExecution = ({ type, src, async, execute }) => {
|
|
733
723
|
const execution = {
|
|
734
724
|
type,
|
|
@@ -754,28 +744,27 @@ window.__supervisor__ = (() => {
|
|
|
754
744
|
}
|
|
755
745
|
const executionResult = {
|
|
756
746
|
status: "pending",
|
|
747
|
+
startTime: Date.now(),
|
|
748
|
+
endTime: null,
|
|
757
749
|
exception: null,
|
|
758
750
|
namespace: null,
|
|
759
751
|
coverage: null,
|
|
760
752
|
}
|
|
761
753
|
executionResults[execution.src] = executionResult
|
|
762
|
-
let
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
if (
|
|
767
|
-
|
|
754
|
+
let resolveScriptExecutionPromise
|
|
755
|
+
const scriptExecutionPromise = new Promise((resolve) => {
|
|
756
|
+
resolveScriptExecutionPromise = () => {
|
|
757
|
+
executionResult.endTime = Date.now()
|
|
758
|
+
if (measurePerf) {
|
|
759
|
+
performance.measure(`execution`, `execution_start`)
|
|
768
760
|
}
|
|
769
761
|
resolve()
|
|
770
762
|
}
|
|
771
763
|
})
|
|
772
|
-
|
|
773
|
-
|
|
764
|
+
scriptExecutionPromise.execution = execution
|
|
765
|
+
scriptExecutionPromises.push(scriptExecutionPromise)
|
|
774
766
|
try {
|
|
775
767
|
const result = await execution.execute({ isReload })
|
|
776
|
-
if (measurePerf) {
|
|
777
|
-
performance.measure(`execution`, `execution_start`)
|
|
778
|
-
}
|
|
779
768
|
executionResult.status = "completed"
|
|
780
769
|
executionResult.namespace = result
|
|
781
770
|
executionResult.coverage = window.__coverage__
|
|
@@ -783,11 +772,8 @@ window.__supervisor__ = (() => {
|
|
|
783
772
|
console.log(`${execution.type} load ended`)
|
|
784
773
|
console.groupEnd()
|
|
785
774
|
}
|
|
786
|
-
|
|
775
|
+
resolveScriptExecutionPromise()
|
|
787
776
|
} catch (e) {
|
|
788
|
-
if (measurePerf) {
|
|
789
|
-
performance.measure(`execution`, `execution_start`)
|
|
790
|
-
}
|
|
791
777
|
executionResult.status = "errored"
|
|
792
778
|
const exception = supervisor.createException({
|
|
793
779
|
reason: e,
|
|
@@ -800,7 +786,7 @@ window.__supervisor__ = (() => {
|
|
|
800
786
|
if (logs) {
|
|
801
787
|
console.groupEnd()
|
|
802
788
|
}
|
|
803
|
-
|
|
789
|
+
resolveScriptExecutionPromise()
|
|
804
790
|
}
|
|
805
791
|
}
|
|
806
792
|
|
|
@@ -809,10 +795,10 @@ window.__supervisor__ = (() => {
|
|
|
809
795
|
// - wait module script previous execution (non async)
|
|
810
796
|
// see https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8afd7a6#typemodule-vs-non-module-typetextjavascript-vs-script-nomodule
|
|
811
797
|
supervisor.getPreviousExecutionDonePromise = async () => {
|
|
812
|
-
const
|
|
798
|
+
const previousNonAsyncScriptExecutions = scriptExecutionPromises.filter(
|
|
813
799
|
(promise) => !promise.execution.async,
|
|
814
800
|
)
|
|
815
|
-
await Promise.all(
|
|
801
|
+
await Promise.all(previousNonAsyncScriptExecutions)
|
|
816
802
|
}
|
|
817
803
|
supervisor.superviseScript = async ({ src, async }) => {
|
|
818
804
|
const { currentScript } = document
|
|
@@ -890,43 +876,39 @@ window.__supervisor__ = (() => {
|
|
|
890
876
|
supervisedScript.reload()
|
|
891
877
|
}
|
|
892
878
|
}
|
|
893
|
-
supervisor.
|
|
879
|
+
supervisor.getDocumentExecutionResult = async () => {
|
|
894
880
|
// just to be super safe and ensure any <script type="module"> got a chance to execute
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
scriptTypeModule.type = "module"
|
|
898
|
-
scriptTypeModule.innerText =
|
|
899
|
-
"window.__supervisor__.scriptModuleCallback()"
|
|
900
|
-
window.__supervisor__.scriptModuleCallback = () => {
|
|
901
|
-
scriptTypeModule.parentNode.removeChild(scriptTypeModule)
|
|
881
|
+
const documentReadyPromise = new Promise((resolve) => {
|
|
882
|
+
if (document.readyState === "complete") {
|
|
902
883
|
resolve()
|
|
884
|
+
return
|
|
903
885
|
}
|
|
904
|
-
|
|
886
|
+
const loadCallback = () => {
|
|
887
|
+
window.removeEventListener("load", loadCallback)
|
|
888
|
+
resolve()
|
|
889
|
+
}
|
|
890
|
+
window.addEventListener("load", loadCallback)
|
|
905
891
|
})
|
|
906
|
-
await
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
892
|
+
await documentReadyPromise
|
|
893
|
+
const waitScriptExecutions = async () => {
|
|
894
|
+
const numberOfScripts = scriptExecutionPromises.length
|
|
895
|
+
await Promise.all(scriptExecutionPromises)
|
|
896
|
+
// new scripts added while the other where executing
|
|
897
|
+
// (should happen only on webkit where
|
|
898
|
+
// script might be added after window load event)
|
|
899
|
+
if (scriptExecutionPromises.length > numberOfScripts) {
|
|
900
|
+
await waitScriptExecutions()
|
|
912
901
|
}
|
|
913
902
|
}
|
|
914
|
-
await
|
|
903
|
+
await waitScriptExecutions()
|
|
904
|
+
|
|
915
905
|
return {
|
|
916
906
|
status: "completed",
|
|
917
907
|
executionResults,
|
|
918
|
-
startTime:
|
|
908
|
+
startTime: navigationStartTime,
|
|
919
909
|
endTime: Date.now(),
|
|
920
910
|
}
|
|
921
911
|
}
|
|
922
|
-
|
|
923
|
-
const getNavigationStartTime = () => {
|
|
924
|
-
try {
|
|
925
|
-
return window.performance.timing.navigationStart
|
|
926
|
-
} catch (e) {
|
|
927
|
-
return Date.now()
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
912
|
}
|
|
931
913
|
|
|
932
914
|
return supervisor
|
package/dist/main.js
CHANGED
|
@@ -28036,7 +28036,7 @@ const createRuntimeFromPlaywright = ({
|
|
|
28036
28036
|
throw new Error(`window.__supervisor__ not found`);
|
|
28037
28037
|
}
|
|
28038
28038
|
|
|
28039
|
-
return window.__supervisor__.
|
|
28039
|
+
return window.__supervisor__.getDocumentExecutionResult();
|
|
28040
28040
|
}
|
|
28041
28041
|
/* eslint-enable no-undef */
|
|
28042
28042
|
);
|
package/package.json
CHANGED
|
@@ -306,7 +306,7 @@ export const createRuntimeFromPlaywright = ({
|
|
|
306
306
|
if (!window.__supervisor__) {
|
|
307
307
|
throw new Error(`window.__supervisor__ not found`)
|
|
308
308
|
}
|
|
309
|
-
return window.__supervisor__.
|
|
309
|
+
return window.__supervisor__.getDocumentExecutionResult()
|
|
310
310
|
},
|
|
311
311
|
/* eslint-enable no-undef */
|
|
312
312
|
)
|
|
@@ -7,27 +7,17 @@ window.__supervisor__ = (() => {
|
|
|
7
7
|
reportError: notImplemented,
|
|
8
8
|
superviseScript: notImplemented,
|
|
9
9
|
reloadSupervisedScript: notImplemented,
|
|
10
|
-
|
|
11
|
-
getScriptExecutionResults: () => {
|
|
12
|
-
// wait for page to load before collecting script execution results
|
|
13
|
-
const htmlReadyPromise = new Promise((resolve) => {
|
|
14
|
-
if (document.readyState === "complete") {
|
|
15
|
-
resolve()
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
const loadCallback = () => {
|
|
19
|
-
window.removeEventListener("load", loadCallback)
|
|
20
|
-
resolve()
|
|
21
|
-
}
|
|
22
|
-
window.addEventListener("load", loadCallback)
|
|
23
|
-
})
|
|
24
|
-
return htmlReadyPromise.then(() => {
|
|
25
|
-
return supervisor.collectScriptResults()
|
|
26
|
-
})
|
|
27
|
-
},
|
|
10
|
+
getDocumentExecutionResult: notImplemented,
|
|
28
11
|
executionResults,
|
|
29
12
|
}
|
|
30
13
|
|
|
14
|
+
let navigationStartTime
|
|
15
|
+
try {
|
|
16
|
+
navigationStartTime = window.performance.timing.navigationStart
|
|
17
|
+
} catch (e) {
|
|
18
|
+
navigationStartTime = Date.now()
|
|
19
|
+
}
|
|
20
|
+
|
|
31
21
|
supervisor.setupReportException = ({
|
|
32
22
|
rootDirectoryUrl,
|
|
33
23
|
errorNotification,
|
|
@@ -728,7 +718,7 @@ window.__supervisor__ = (() => {
|
|
|
728
718
|
})
|
|
729
719
|
|
|
730
720
|
const supervisedScripts = []
|
|
731
|
-
const
|
|
721
|
+
const scriptExecutionPromises = []
|
|
732
722
|
supervisor.createExecution = ({ type, src, async, execute }) => {
|
|
733
723
|
const execution = {
|
|
734
724
|
type,
|
|
@@ -754,28 +744,27 @@ window.__supervisor__ = (() => {
|
|
|
754
744
|
}
|
|
755
745
|
const executionResult = {
|
|
756
746
|
status: "pending",
|
|
747
|
+
startTime: Date.now(),
|
|
748
|
+
endTime: null,
|
|
757
749
|
exception: null,
|
|
758
750
|
namespace: null,
|
|
759
751
|
coverage: null,
|
|
760
752
|
}
|
|
761
753
|
executionResults[execution.src] = executionResult
|
|
762
|
-
let
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
if (
|
|
767
|
-
|
|
754
|
+
let resolveScriptExecutionPromise
|
|
755
|
+
const scriptExecutionPromise = new Promise((resolve) => {
|
|
756
|
+
resolveScriptExecutionPromise = () => {
|
|
757
|
+
executionResult.endTime = Date.now()
|
|
758
|
+
if (measurePerf) {
|
|
759
|
+
performance.measure(`execution`, `execution_start`)
|
|
768
760
|
}
|
|
769
761
|
resolve()
|
|
770
762
|
}
|
|
771
763
|
})
|
|
772
|
-
|
|
773
|
-
|
|
764
|
+
scriptExecutionPromise.execution = execution
|
|
765
|
+
scriptExecutionPromises.push(scriptExecutionPromise)
|
|
774
766
|
try {
|
|
775
767
|
const result = await execution.execute({ isReload })
|
|
776
|
-
if (measurePerf) {
|
|
777
|
-
performance.measure(`execution`, `execution_start`)
|
|
778
|
-
}
|
|
779
768
|
executionResult.status = "completed"
|
|
780
769
|
executionResult.namespace = result
|
|
781
770
|
executionResult.coverage = window.__coverage__
|
|
@@ -783,11 +772,8 @@ window.__supervisor__ = (() => {
|
|
|
783
772
|
console.log(`${execution.type} load ended`)
|
|
784
773
|
console.groupEnd()
|
|
785
774
|
}
|
|
786
|
-
|
|
775
|
+
resolveScriptExecutionPromise()
|
|
787
776
|
} catch (e) {
|
|
788
|
-
if (measurePerf) {
|
|
789
|
-
performance.measure(`execution`, `execution_start`)
|
|
790
|
-
}
|
|
791
777
|
executionResult.status = "errored"
|
|
792
778
|
const exception = supervisor.createException({
|
|
793
779
|
reason: e,
|
|
@@ -800,7 +786,7 @@ window.__supervisor__ = (() => {
|
|
|
800
786
|
if (logs) {
|
|
801
787
|
console.groupEnd()
|
|
802
788
|
}
|
|
803
|
-
|
|
789
|
+
resolveScriptExecutionPromise()
|
|
804
790
|
}
|
|
805
791
|
}
|
|
806
792
|
|
|
@@ -809,10 +795,10 @@ window.__supervisor__ = (() => {
|
|
|
809
795
|
// - wait module script previous execution (non async)
|
|
810
796
|
// see https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8afd7a6#typemodule-vs-non-module-typetextjavascript-vs-script-nomodule
|
|
811
797
|
supervisor.getPreviousExecutionDonePromise = async () => {
|
|
812
|
-
const
|
|
798
|
+
const previousNonAsyncScriptExecutions = scriptExecutionPromises.filter(
|
|
813
799
|
(promise) => !promise.execution.async,
|
|
814
800
|
)
|
|
815
|
-
await Promise.all(
|
|
801
|
+
await Promise.all(previousNonAsyncScriptExecutions)
|
|
816
802
|
}
|
|
817
803
|
supervisor.superviseScript = async ({ src, async }) => {
|
|
818
804
|
const { currentScript } = document
|
|
@@ -890,43 +876,39 @@ window.__supervisor__ = (() => {
|
|
|
890
876
|
supervisedScript.reload()
|
|
891
877
|
}
|
|
892
878
|
}
|
|
893
|
-
supervisor.
|
|
879
|
+
supervisor.getDocumentExecutionResult = async () => {
|
|
894
880
|
// just to be super safe and ensure any <script type="module"> got a chance to execute
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
scriptTypeModule.type = "module"
|
|
898
|
-
scriptTypeModule.innerText =
|
|
899
|
-
"window.__supervisor__.scriptModuleCallback()"
|
|
900
|
-
window.__supervisor__.scriptModuleCallback = () => {
|
|
901
|
-
scriptTypeModule.parentNode.removeChild(scriptTypeModule)
|
|
881
|
+
const documentReadyPromise = new Promise((resolve) => {
|
|
882
|
+
if (document.readyState === "complete") {
|
|
902
883
|
resolve()
|
|
884
|
+
return
|
|
903
885
|
}
|
|
904
|
-
|
|
886
|
+
const loadCallback = () => {
|
|
887
|
+
window.removeEventListener("load", loadCallback)
|
|
888
|
+
resolve()
|
|
889
|
+
}
|
|
890
|
+
window.addEventListener("load", loadCallback)
|
|
905
891
|
})
|
|
906
|
-
await
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
892
|
+
await documentReadyPromise
|
|
893
|
+
const waitScriptExecutions = async () => {
|
|
894
|
+
const numberOfScripts = scriptExecutionPromises.length
|
|
895
|
+
await Promise.all(scriptExecutionPromises)
|
|
896
|
+
// new scripts added while the other where executing
|
|
897
|
+
// (should happen only on webkit where
|
|
898
|
+
// script might be added after window load event)
|
|
899
|
+
if (scriptExecutionPromises.length > numberOfScripts) {
|
|
900
|
+
await waitScriptExecutions()
|
|
912
901
|
}
|
|
913
902
|
}
|
|
914
|
-
await
|
|
903
|
+
await waitScriptExecutions()
|
|
904
|
+
|
|
915
905
|
return {
|
|
916
906
|
status: "completed",
|
|
917
907
|
executionResults,
|
|
918
|
-
startTime:
|
|
908
|
+
startTime: navigationStartTime,
|
|
919
909
|
endTime: Date.now(),
|
|
920
910
|
}
|
|
921
911
|
}
|
|
922
|
-
|
|
923
|
-
const getNavigationStartTime = () => {
|
|
924
|
-
try {
|
|
925
|
-
return window.performance.timing.navigationStart
|
|
926
|
-
} catch (e) {
|
|
927
|
-
return Date.now()
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
912
|
}
|
|
931
913
|
|
|
932
914
|
return supervisor
|
|
@@ -9,7 +9,7 @@ export const renderExecutionInToolbar = async () => {
|
|
|
9
9
|
removeForceHideElement(document.querySelector("#execution-indicator"))
|
|
10
10
|
|
|
11
11
|
const { status, startTime, endTime } =
|
|
12
|
-
await window.parent.__supervisor__.
|
|
12
|
+
await window.parent.__supervisor__.getDocumentExecutionResult()
|
|
13
13
|
const execution = { status, startTime, endTime }
|
|
14
14
|
applyExecutionIndicator(execution)
|
|
15
15
|
const executionStorageKey = window.location.href
|