Skip to content

Commit 0d477b1

Browse files
committed
scripts: replace js test job with cargo-make
1 parent f83844d commit 0d477b1

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

Makefile.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ extend = "js-base"
2626
dependencies = ["js-install"]
2727
args = ["lint"]
2828

29+
[tasks.js-test]
30+
script = [
31+
"./scripts/start-test-validator.sh",
32+
"cd ${MANIFEST_DIR}",
33+
"pnpm install",
34+
"pnpm build",
35+
"pnpm test",
36+
"./scripts/stop-test-validator.sh",
37+
]
38+
2939

3040
# Rust Tasks
3141

scripts/js.mts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,11 @@ import {
99
} from './helpers/utils.mts';
1010

1111
enum Command {
12-
Test = 'test',
1312
Publish = 'publish',
1413
}
1514

1615
const { command, libraryPath, args } = parseCliArguments();
1716

18-
async function pnpm(
19-
command: string,
20-
build = false,
21-
) {
22-
const [pnpmArgs, commandArgs] = partitionArguments(args, '--');
23-
cd(libraryPath);
24-
await $`pnpm install`;
25-
if (build) {
26-
await $`pnpm build`;
27-
}
28-
await $`pnpm ${command} ${pnpmArgs} -- ${commandArgs}`;
29-
}
30-
31-
async function test() {
32-
// Start the local validator, or restart it if it is already running.
33-
await $`pnpm validator:restart`;
34-
35-
// Build the client and run the tests.
36-
return pnpm('test', true);
37-
}
38-
3917
async function publish() {
4018
const [level, tag = 'latest'] = args;
4119
if (!level) {
@@ -72,9 +50,6 @@ async function publish() {
7250

7351

7452
switch (command) {
75-
case Command.Test:
76-
await test();
77-
break;
7853
case Command.Publish:
7954
await publish();
8055
break;

scripts/start-test-validator.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
4+
PORT=8899
5+
LOG_FILE="./test-ledger/validator.log"
6+
7+
PID=$(lsof -t -i:$PORT)
8+
9+
if [ -n "$PID" ]; then
10+
echo "Detected test validator running on PID $PID. Restarting..."
11+
kill "$PID"
12+
sleep 1
13+
fi
14+
15+
echo "Starting Solana test validator..."
16+
solana-test-validator > /dev/null 2>&1 &
17+
VALIDATOR_PID=$!
18+
19+
# Wait for test validator to move past slot 0.
20+
echo -n "Waiting for validator to stabilize"
21+
for i in {1..8}; do
22+
if ! kill -0 "$VALIDATOR_PID" 2>/dev/null; then
23+
echo -e "\nTest validator exited early."
24+
exit 1
25+
fi
26+
27+
SLOT=$(solana slot -ul 2>/dev/null)
28+
if [[ "$SLOT" =~ ^[0-9]+$ ]] && [ "$SLOT" -gt 0 ]; then
29+
echo -e "\nTest validator is ready. Slot: $SLOT"
30+
exit 0
31+
fi
32+
33+
echo -n "."
34+
sleep 2
35+
done
36+
37+
echo -e "\nTimed out waiting for test validator to stabilize."
38+
exit 1

scripts/stop-test-validator.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
PORT=8899
4+
5+
if lsof -t -i:$PORT > /dev/null; then
6+
echo "Stopping test validator..."
7+
pkill -f solana-test-validator
8+
sleep 1
9+
echo "Test validator terminated."
10+
else
11+
echo "Test validator is not running."
12+
fi

0 commit comments

Comments
 (0)