Skip to content
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

feat: add support for default-timeout input #625

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ jobs:
with:
definition-file: examples/openapi-2-0-error.yaml
ignore-error: examples/ignore-error.js
default-timeout: 30000
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ as a physical file in your repository.
**Optional** Defines path to JavaScript file containing predicate for determining if the error should be ignored or not.


### `default-timeout`

**Optional** Defines maximum time in milliseconds a script waits for certain actions or events to occur.


## Example usage

There are two major use-cases of how to use this GitHub Action.
Expand Down Expand Up @@ -87,4 +92,5 @@ jobs:
with:
swagger-editor-url: http://localhost/
definition-file: examples/openapi-2-0.yaml
default-timeout: 20000
```
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ inputs:
ignore-error:
description: JavaScript file containing predicate for determining if the error should be ignored or not
required: false
default-timeout:
description: Maximum time in milliseconds a script waits for certain actions or events to occur
required: false
runs:
using: composite
steps:
- run: cd ${{ github.action_path }} && npm install
shell: bash
- run: cd ${{ github.action_path }} && SWAGGER_EDITOR_URL=${{ inputs.swagger-editor-url }} DEFINITION_FILE=${{ inputs.definition-file }} IGNORE_ERROR=${{ inputs.ignore-error }} node src/index.js
- run: cd ${{ github.action_path }} && SWAGGER_EDITOR_URL=${{ inputs.swagger-editor-url }} DEFINITION_FILE=${{ inputs.definition-file }} IGNORE_ERROR=${{ inputs.ignore-error }} DEFAULT_TIMEOUT=${{ inputs.default-timeout }} node src/index.js
shell: bash
branding:
icon: 'file-text'
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const parseErrors = async (page) => {
try {
await page.waitForSelector(
'.swagger-ui .errors-wrapper .errors .error-wrapper',
{ visible: true, timeout: 10000 }
{ visible: true }
);
} catch {
return errors;
Expand Down Expand Up @@ -85,10 +85,13 @@ const definitionFilePath = path.join(
process.env.GITHUB_WORKSPACE,
process.env.DEFINITION_FILE
);
const defaultTimeout = parseInt(process.env.DEFAULT_TIMEOUT || '10000', 10);

try {
const definition = fs.readFileSync(definitionFilePath).toString();

page.setDefaultNavigationTimeout(defaultTimeout);
page.setDefaultTimeout(defaultTimeout);
await page.goto(process.env.SWAGGER_EDITOR_URL);
await page.waitForSelector('.info .main .title', { visible: true });
await page.waitForSelector('.ace_text-input', { visible: true });
Expand All @@ -104,7 +107,7 @@ try {
await page.keyboard.up('Control');
await page.waitForFunction(
(text) => document.body.innerText.includes(text),
{ timeout: 10000 },
{},
'No API definition provided'
);
// paste in the OpenAPI description
Expand Down
Loading