Skip to content

Commit

Permalink
feat: move api e2e to tests package
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 8, 2024
1 parent c25217e commit 476b91f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/actions/copilot-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Run Copilot E2E Test'
inputs:
script:
description: 'Script to run'
default: 'yarn workspace @affine-test/affine-cloud-copilot e2e --forbid-only'
default: 'yarn workspace @affine-test/affine-cloud-copilot test:e2e --forbid-only'
required: false
openai-key:
description: 'OpenAI secret key'
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/copilot-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ jobs:
strategy:
fail-fast: false
matrix:
type: [e2e, spec]
spec:
- {
name: e2e,
package: '@affine-test/affine-cloud-copilot',
type: e2e,
}
- { name: spec, package: '@affine/server', type: copilot:spec }
services:
postgres:
image: postgres
Expand Down Expand Up @@ -82,8 +88,8 @@ jobs:
- name: Prepare Server Test Environment
uses: ./.github/actions/server-test-env

- name: Run copilot api ${{ matrix.type }} tests
run: yarn workspace @affine/server test:copilot:${{ matrix.type }}:coverage --forbid-only
- name: Run copilot api ${{ matrix.name }} tests
run: yarn workspace ${{ matrix.spec.package }} test:${{ matrix.spec.type }}:coverage --forbid-only
env:
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
Expand Down Expand Up @@ -147,7 +153,7 @@ jobs:
- name: Run Copilot E2E Test ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
uses: ./.github/actions/copilot-test
with:
script: yarn workspace @affine-test/affine-cloud-copilot e2e --forbid-only --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
script: yarn workspace @affine-test/affine-cloud-copilot test:e2e --forbid-only --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
openai-key: ${{ secrets.COPILOT_OPENAI_API_KEY }}
fal-key: ${{ secrets.COPILOT_FAL_API_KEY }}

Expand Down
2 changes: 0 additions & 2 deletions packages/backend/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
"start": "node --loader ts-node/esm/transpile-only.mjs ./src/index.ts",
"dev": "nodemon ./src/index.ts",
"test": "ava --concurrency 1 --serial",
"test:copilot:e2e": "ava \"tests/**/copilot-*.e2e.ts\"",
"test:copilot:spec": "ava \"tests/**/copilot-*.spec.ts\"",
"test:coverage": "c8 ava --concurrency 1 --serial",
"test:copilot:e2e:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.e2e.ts\"",
"test:copilot:spec:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.spec.ts\"",
"postinstall": "prisma generate",
"data-migration": "node --loader ts-node/esm/transpile-only.mjs ./src/data/index.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/// <reference types="../src/global.d.ts" />

import { randomUUID } from 'node:crypto';

import { INestApplication } from '@nestjs/common';
import type { ExecutionContext, TestFn } from 'ava';
import ava from 'ava';

import { automaticSignIn, createWorkspace } from './utils';
import { automaticSignIn, createWorkspace } from '@affine/server/tests/utils';
import {
chatWithImages,
chatWithText,
Expand All @@ -16,10 +10,12 @@ import {
ProviderActionTestCase,
ProviderWorkflowTestCase,
sse2array,
} from './utils/copilot';
} from '@affine/server/tests/utils/copilot';
import type { ExecutionContext, TestFn } from 'ava';
import ava from 'ava';

type Tester = {
app: INestApplication<any>;
app: any;
userToken: string;
workspaceId: string;
};
Expand Down Expand Up @@ -54,7 +50,7 @@ const runIfCopilotConfigured = test.macro(
test.before(async t => {
if (!isCopilotConfigured) return;
const { endpoint, user, password, secret } = e2eConfig;
const app = { getHttpServer: () => endpoint } as INestApplication<any>;
const app = { getHttpServer: () => endpoint } as any;
const token = await automaticSignIn(app, user, password, secret);
const { id } = await createWorkspace(app, token);

Expand Down
8 changes: 6 additions & 2 deletions tests/affine-cloud-copilot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
"name": "@affine-test/affine-cloud-copilot",
"private": true,
"scripts": {
"e2e": "yarn playwright test"
"test:e2e": "yarn playwright test",
"test:api": "ava \"tests/**/copilot-*.e2e.ts\"",
"test:api:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.e2e.ts\""
},
"devDependencies": {
"@affine-test/kit": "workspace:*",
"@playwright/test": "=1.48.2"
"@affine/server": "workspace:*",
"@playwright/test": "=1.48.2",
"ava": "^6.1.2"
},
"version": "0.17.0"
}
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ __metadata:
resolution: "@affine-test/affine-cloud-copilot@workspace:tests/affine-cloud-copilot"
dependencies:
"@affine-test/kit": "workspace:*"
"@affine/server": "workspace:*"
"@playwright/test": "npm:=1.48.2"
ava: "npm:^6.1.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -746,7 +748,7 @@ __metadata:
languageName: unknown
linkType: soft

"@affine/server@workspace:packages/backend/server":
"@affine/server@workspace:*, @affine/server@workspace:packages/backend/server":
version: 0.0.0-use.local
resolution: "@affine/server@workspace:packages/backend/server"
dependencies:
Expand Down

0 comments on commit 476b91f

Please sign in to comment.