-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Add required chromeinspector lib for debugging #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
baptistegrimaud
wants to merge
2
commits into
main
Choose a base branch
from
fix-unable-to-debug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| describe("Check that GraalVM debugger can be enabled", () => { | ||
| // these ports must be exposed in docker-compose.yml | ||
| const ports = [9229, 10229]; | ||
|
|
||
| ports.forEach((port) => { | ||
| it(`Check that GraalVM debugger can be enabled on port ${port}`, function () { | ||
| // extract the host from the JAHIA_URL env var | ||
| const host = Cypress.env("JAHIA_URL").split("//")[1].split(":")[0]; | ||
|
|
||
| // delete the config | ||
| deleteGraalVMConfig(); | ||
| waitForCurlExitCode( | ||
| host, | ||
| port, | ||
| CONNECTION_ERROR_CODES, | ||
| "debugger should be disabled by default (no config)", | ||
| ); | ||
|
|
||
| // Enable the debugger | ||
| enableGraalVMDebugger(port); | ||
| waitForCurlExitCode(host, port, CONNECTION_OK, "debugger should be enabled when configured"); | ||
| verifyGraalVMInspector(host, port); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| // Constants for curl exit codes | ||
| const CONNECTION_OK = 0; | ||
| const CONNECTION_ERROR_CODES = [7, 56]; // 7=ECONNREFUSED, 56=ECONNRESET | ||
|
|
||
| /** | ||
| * Wait for curl to return the expected exit code when connecting to host:port Exit codes: | ||
| * 0=success, 7=ECONNREFUSED, 56=ECONNRESET | ||
| */ | ||
| function waitForCurlExitCode( | ||
| host: string, | ||
| port: number, | ||
| expectedExitCode: number | number[], | ||
| errorMsg: string, | ||
| ) { | ||
| const expectedCodes = Array.isArray(expectedExitCode) ? expectedExitCode : [expectedExitCode]; | ||
|
|
||
| cy.waitUntil( | ||
| () => | ||
| cy | ||
| .exec(`curl -s -o /dev/null -w "%{http_code}" http://${host}:${port}/json/version`, { | ||
| failOnNonZeroExit: false, | ||
| timeout: 4000, | ||
| }) | ||
| .then((result) => { | ||
| const actualCode = result.code; | ||
|
|
||
| if (expectedCodes.includes(actualCode)) { | ||
| const msg = | ||
| actualCode === 0 | ||
| ? `Connection successful (HTTP ${result.stdout})` | ||
| : `Got expected connection error (exit code: ${actualCode})`; | ||
| Cypress.log({ message: msg }); | ||
| return true; | ||
| } | ||
|
|
||
| Cypress.log({ | ||
| message: `Waiting... got exit code ${actualCode}, expected ${expectedCodes.join(" or ")}`, | ||
| }); | ||
| return false; | ||
| }), | ||
| { | ||
| timeout: 5000, | ||
| errorMsg: `${errorMsg} - Expected curl exit code ${expectedCodes.join(" or ")}`, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| /** Delete the GraalVM Engine configuration */ | ||
| function deleteGraalVMConfig() { | ||
| cy.runProvisioningScript({ | ||
| script: { | ||
| fileContent: JSON.stringify([ | ||
| { | ||
| editConfiguration: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine", | ||
| content: "", | ||
| }, | ||
| ]), | ||
| type: "application/yaml", | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** Enable the GraalVM debugger on a given port */ | ||
| function enableGraalVMDebugger(port: number) { | ||
| cy.apollo({ | ||
| variables: { inspect: `0.0.0.0:${port}`, suspend: false, secure: false }, | ||
| mutationFile: "graphql/enableGraalVMDebugger.graphql", | ||
| }); | ||
| } | ||
|
|
||
| /** Verify the response is from the GraalVM Chrome DevTools inspector */ | ||
| function verifyGraalVMInspector(host: string, port: number) { | ||
| cy.request(`http://${host}:${port}/json/version`).then((response) => { | ||
| expect(response.status).to.equal(200); | ||
| expect(response.body).to.have.property("Browser", "GraalVM"); | ||
| expect(response.body).to.have.property("Protocol-Version", "1.2"); | ||
| }); | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| mutation enableGraalVMDebugger($inspect: String!, $suspend: String!, $secure: String!) { | ||
| admin { | ||
| jahia { | ||
| configuration(pid: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine") { | ||
| polyGlotInspect: value(name: "polyglot.inspect", value: $inspect) | ||
| polyGlotInspectSuspend: value(name: "polyglot.inspect.Suspend", value: $suspend) | ||
| polyGlotInspectSecure: value(name: "polyglot.inspect.Secure", value: $secure) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a
curlcommand is used withincy.exec()as it's not possible (at least I couldn't have it working) to rely on acy.request()to check a network error, the Cypress test is always failing