Skip to content

Commit

Permalink
chore: Refactor E2E Test using Jest (#51)
Browse files Browse the repository at this point in the history
* WIP

* Apply local testing strategy

* Fix server startup

* Fix WGET

* Fix WGET

* Cleanup

* More cleanup

* Add Staging and Prod environments

* Try printing environment info

* Update .github/workflows/e2e-test.yaml

Co-authored-by: Marika Marszalkowski <[email protected]>

* Update .github/workflows/e2e-test.yaml

Co-authored-by: Marika Marszalkowski <[email protected]>

* Update sample-code/src/index.ts

Co-authored-by: Marika Marszalkowski <[email protected]>

* Add linting and change to await/try/catch

* Formatting

* Try moving E2E test to jest

* Cleanup and fix badge link

* fix: Changes from lint

* Cleanup

* Remove redundant dependencies

* Update lockfile

* experiments

* Fix jest

* Update E2E Test workflow

* Add install step

* Update lockfile

* Try fix

* Fix TS finally

* Remove unnecessary workaround

* re-enable slack notification

* Cleanup

* Fix import paths

* Add AI Core and Orchestration Tests

* fix: Changes from lint

* Disable orchestration e2e test

* fix: Changes from lint

* set private

---------

Co-authored-by: Marika Marszalkowski <[email protected]>
Co-authored-by: cloud-sdk-js <[email protected]>
Co-authored-by: deekshas8 <[email protected]>
  • Loading branch information
4 people authored Aug 6, 2024
1 parent 17321ce commit fd4e8d2
Show file tree
Hide file tree
Showing 21 changed files with 544 additions and 334 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: "E2E Test"
on:
push:
branches:
- chore/e2e-test
workflow_dispatch:
schedule:
- cron: 0 22 * * *
Expand All @@ -20,9 +17,6 @@ jobs:
secret-name: AI_CORE_PRODUCTION
name: "Build and Test"
runs-on: ubuntu-latest
env:
WGET_ARGS: "-qO- -S --content-on-error"
WGET_URL: "localhost:8080"
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
Expand All @@ -37,12 +31,12 @@ jobs:
- name: Create .env file
env:
aicore: ${{ secrets[matrix.secret-name] }}
working-directory: ./sample-code
run: |
echo "aicore='$aicore'" > .env
echo "aicore='$aicore'" > sample-code/.env
echo "aicore='$aicore'" > tests/e2e-tests/.env
url=$(echo "$aicore" | jq -r '.serviceurls.AI_API_URL' | sed 's|^https://||')
echo "Using AI Core ${{ matrix.environment }} instance on $url"
- name: "Start App"
- name: "Check Sample App Starts Up"
working-directory: ./sample-code
run: |
pnpm run local &
Expand All @@ -55,15 +49,11 @@ jobs:
exit 1
fi
done
- name: "Health Check"
run: |
wget "$WGET_ARGS" "$WGET_URL/health"
- name: "OpenAI Chat Completion"
run: |
wget "$WGET_ARGS" "$WGET_URL/llm"
- name: "OpenAI Text Embedding"
wget -qO- -S --content-on-error localhost:8080
- name: "Execute E2E Tests"
working-directory: ./tests/e2e-tests
run: |
wget "$WGET_ARGS" "$WGET_URL/embedding"
pnpm run e2e-test
- name: "Slack Notification"
if: failure()
uses: slackapi/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ build/Release
.env
.env.test
.env.local

# VS Code
.vscode
/pnpm-publish-summary.json
12 changes: 7 additions & 5 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const config = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm',

// Run tests from one or more projects
// projects: undefined,
Expand Down Expand Up @@ -153,9 +153,9 @@ const config = {
testMatch: ['**/*.test.ts'],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
testPathIgnorePatterns: [
"./dist"
],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
Expand All @@ -166,6 +166,8 @@ const config = {
// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// extensionsToTreatAsEsm: ['.ts'],

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.tsx?$': [
Expand All @@ -186,7 +188,7 @@ const config = {
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,
// verbose: true,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"repository": "github:SAP/ai-sdk-js",
"private": true,
"type": "module",
"types": "type-tests",
"types": "tests/type-tests",
"tsd": {
"directory": "type-tests"
"directory": "tests/type-tests"
},
"scripts": {
"postinstall": "pnpm compile",
Expand Down
1 change: 1 addition & 0 deletions packages/gen-ai-hub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export {
LlmConfig,
ChatMessages
} from './orchestration/index.js';
export { getAiCoreDestination } from './core/index.js';
Loading

0 comments on commit fd4e8d2

Please sign in to comment.