-
Notifications
You must be signed in to change notification settings - Fork 117
improve(laboratory): validate editor content with TypeScript #6476
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
jasonkuhrt
wants to merge
27
commits into
main
Choose a base branch
from
console-1003
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
27 commits
Select commit
Hold shift + click to select a range
e3a3a07
improve(laboratory): validate editor content with TypeScript
jasonkuhrt 6fdd227
group laboratory e2e tests
jasonkuhrt de26096
Merge branch 'main' into console-1003
jasonkuhrt 2d772e4
doc rationale
jasonkuhrt ce4c80f
lint
jasonkuhrt 7dfbe35
pin
jasonkuhrt 3bcfb5d
fix
jasonkuhrt 78d4a87
fix type cast any
jasonkuhrt 2b725b2
feedback
jasonkuhrt 09077d0
lock
jasonkuhrt ebe9be3
mention hack
jasonkuhrt 7692fc4
wip
jasonkuhrt a526c7b
Merge branch 'main' into console-1003
jasonkuhrt 3b38db8
undo refactor
jasonkuhrt c420094
undo refactor
jasonkuhrt 2da62d1
Merge branch 'main' into console-1003
jasonkuhrt 26cb47a
ts validation
jasonkuhrt 8d82086
remove refactor
jasonkuhrt b734ade
try feedback change
jasonkuhrt 80eb572
feedback
jasonkuhrt 7c25002
add changeset
jasonkuhrt 0aa198e
no cy selectors
jasonkuhrt fe3f808
fix
jasonkuhrt 60803b1
Merge branch 'main' into console-1003
jasonkuhrt fb29bdd
fixes
jasonkuhrt 865a7bf
fixes
jasonkuhrt 08b3640
format
jasonkuhrt 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
'hive': minor | ||
--- | ||
|
||
Laboratory Preflight now validates your script with TypeScript. Also, the `WebWorker` runtime types are applied giving you confidence about what globals are available to you in your script. | ||
|
||
## Backwards Incompatible Notes | ||
|
||
This change is backwards incompatible in the sense that invalid or problematic Script code which would have previously not statically errored will now. However at this time we do not prevent script saving because of static type errors. Therefore your workflow should only at worst be visually impacted. | ||
|
||
## About WebWorker Runtime & Types | ||
|
||
To learn more about what the WebWorker runtime and types are, you can review the following: | ||
|
||
1. https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | ||
2. https://www.typescriptlang.org/tsconfig/#lib (see "WebWorker") | ||
|
||
|
||
## Leveraging TypeScript in JavaScript | ||
|
||
If you are not familiar with TypeScript, here is a tip for you if you find yourself with a TypeScript error that you cannot or do not want to fix. You can silence them by using comments: | ||
|
||
```js | ||
let a = 1; | ||
let b = ''; | ||
// @ts-ignore | ||
a = b; | ||
// @ts-expect-error | ||
a = b; | ||
``` | ||
|
||
The advantage of `@ts-expect-error` is that if there is no error to ignore, then the comment itself becomes an error whereas `@ts-ignore` sits there quietly whether it has an effect or not. | ||
|
||
There is more you can do with TypeScript in JavaScript, such as providing type annotations via JSDoc. Learn more about it all here: | ||
|
||
https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html |
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,90 @@ | ||
import { cyMonaco } from '../../support/monaco'; | ||
|
||
export namespace cyLaboratory { | ||
/** | ||
* Updates the value of the graphiql editor | ||
*/ | ||
export function updateEditorValue(value: string) { | ||
cy.get('.graphiql-query-editor .cm-s-graphiql').then($editor => { | ||
const editor = ($editor[0] as any).CodeMirror; // Access the CodeMirror instance | ||
editor.setValue(value); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns the value of the graphiql editor as Chainable<string> | ||
*/ | ||
export function getEditorValue() { | ||
return cy.get('.graphiql-query-editor .cm-s-graphiql').then<string>($editor => { | ||
const editor = ($editor[0] as any).CodeMirror; // Access the CodeMirror instance | ||
return editor.getValue(); | ||
}); | ||
} | ||
|
||
/** | ||
* Opens a new tab | ||
*/ | ||
export function openNewTab() { | ||
cy.get('button[aria-label="New tab"]').click(); | ||
// tab's title should be "untitled" as it's a default name | ||
cy.contains('button[aria-controls="graphiql-session"]', 'untitled').should('exist'); | ||
} | ||
|
||
/** | ||
* Asserts that the tab with the given name is active | ||
*/ | ||
export function assertActiveTab(name: string) { | ||
cy.contains('li.graphiql-tab-active > button[aria-controls="graphiql-session"]', name).should( | ||
'exist', | ||
); | ||
} | ||
|
||
/** | ||
* Closes the active tab | ||
*/ | ||
export function closeActiveTab() { | ||
cy.get('li.graphiql-tab-active > button.graphiql-tab-close').click(); | ||
} | ||
|
||
/** | ||
* Closes all tabs until one is left | ||
*/ | ||
export function closeTabsUntilOneLeft() { | ||
cy.get('li.graphiql-tab').then($tabs => { | ||
if ($tabs.length > 1) { | ||
closeActiveTab(); | ||
// Recurse until there's only one tab left | ||
return closeTabsUntilOneLeft(); | ||
} | ||
}); | ||
} | ||
|
||
export namespace preflight { | ||
export const selectors = { | ||
buttonGraphiQLPreflight: '[aria-label*="Preflight Script"]', | ||
buttonModal: '[data-cy="preflight-modal-button"]', | ||
buttonToggle: '[data-cy="toggle-preflight"]', | ||
buttonHeaders: '[data-name="headers"]', | ||
headersEditor: { | ||
textArea: '.graphiql-editor-tool .graphiql-editor:last-child textarea', | ||
}, | ||
graphiql: { | ||
buttonExecute: '.graphiql-execute-button', | ||
}, | ||
|
||
modal: { | ||
buttonSubmit: '[data-cy="preflight-modal-submit"]', | ||
scriptEditor: '[data-cy="preflight-editor"]', | ||
variablesEditor: '[data-cy="env-editor"]', | ||
}, | ||
}; | ||
|
||
export const setScriptEditorContent = (value: string) => { | ||
cyMonaco.setContent(selectors.modal.scriptEditor, value); | ||
}; | ||
|
||
export const setEnvironmentEditorContent = (value: string) => { | ||
cyMonaco.setContent(selectors.modal.variablesEditor, value); | ||
}; | ||
} | ||
} |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.