Skip to content

Commit 20d763d

Browse files
authored
feat: add support for default-timeout input (#625)
Closes #621
1 parent 8754dd0 commit 20d763d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ jobs:
8383
with:
8484
definition-file: examples/openapi-2-0-error.yaml
8585
ignore-error: examples/ignore-error.js
86+
default-timeout: 30000

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ as a physical file in your repository.
3131
**Optional** Defines path to JavaScript file containing predicate for determining if the error should be ignored or not.
3232

3333

34+
### `default-timeout`
35+
36+
**Optional** Defines maximum time in milliseconds a script waits for certain actions or events to occur.
37+
38+
3439
## Example usage
3540

3641
There are two major use-cases of how to use this GitHub Action.
@@ -87,4 +92,5 @@ jobs:
8792
with:
8893
swagger-editor-url: http://localhost/
8994
definition-file: examples/openapi-2-0.yaml
95+
default-timeout: 20000
9096
```

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ inputs:
1212
ignore-error:
1313
description: JavaScript file containing predicate for determining if the error should be ignored or not
1414
required: false
15+
default-timeout:
16+
description: Maximum time in milliseconds a script waits for certain actions or events to occur
17+
required: false
1518
runs:
1619
using: composite
1720
steps:
1821
- run: cd ${{ github.action_path }} && npm install
1922
shell: bash
20-
- 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
23+
- 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
2124
shell: bash
2225
branding:
2326
icon: 'file-text'

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const parseErrors = async (page) => {
5757
try {
5858
await page.waitForSelector(
5959
'.swagger-ui .errors-wrapper .errors .error-wrapper',
60-
{ visible: true, timeout: 10000 }
60+
{ visible: true }
6161
);
6262
} catch {
6363
return errors;
@@ -85,10 +85,13 @@ const definitionFilePath = path.join(
8585
process.env.GITHUB_WORKSPACE,
8686
process.env.DEFINITION_FILE
8787
);
88+
const defaultTimeout = parseInt(process.env.DEFAULT_TIMEOUT || '10000', 10);
8889

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

93+
page.setDefaultNavigationTimeout(defaultTimeout);
94+
page.setDefaultTimeout(defaultTimeout);
9295
await page.goto(process.env.SWAGGER_EDITOR_URL);
9396
await page.waitForSelector('.info .main .title', { visible: true });
9497
await page.waitForSelector('.ace_text-input', { visible: true });
@@ -104,7 +107,7 @@ try {
104107
await page.keyboard.up('Control');
105108
await page.waitForFunction(
106109
(text) => document.body.innerText.includes(text),
107-
{ timeout: 10000 },
110+
{},
108111
'No API definition provided'
109112
);
110113
// paste in the OpenAPI description

0 commit comments

Comments
 (0)