Skip to content

Commit

Permalink
feat: add support for default-timeout input (#625)
Browse files Browse the repository at this point in the history
Closes #621
  • Loading branch information
char0n authored Feb 11, 2025
1 parent 8754dd0 commit 20d763d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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

0 comments on commit 20d763d

Please sign in to comment.