diff --git a/.gitignore b/.gitignore index 70e68c19a1..74dba23b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,5 @@ schema.graphql resolvers.generated.ts docker/docker-compose.override.yml + +vite.config.ts.*.mjs diff --git a/cypress.config.ts b/cypress.config.ts index 90bdf0e499..68a2b3678b 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,8 +1,10 @@ import fs from 'node:fs'; // eslint-disable-next-line import/no-extraneous-dependencies -- cypress SHOULD be a dev dependency import { defineConfig } from 'cypress'; +import { initSeed } from 'integration-tests/testkit/seed.js'; // eslint-disable-next-line import/no-extraneous-dependencies import pg from 'pg'; +import 'integration-tests/local-dev.js'; const isCI = Boolean(process.env.CI); @@ -22,6 +24,8 @@ export default defineConfig({ }, e2e: { setupNodeEvents(on, config) { + const seed = initSeed(); + async function connectDB(query: string) { const dbUrl = new URL(config.env.POSTGRES_URL); const client = new pg.Client({ @@ -67,32 +71,34 @@ COMMIT; firstName?: string; lastName?: string; } = {}) { - const response = await fetch('http://localhost:3001/auth-api/signup', { - method: 'POST', - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - formFields: [ - { id: 'email', value: email }, - { id: 'password', value: password }, - { id: 'firstName', value: firstName }, - { id: 'lastName', value: lastName }, - ], - }), - }); - const data = await response.json(); - if (response.status !== 200 || data.status === 'FIELD_ERROR') { - throw new Error( - `${response.status}: ${response.statusText}\n\n${JSON.stringify(data, null, 2)}`, - ); - } - const result: Token = { - sAccessToken: response.headers.get('st-access-token')!, - sFrontToken: response.headers.get('front-token')!, - sRefreshToken: response.headers.get('st-refresh-token')!, - }; - return result; + const { createOrg, ownerToken } = seed.createOwner(email); + + // const response = await fetch('http://localhost:3001/auth-api/signup', { + // method: 'POST', + // headers: { + // 'content-type': 'application/json', + // }, + // body: JSON.stringify({ + // formFields: [ + // { id: 'email', value: email }, + // { id: 'password', value: password }, + // { id: 'firstName', value: firstName }, + // { id: 'lastName', value: lastName }, + // ], + // }), + // }); + // const data = await response.json(); + // if (response.status !== 200 || data.status === 'FIELD_ERROR') { + // throw new Error( + // `${response.status}: ${response.statusText}\n\n${JSON.stringify(data, null, 2)}`, + // ); + // } + // const result: Token = { + // sAccessToken: response.headers.get('st-access-token')!, + // sFrontToken: response.headers.get('front-token')!, + // sRefreshToken: response.headers.get('st-refresh-token')!, + // }; + // return result; }, async login() { const response = await fetch('http://localhost:3001/auth-api/signin', { diff --git a/integration-tests/local-dev.ts b/integration-tests/local-dev.ts index 962b88d5fd..2b17957ae7 100644 --- a/integration-tests/local-dev.ts +++ b/integration-tests/local-dev.ts @@ -1,4 +1,5 @@ -import { readFileSync } from 'fs'; +import { readFileSync } from 'node:fs'; +import path from 'node:path'; import { parse } from 'dotenv'; function applyEnv(env: Record) { @@ -7,7 +8,9 @@ function applyEnv(env: Record) { } } -const serverEnvVars = parse(readFileSync('../packages/services/server/.env', 'utf-8')); +const envPath = path.join(process.cwd(), 'packages', 'services', 'server', '.env'); + +const serverEnvVars = parse(readFileSync(envPath, 'utf-8')); applyEnv({ SUPERTOKENS_CONNECTION_URI: serverEnvVars.SUPERTOKENS_CONNECTION_URI, diff --git a/integration-tests/testkit/schema-policy.ts b/integration-tests/testkit/schema-policy.ts index 9602e7e986..ea848467cd 100644 --- a/integration-tests/testkit/schema-policy.ts +++ b/integration-tests/testkit/schema-policy.ts @@ -1,4 +1,4 @@ -import { RuleInstanceSeverityLevel, SchemaPolicyInput } from 'testkit/gql/graphql'; +import { RuleInstanceSeverityLevel, SchemaPolicyInput } from './gql/graphql'; import { graphql } from './gql'; export const OrganizationAndProjectsWithSchemaPolicy = graphql(` diff --git a/integration-tests/testkit/seed.ts b/integration-tests/testkit/seed.ts index f8b00100c7..3a3d401aa6 100644 --- a/integration-tests/testkit/seed.ts +++ b/integration-tests/testkit/seed.ts @@ -7,8 +7,7 @@ import { RegistryModel, SchemaPolicyInput, TargetAccessScope, - TargetSelectorInput, -} from 'testkit/gql/graphql'; +} from './gql/graphql'; import { authenticate, userEmail } from './auth'; import { CreateCollectionMutation, @@ -83,10 +82,9 @@ export function initSeed() { }, }; }, - authenticate: authenticate, + authenticate, generateEmail: () => userEmail(generateUnique()), - async createOwner() { - const ownerEmail = userEmail(generateUnique()); + async createOwner(ownerEmail = userEmail(generateUnique())) { const ownerToken = await authenticate(ownerEmail).then(r => r.access_token); return { diff --git a/package.json b/package.json index 0035781a08..8d08ecee49 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "release": "pnpm build:libraries && changeset publish", "seed": "tsx scripts/seed-local-env.ts", "start": "pnpm run local:setup", + "pretest:e2e":"pnpm --filter integration-tests start", "test": "vitest", "test:e2e": "CYPRESS_BASE_URL=$HIVE_APP_BASE_URL cypress run", "test:integration": "cd integration-tests && pnpm test:integration",