Skip to content

Commit e41fac0

Browse files
committed
Add per-test description and conditional skipping
1 parent 8dd6f9c commit e41fac0

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

.github/workflows/integrationTests.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,4 @@ jobs:
4747
env:
4848
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
4949
run: |
50-
if [ -z "$OPENAI_API_KEY" ]; then
51-
echo "Skipping integration tests due to missing required API keys"
52-
exit 1
53-
else
54-
pnpm run integrationTests
55-
fi
50+
pnpm run integrationTests

tests/test1.mjs

+11-13
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,19 @@ import {
66
runIntegrationTest,
77
} from "./testLibrary.mjs";
88

9-
// Validation function to check required environment variables
10-
async function validateEnvironment(requiredVars) {
11-
const missing = requiredVars.filter(varName => !process.env[varName]);
12-
if (missing.length > 0) {
13-
throw new Error(`Required environment variables not set: ${missing.join(', ')}\nPlease set these variables before running the tests.`);
14-
}
15-
return true;
16-
}
179

1810
async function helloTrump() {
1911
const reply = await send("Hi");
20-
2112
assert(reply.length > 0, "Response should not be empty");
2213
const response = reply[0];
2314
assert(response.text, "Response should have text property");
2415
assert(response.text.length > 10, `Response should be longer than 10 characters, is ${reply.length}`);
25-
2616
}
17+
helloTrump.description = "Hello Trump";
18+
helloTrump.skipIf = !process.env.OPENAI_API_KEY;
2719

28-
async function coinbaseCommerceChargeTest() {
29-
await validateEnvironment(['COINBASE_COMMERCE_KEY']);
3020

21+
async function coinbaseCommerceChargeTest() {
3122
const chargeDescription = "Exclusive digital artwork collection";
3223
const chargeRequest = `Create a charge for $100 USD for Digital Art NFT with description '${chargeDescription}'`;
3324
const response = await send(chargeRequest);
@@ -106,8 +97,15 @@ async function coinbaseCommerceChargeTest() {
10697
assert.equal(chargeData.data.hosted_url, createdChargeUrl, "Hosted URLs should match");
10798
assert.equal(chargeData.data.description, chargeDescription, "Charge description should match")
10899
}
100+
coinbaseCommerceChargeTest.description = "Coinbase Charge";
101+
coinbaseCommerceChargeTest.skipIf = !process.env.OPENAI_API_KEY || !process.env.COINBASE_COMMERCE_KEY;
102+
103+
109104

110-
const testSuite = [helloTrump, coinbaseCommerceChargeTest]; // Add tests here
105+
const testSuite = [
106+
helloTrump,
107+
coinbaseCommerceChargeTest,
108+
];
111109
try {
112110
for (const test of testSuite) await runIntegrationTest(test);
113111
} catch (error) {

tests/testLibrary.mjs

+17-10
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,22 @@ async function send(message) {
112112
}
113113

114114
async function runIntegrationTest(fn) {
115-
const proc = await startAgent();
116-
try {
117-
await fn();
118-
log("✓ Test passed");
119-
} catch (error) {
120-
log("✗ Test failed");
121-
logError(error);
122-
} finally {
123-
await stopAgent(proc);
115+
const skip = fn.hasOwnProperty("skipIf") ? fn.skipIf : false;
116+
const description = fn.description ?? "unnamed";
117+
if (skip) {
118+
log(fn.description ? `Skipping test ${fn.description}...` : "Skipping test...");
119+
} else {
120+
log(fn.description ? `Running test ${fn.description}...` : "Running test...");
121+
const proc = await startAgent();
122+
try {
123+
await fn();
124+
log(fn.description ? `✓ Test ${fn.description} passed` : "✓ Test passed");
125+
} catch (error) {
126+
log(fn.description ? `✗ Test ${fn.description} failed` : "✗ Test failed");
127+
logError(error);
128+
} finally {
129+
await stopAgent(proc);
130+
}
124131
}
125132
}
126133

@@ -137,4 +144,4 @@ export {
137144
log,
138145
logError,
139146
sleep
140-
}
147+
}

0 commit comments

Comments
 (0)