Skip to content

Commit

Permalink
test(examples): e2e test for examples
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
  • Loading branch information
akihikokuroda committed Oct 11, 2024
1 parent 9eeaa0a commit d32d11c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .github/workflows/examples-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: E2E Examples

on:
push:
branches: ["main"]
paths-ignore:
- "**/*.md"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Tests
timeout-minutes: 40
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable
- name: Install ollama
run: curl -fsSL https://ollama.com/install.sh | sh
- name: Run ollama
run: |
ollama serve &
ollama pull llama3.1
- name: Call ollama API
run: |
curl -d '{"model": "llama3.1:latest", "stream": false, "prompt":"Whatever I say, asnwer with Yes"}' http://localhost:11434/api/generate
- name: Example Tests
run: |
yarn test:examples
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"test:e2e:watch": "vitest watch tests",
"test:all": "vitest run",
"test:watch": "vitest watch",
"test:examples": "vitest run tests/e2e/examples",
"test:examples:watch": "vitest run tests/e2e/examples",
"prepare": "husky",
"copyright": "./scripts/copyright.sh",
"release": "release-it",
Expand Down Expand Up @@ -181,7 +183,7 @@
"temp-dir": "^3.0.0",
"tsc-files": "^1.1.4",
"tsup": "^8.3.0",
"tsx": "^4.19.0",
"tsx": "^4.19.1",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0",
"vite-tsconfig-paths": "^5.0.1",
Expand Down
57 changes: 57 additions & 0 deletions tests/e2e/examples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2024 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { execSync } from "child_process";
import * as fs from "fs";
import * as path from "path";

const pattern = process.env.EXAMPLE_NAME;
const files: string[] = [];
function getTypeScriptFiles(directoryPath: string) {
const fileNames = fs.readdirSync(directoryPath);

for (const fileName of fileNames) {
const filePath = path.join(directoryPath, fileName);
if (fs.statSync(filePath).isDirectory()) {
getTypeScriptFiles(filePath);
} else {
if (filePath.endsWith(".ts")) {
files.push(filePath);
}
}
}
}

function runExample(example: string) {
describe("e2e test", () => {
it(`Runs ${example}`, async () => {
execSync(`yarn start -- ${example}`);
});
});
}

const exampleDirectory = "./examples";
getTypeScriptFiles(exampleDirectory);

for (const example of files) {
if (pattern == null || pattern.trim() == "") {
runExample(example);
} else {
if (example.includes(pattern)) {
runExample(example);
}
}
}

0 comments on commit d32d11c

Please sign in to comment.