Skip to content

Commit

Permalink
test(examples): goth ci debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Sep 18, 2023
1 parent 4a299d6 commit 416bf53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/goth-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ jobs:
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd examples
node test.mjs
python -m goth start ../goth/assets/goth-config.yml
- name: Upload test logs
uses: actions/upload-artifact@v2
Expand Down
15 changes: 11 additions & 4 deletions examples/test.mjs → tests/examples/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { spawn } from "child_process";
import { dirname, basename } from "path";
import { dirname, basename, resolve } from "path";
import { Goth } from "../goth/goth";

const gothConfig = resolve("../goth/assets/goth-config.yml");
const goth = new Goth(gothConfig);

const examples = [
{ cmd: "node", path: "docs-examples/examples/composing-tasks/batch-end.mjs" },
{ cmd: "node", path: "examples/docs-examples/examples/composing-tasks/batch-end.mjs" },
{ cmd: "node", path: "docs-examples/examples/composing-tasks/batch-endstream-chunks.mjs" },
{ cmd: "node", path: "docs-examples/examples/composing-tasks/batch-endstream-forawait.mjs" },
{ cmd: "node", path: "docs-examples/examples/composing-tasks/multiple-run-prosaic.mjs" },
Expand All @@ -25,14 +29,16 @@ async function test(cmd, path, args = [], timeout = 120) {
const spawnedExample = spawn(cmd, [file, ...args], { stdio: "inherit", cwd });
const testPromise = new Promise((res, rej) => {
spawnedExample.on("close", (code, signal) => {
if (code === 0) return res();
if (code === 0) return res(true);
rej(`Example test exited with code ${code} by signal ${signal}`);
});
});
return Promise.race([timeoutPromise(timeout), testPromise]);
}

async function testAll(examples) {
const { apiKey } = await goth.start();
console.log(`Goth started with APIKEY:`, apiKey);
try {
for (const example of examples) {
console.log(`Starting test for example ${example.path}`);
Expand All @@ -44,4 +50,5 @@ async function testAll(examples) {
}
process.exit(0);
}
await testAll(examples);

testAll(examples).then();

0 comments on commit 416bf53

Please sign in to comment.