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 19, 2023
1 parent 3e42743 commit 79cf8c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/goth-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
sudo apt-get install -y build-essential
npm install
npm run build
npm install ts-node
- name: Configure python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -86,7 +87,7 @@ jobs:
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m goth start ../goth/assets/goth-config.yml
npm run test:examples
- name: Upload test logs
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test:e2e": "jest --config tests/e2e/jest.config.json tests/e2e/**.spec.ts --runInBand --forceExit",
"test:e2e:no-goth": "jest tests/e2e/**.spec.ts --testTimeout=180000 --runInBand --forceExit",
"test:cypress": "cypress run",
"test:examples": "node examples/test.mjs",
"test:examples": "ts-node --project ./tsconfig.spec.json tests/examples/examples.test.ts",
"lint": "npm run lint:ts && npm run lint:ts:tests && npm run lint:eslint",
"lint:ts": "tsc --project tsconfig.json --noEmit",
"lint:ts:tests": "tsc --project tests/tsconfig.json --noEmit",
Expand Down
22 changes: 14 additions & 8 deletions tests/examples/test.ts → tests/examples/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { Goth } from "../goth/goth";
const gothConfig = resolve("../goth/assets/goth-config.yml");
const goth = new Goth(gothConfig);

const examples = [
type Example = {
cmd: string;
path: string;
args?: string[];
timeout?: number;
};

const examples: Example[] = [
{ 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" },
Expand All @@ -15,34 +22,33 @@ const examples = [

const criticalLogsRegexp = [/Task timeot/, /Task rejected/, /TODO/];

const timeoutPromise = (seconds) =>
const timeoutPromise = (seconds: number) =>
new Promise((res, rej) =>
setTimeout(
() => rej(new Error(`The timeout was reached and the racing promise has rejected after ${seconds} seconds`)),
seconds * 1000,
),
);

async function test(cmd, path, args = [], timeout = 120) {
async function examplesTest(cmd: string, path: string, args: string[] = [], timeout = 120) {
const file = basename(path);
const cwd = dirname(path);
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(true);
rej(`Example test exited with code ${code} by signal ${signal}`);
rej(`Example test "${file}" 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);
async function testAll(examples: Example[]) {
await Promise.race([goth.start(), timeoutPromise(180)]);
try {
for (const example of examples) {
console.log(`Starting test for example ${example.path}`);
await test(example.cmd, example.path, example.args);
await examplesTest(example.cmd, example.path, example.args);
}
} catch (error) {
console.error(error);
Expand Down
8 changes: 7 additions & 1 deletion tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@
"typeRoots": ["node_modules/@types"]
},
"exclude": ["dist", "node_modules", "examples", "cypress.config.ts"],
"include": ["src/**/*.spec.ts", "tests/unit/**/*.test.ts", "tests/unit/**/*.spec.ts"]
"include": ["src/**/*.spec.ts", "tests/unit/**/*.test.ts", "tests/unit/**/*.spec.ts"],
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "nodenext"
}
}
}

0 comments on commit 79cf8c1

Please sign in to comment.