Skip to content

Commit

Permalink
App test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang-33 committed Apr 2, 2024
1 parent ea09c91 commit db836ad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
42 changes: 42 additions & 0 deletions .github/actions/app-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'Start and Test Node.js App'
description: 'Starts Node.js app, runs tests, and shuts it down'
inputs:
port:
description: 'Port on which the Node.js app is running'
required: true
path:
description: 'Path to test with the HTTP request'
required: false
default: ""
method:
description: 'HTTP method to use for the test (GET, POST, etc.)'
required: true
body:
description: 'Request body for POST method (optional)'
required: false
default: ""

runs:
using: 'composite'
steps:
- name: Start application
run: npm start &
shell: bash

- name: Wait for application to start
run: sleep 10
shell: bash


- name: Test application
run: |
if [ "${{ inputs.method }}" = "POST" ]; then
curl --fail -X POST -d '${{ inputs.body }}' http://localhost:${{ inputs.port }}/${{ inputs.path }} || exit 1
else
curl --fail -X ${{ inputs.method }} http://localhost:${{ inputs.port }}/${{ inputs.path }} || exit 1
fi
shell: bash

- name: Kill application
run: pkill node
shell: bash
16 changes: 10 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
node: [ '18', '20' ]
fail-fast: false

name: Node.js ${{ matrix.node }}
name: Node.js ${{ matrix.node }} - test

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
# https://nodejs.org/en/about/releases/
node: [ '18', '20' ]
fail-fast: false
name: Node.js ${{ matrix.node }}
name: Node.js ${{ matrix.node }} - example
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -57,15 +57,19 @@ jobs:
node-version: ${{ matrix.node }}
- name: Test building examples (CJS)
run: |
cd examples/echo-bot-ts-cjs
pushd examples/echo-bot-ts-cjs
npm run build-sdk
npm install
npm run build
cd -
- name: Test Node.js App
uses: ./.github/actions/app-test
with:
port: '3000'
method: 'GET'
- name: Test building examples (ESM)
run: |
cd examples/echo-bot-ts-esm
popd
pushd examples/echo-bot-ts-esm
npm run build-sdk
npm install
npm run build
cd -

0 comments on commit db836ad

Please sign in to comment.