Browse Source

Switch to using dotenv to get test environment variables

ColemanRoo 1 year ago
parent
commit
8e54360a86
3 changed files with 28 additions and 13 deletions
  1. 14 0
      package-lock.json
  2. 2 1
      package.json
  3. 12 12
      src/test/extension.test.ts

+ 14 - 0
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",

+ 2 - 1
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",

+ 12 - 12
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;