Skip to content

Commit

Permalink
feat(test): add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Mar 5, 2024
1 parent 8c844bc commit 97acacd
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 6 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: tests
on: pull_request

jobs:
run-tests:
unit:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -29,5 +29,35 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Jest tests
run: pnpm test
- name: Unit tests
run: pnpm test:unit

e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install pnpm
run: npm install -g pnpm@8

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: E2E tests
run: pnpm test:e2e
68 changes: 68 additions & 0 deletions examples/simple-worker.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Workflow } from '../src';
import sleep from '../src/util/sleep';
import Hatchet from '../src/sdk';

describe('e2e', () => {
let hatchet: Hatchet;

beforeEach(() => {
hatchet = Hatchet.init();
});

describe('workflow', () => {
it('should pass', async () => {
let invoked = 0;

const workflow: Workflow = {
id: 'simple-e2e-workflow',
description: 'test',
on: {
event: 'user:create',
},
steps: [
{
name: 'step1',
run: async (ctx) => {
console.log('starting step1 with the following input', ctx.workflowInput());
invoked += 1;
return { step1: 'step1 results!' };
},
},
{
name: 'step2',
parents: ['step1'],
run: (ctx) => {
console.log('executed step2 after step1 returned ', ctx.stepOutput('step1'));
invoked += 1;
return { step2: 'step2 results!' };
},
},
],
};

console.log('starting worker...');

const worker = await hatchet.worker('example-worker');
console.log('registering workflow...');
await worker.registerWorkflow(workflow);

console.log('worker started.');

void worker.start();

await sleep(20000);

console.log('pushing event...');

await hatchet.event.push('user:create', {
test: 'test',
});

await sleep(5000);

expect(invoked).toEqual(2);

// await worker.stop();
}, 60000);
});
});
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"files": [
"*",
"!**/*.test.js",
"!**/*.test.d.ts"
"!**/*.test.d.ts",
"!**/*.e2e.js",
"!**/*.e2e.d.ts"
],
"repository": {
"type": "git",
Expand All @@ -17,8 +19,9 @@
"build": "echo 'build hatchet sdk with `npn run tsc:build` to ensure it is not build during the publish step' && exit 0",
"prepare": "npm run build",
"tsc:build": "tsc && resolve-tspaths",
"test": "jest",
"test:watch": "jest --watch",
"test:unit": "jest --testMatch='**/*.test.ts'",
"test:e2e": "jest --testMatch='**/*.e2e.ts'",
"test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
"generate": "pnpm run '/generate-.*/'",
"generate-api": "npx --yes swagger-cli bundle ./hatchet/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
"generate-protoc": "./generate-protoc.sh",
Expand Down

0 comments on commit 97acacd

Please sign in to comment.