diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 26f337f..d17295c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,22 +4,27 @@ on: pull_request: branches: [main] push: - branches: [main] + branches: [main, pnpm-setup] jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2.4.0 + with: + version: 8 - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: '20' + cache: 'pnpm' - name: Install Dependencies - run: npm ci + run: pnpm install - name: Run Tests - run: npm test + run: pnpm run test diff --git a/packages/client/jest.config.js b/packages/client/jest.config.js index ec0a91b..db375fd 100644 --- a/packages/client/jest.config.js +++ b/packages/client/jest.config.js @@ -3,6 +3,6 @@ import base from '../../jest.config.base.js'; export default { ...base, testEnvironment: 'jest-environment-jsdom', - setupFiles: ['../../test-setup.ts'], + // setupFiles: ['../../test-setup.ts'], setupFilesAfterEnv: ['../../test-setup-after-env.ts'], }; diff --git a/packages/server/jest.config.js b/packages/server/jest.config.js index 551da8b..f282190 100644 --- a/packages/server/jest.config.js +++ b/packages/server/jest.config.js @@ -3,6 +3,6 @@ import base from '../../jest.config.base.js'; export default { ...base, testEnvironment: 'node', - setupFiles: ['../../test-setup.ts'], + // setupFiles: ['../../test-setup.ts'], setupFilesAfterEnv: ['../../test-setup-after-env.ts'], }; diff --git a/test-setup-after-env.ts b/test-setup-after-env.ts index 0151618..c37c92a 100644 --- a/test-setup-after-env.ts +++ b/test-setup-after-env.ts @@ -1,3 +1,14 @@ +const originalEnv = process.env; + beforeEach(() => { + jest.resetModules(); jest.clearAllMocks(); + process.env = { + ...originalEnv, + OPENAI_API_KEY: 'YOUR_MOCKED_VALUE', + }; +}); + +afterEach(() => { + process.env = originalEnv; }); diff --git a/test-setup.ts b/test-setup.ts index b7c788c..8bc035c 100644 --- a/test-setup.ts +++ b/test-setup.ts @@ -1 +1 @@ -process.env.OPENAI_API_KEY = 'test-api-key'; +// process.env.OPENAI_API_KEY = 'test-api-key';