Skip to content

Commit

Permalink
fix: fixing startup of mock server
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo Velasquez committed Jul 1, 2024
1 parent 23340aa commit f03eb27
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 39 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,29 @@ jobs:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install npm Dependencies
id: npm-ci
run: npm ci

- name: Start Mock Server
id: mock-server
run: |
nohup npm run mock-server > /dev/null 2>&1 &
echo $! > mock-server.PID
npm run mock-server &
echo $! > "$(pwd)/mock-server.PID"
sleep 1 # Give it a moment before logging
- name: Wait for Mock Server
run: sleep 5 # Waits for 5 seconds. Adjust the time based on your server's startup time.
run: |
for i in {1..10}; do
echo "Attempt $i"
curl --fail http://localhost:3000/v1/ && echo "Mock server is up" && break || echo "Waiting for mock server..."
sleep 5
done
- name: Verify Mock Server is Up
run: |
Expand All @@ -71,15 +85,17 @@ jobs:
uses: ./
with:
links-filepath: '.lighthouseci/links.json'
base-url: 'https://localhost:3000/v1'
base-url: 'http://localhost:3000/v1'
project-id: 'mock-project-id'
current-commit-sha: '59e778936f40d70edb2af15d61fdeb5cae661649'

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.markdown }}"
run: |
echo "${{ steps.test-action.outputs.markdown }}"
echo "${{ steps.test-action.outputs.comparedMetrics }}"
- name: Kill Mock Server
if: always()
run: |
kill $(cat mock-server.PID)
kill "$(cat mock-server.PID)"
6 changes: 5 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ describe('action', () => {
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
it('sets a failed status if inputs are empty', async () => {
// Set the action's inputs as return values from core.getInput()
// getBuildsMock.mockRejectedValue(
// new Error(`[api-service][ERROR]: Could not get builds from LHCI API`)
// )
// all inputs are empty
getInputMock.mockImplementation(() => {
return ''
})

await main.run()
expect(runMock).toHaveReturned()
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ inputs:

# Define your outputs here.
outputs:
time:
description: 'Your output description here'
markdown:
description: 'The markdown table with the results'
comparedMetrics:
description:
'An object with the results, in case you want to use it for something
else.'

runs:
using: node20
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 39 additions & 25 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getBuilds = async ({
const CURRENT_COMMIT_SHA = currentCommitSha
const BUILD_LIST_URL = `${PROJECT_URL}/builds?limit=20`

console.log('Build LIst URL \n', BUILD_LIST_URL)
const buildListResponse = await fetch(BUILD_LIST_URL)
if (!buildListResponse.ok) {
throw new Error(`[api-service][ERROR]: Could not get builds from LHCI API`)
Expand Down
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import { InputsInterface } from './types.d'
import { ComparisonResultsByURLInterface, InputsInterface } from './types.d'
import { getBuilds, getLighthouseCIRuns } from './api-service'
import { compareLHRs } from './compare-service'
import { formatReportComparisonAsMarkdown } from './markdown-service'
Expand Down Expand Up @@ -48,8 +48,11 @@ export const executeRun = async ({
debug
}: {
inputs: InputsInterface
debug: any
}) => {
debug: typeof core.debug
}): Promise<{
markdownResult: string
comparedMetrics: ComparisonResultsByURLInterface
}> => {
debug('Running action and printing inputs...')
debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
const { build, ancestorBuild } = await getBuilds(inputs)
Expand Down

0 comments on commit f03eb27

Please sign in to comment.