From 8e54360a8606b8aa217918fd84674993122fffef Mon Sep 17 00:00:00 2001 From: ColemanRoo Date: Fri, 3 Jan 2025 21:35:25 -0600 Subject: [PATCH] Switch to using dotenv to get test environment variables --- package-lock.json | 14 ++++++++++++++ package.json | 3 ++- src/test/extension.test.ts | 24 ++++++++++++------------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6143970..fb2065a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,7 @@ "@typescript-eslint/parser": "^7.11.0", "@vscode/test-cli": "^0.0.9", "@vscode/test-electron": "^2.4.0", + "dotenv": "^16.4.7", "esbuild": "^0.24.0", "eslint": "^8.57.0", "husky": "^9.1.7", @@ -8000,6 +8001,19 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/duck": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/duck/-/duck-0.1.12.tgz", diff --git a/package.json b/package.json index 0f9666b..0ac1434 100644 --- a/package.json +++ b/package.json @@ -185,6 +185,7 @@ "@typescript-eslint/parser": "^7.11.0", "@vscode/test-cli": "^0.0.9", "@vscode/test-electron": "^2.4.0", + "dotenv": "^16.4.7", "esbuild": "^0.24.0", "eslint": "^8.57.0", "husky": "^9.1.7", @@ -196,9 +197,9 @@ }, "dependencies": { "@anthropic-ai/bedrock-sdk": "^0.10.2", - "@aws-sdk/client-bedrock-runtime": "^3.706.0", "@anthropic-ai/sdk": "^0.26.0", "@anthropic-ai/vertex-sdk": "^0.4.1", + "@aws-sdk/client-bedrock-runtime": "^3.706.0", "@google/generative-ai": "^0.18.0", "@modelcontextprotocol/sdk": "^1.0.1", "@types/clone-deep": "^4.0.4", diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index d57654b..7377f3f 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -2,6 +2,11 @@ const assert = require('assert'); const vscode = require('vscode'); const path = require('path'); const fs = require('fs'); +const dotenv = require('dotenv'); + +// Load test environment variables +const testEnvPath = path.join(__dirname, '.test_env'); +dotenv.config({ path: testEnvPath }); suite('Roo Cline Extension Test Suite', () => { vscode.window.showInformationMessage('Starting Roo Cline extension tests.'); @@ -34,14 +39,11 @@ suite('Roo Cline Extension Test Suite', () => { } // Verify API key is set and valid - const testEnvPath = path.join(__dirname, '.test_env'); - const envContent = fs.readFileSync(testEnvPath, 'utf8'); - const match = envContent.match(/OPEN_ROUTER_API_KEY=(.+)/); - if (!match) { - done(new Error('OpenRouter API key should be present in .test_env')); + const apiKey = process.env.OPEN_ROUTER_API_KEY; + if (!apiKey) { + done(new Error('OPEN_ROUTER_API_KEY environment variable is not set')); return; } - const apiKey = match[1]; if (!apiKey.startsWith('sk-or-v1-')) { done(new Error('OpenRouter API key should have correct format')); return; @@ -180,14 +182,12 @@ suite('Roo Cline Extension Test Suite', () => { // Set up API configuration await provider.updateGlobalState('apiProvider', 'openrouter'); await provider.updateGlobalState('openRouterModelId', 'anthropic/claude-3.5-sonnet'); - const testEnvPath = path.join(__dirname, '.test_env'); - const envContent = fs.readFileSync(testEnvPath, 'utf8'); - const match = envContent.match(/OPEN_ROUTER_API_KEY=(.+)/); - if (!match) { - assert.fail('OpenRouter API key should be present in .test_env'); + const apiKey = process.env.OPEN_ROUTER_API_KEY; + if (!apiKey) { + assert.fail('OPEN_ROUTER_API_KEY environment variable is not set'); return; } - await provider.storeSecret('openRouterApiKey', match[1]); + await provider.storeSecret('openRouterApiKey', apiKey); // Create webview panel with development options const extensionUri = extension.extensionUri;