Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd0d16e

Browse files
authored
Merge pull request#2 from ServiceStack/claude/create-npx-project-script-014KBKErgkQjXM1eXSndDaZi
Add comprehensive test scripts
2 parents34740b3 +166c5fb commitfd0d16e

File tree

4 files changed

+259
-0
lines changed

4 files changed

+259
-0
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules/
33
.DS_Store
44
temp-download.zip
55
temp-extract/
6+
test-projects/
7+
test-manual/

‎README.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ This downloads from: `https://github.com/NetFrameworkTemplates/web-netfx`
5757

5858
- Node.js >= 14.0.0
5959

60+
##Testing
61+
62+
Two test scripts are provided to verify the functionality:
63+
64+
###Automated Tests
65+
66+
Run automated tests that verify all scenarios and clean up afterwards:
67+
68+
```bash
69+
./test.sh
70+
```
71+
72+
This tests:
73+
- Creating a project with repo name and ProjectName
74+
- Creating a project with organization/repo and ProjectName
75+
- Creating a project without ProjectName (current directory)
76+
- Error handling for existing directories
77+
- Error handling for non-empty directories
78+
79+
###Manual Tests
80+
81+
Run manual tests that leave the results for inspection:
82+
83+
```bash
84+
./test-manual.sh
85+
```
86+
87+
This creates test projects in`test-manual/` for manual verification. Clean up with`rm -rf test-manual/` when done.
88+
6089
##Publishing
6190

6291
To publish this package to npm:

‎test-manual.sh‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Manual test script for create-net
4+
# This script runs the three main scenarios and leaves the results for manual inspection
5+
# Run this from the create-net project root directory
6+
7+
set -e# Exit on error
8+
9+
YELLOW='\033[1;33m'
10+
GREEN='\033[0;32m'
11+
NC='\033[0m'# No Color
12+
13+
TEST_DIR="test-manual"
14+
CREATE_NET_SCRIPT="$(pwd)/bin/create-net.js"
15+
16+
echo -e"${YELLOW}=== Manual Testing for create-net ===${NC}"
17+
echo -e"${YELLOW}Results will be saved in:$TEST_DIR${NC}\n"
18+
19+
# Clean up any previous test runs
20+
if [-d"$TEST_DIR" ];then
21+
echo"Cleaning up previous test directory..."
22+
rm -rf"$TEST_DIR"
23+
fi
24+
25+
mkdir -p"$TEST_DIR"
26+
cd"$TEST_DIR"
27+
28+
# Test 1: With repo name and ProjectName
29+
echo -e"\n${YELLOW}================================================${NC}"
30+
echo -e"${GREEN}Test 1: With repo name and ProjectName${NC}"
31+
echo -e"${YELLOW}Command: node$CREATE_NET_SCRIPT nextjs AcmeCorp${NC}"
32+
echo -e"${YELLOW}================================================${NC}\n"
33+
34+
node"$CREATE_NET_SCRIPT" nextjs AcmeCorp
35+
36+
echo -e"\n${GREEN}✓ Test 1 complete. Check$TEST_DIR/AcmeCorp${NC}"
37+
38+
# Test 2: With organization and repo name and ProjectName
39+
echo -e"\n${YELLOW}================================================${NC}"
40+
echo -e"${GREEN}Test 2: With org/repo and ProjectName${NC}"
41+
echo -e"${YELLOW}Command: node$CREATE_NET_SCRIPT NetCoreTemplates/vue-vite VueProject${NC}"
42+
echo -e"${YELLOW}================================================${NC}\n"
43+
44+
node"$CREATE_NET_SCRIPT" NetCoreTemplates/vue-vite VueProject
45+
46+
echo -e"\n${GREEN}✓ Test 2 complete. Check$TEST_DIR/VueProject${NC}"
47+
48+
# Test 3: Without ProjectName (extract to current directory)
49+
echo -e"\n${YELLOW}================================================${NC}"
50+
echo -e"${GREEN}Test 3: Without ProjectName (current directory)${NC}"
51+
echo -e"${YELLOW}Commands:${NC}"
52+
echo -e"${YELLOW} mkdir CurrentDirTest${NC}"
53+
echo -e"${YELLOW} cd CurrentDirTest${NC}"
54+
echo -e"${YELLOW} node$CREATE_NET_SCRIPT nextjs${NC}"
55+
echo -e"${YELLOW}================================================${NC}\n"
56+
57+
mkdir CurrentDirTest
58+
cd CurrentDirTest
59+
node"$CREATE_NET_SCRIPT" nextjs
60+
cd ..
61+
62+
echo -e"\n${GREEN}✓ Test 3 complete. Check$TEST_DIR/CurrentDirTest${NC}"
63+
64+
# Summary
65+
echo -e"\n${YELLOW}================================================${NC}"
66+
echo -e"${GREEN}All manual tests complete!${NC}"
67+
echo -e"${YELLOW}================================================${NC}"
68+
echo -e"\nTest results are in:${YELLOW}$TEST_DIR${NC}"
69+
echo -e"\nYou can inspect the following directories:"
70+
echo -e" 1.${YELLOW}$TEST_DIR/AcmeCorp${NC} - Created with repo name and ProjectName"
71+
echo -e" 2.${YELLOW}$TEST_DIR/VueProject${NC} - Created with org/repo and ProjectName"
72+
echo -e" 3.${YELLOW}$TEST_DIR/CurrentDirTest${NC} - Created without ProjectName\n"
73+
echo -e"Verify that:"
74+
echo -e" • Files contain project-specific names (AcmeCorp, VueProject, CurrentDirTest)"
75+
echo -e" • 'MyApp' variations have been replaced with project name variations"
76+
echo -e" • node_modules directories exist (npm install ran)\n"
77+
echo -e"To clean up:${YELLOW}rm -rf$TEST_DIR${NC}\n"

‎test.sh‎

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/bash
2+
3+
# Test script for create-net
4+
# Tests different scenarios for creating projects from templates
5+
6+
set -e# Exit on error
7+
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
NC='\033[0m'# No Color
12+
13+
TEST_DIR="test-projects"
14+
CREATE_NET_SCRIPT="$(pwd)/bin/create-net.js"
15+
16+
echo -e"${YELLOW}=== Testing create-net ===${NC}\n"
17+
18+
# Clean up any previous test runs
19+
if [-d"$TEST_DIR" ];then
20+
echo"Cleaning up previous test directory..."
21+
rm -rf"$TEST_DIR"
22+
fi
23+
24+
mkdir -p"$TEST_DIR"
25+
cd"$TEST_DIR"
26+
27+
# Track test results
28+
TESTS_PASSED=0
29+
TESTS_FAILED=0
30+
31+
# Helper function to check if a project was created successfully
32+
check_project() {
33+
local project_name=$1
34+
local project_path=$2
35+
36+
echo -e"\n${YELLOW}Verifying project:$project_name${NC}"
37+
38+
# Check if directory exists
39+
if [!-d"$project_path" ];then
40+
echo -e"${RED}✗ FAILED: Directory$project_path does not exist${NC}"
41+
((TESTS_FAILED++))
42+
return 1
43+
fi
44+
45+
# Check if files were extracted
46+
if [-z"$(ls -A$project_path)" ];then
47+
echo -e"${RED}✗ FAILED: Directory$project_path is empty${NC}"
48+
((TESTS_FAILED++))
49+
return 1
50+
fi
51+
52+
# Check if project name replacements were made
53+
# Look for any files containing the project name variations
54+
local found_replacement=false
55+
56+
# Check for lowercase version in files
57+
local lowercase_name=$(echo"$project_name"| tr'[:upper:]''[:lower:]')
58+
if grep -r"$lowercase_name""$project_path" --include="*.json" --include="*.md" --include="*.txt" --include="*.cs" --include="*.js" --include="*.ts">/dev/null2>&1;then
59+
found_replacement=true
60+
fi
61+
62+
if ["$found_replacement"=false ];then
63+
echo -e"${YELLOW}⚠ WARNING: Could not verify project name replacement (this may be normal if template doesn't have MyApp references)${NC}"
64+
fi
65+
66+
echo -e"${GREEN}✓ PASSED: Project$project_name created successfully${NC}"
67+
((TESTS_PASSED++))
68+
return 0
69+
}
70+
71+
# Test 1: Create project with repo name and ProjectName
72+
echo -e"\n${YELLOW}========================================${NC}"
73+
echo -e"${YELLOW}Test 1: With repo name and ProjectName${NC}"
74+
echo -e"${YELLOW}Command: node$CREATE_NET_SCRIPT nextjs AcmeCorp${NC}"
75+
echo -e"${YELLOW}========================================${NC}\n"
76+
77+
node"$CREATE_NET_SCRIPT" nextjs AcmeCorp
78+
check_project"AcmeCorp""AcmeCorp"
79+
80+
# Test 2: Create project with organization/repo name and ProjectName
81+
echo -e"\n${YELLOW}========================================${NC}"
82+
echo -e"${YELLOW}Test 2: With org/repo name and ProjectName${NC}"
83+
echo -e"${YELLOW}Command: node$CREATE_NET_SCRIPT NetCoreTemplates/vue-vite VueProject${NC}"
84+
echo -e"${YELLOW}========================================${NC}\n"
85+
86+
node"$CREATE_NET_SCRIPT" NetCoreTemplates/vue-vite VueProject
87+
check_project"VueProject""VueProject"
88+
89+
# Test 3: Create project without ProjectName (extract to current directory)
90+
echo -e"\n${YELLOW}========================================${NC}"
91+
echo -e"${YELLOW}Test 3: Without ProjectName (current directory)${NC}"
92+
echo -e"${YELLOW}Commands: mkdir CurrentDirTest && cd CurrentDirTest && node$CREATE_NET_SCRIPT nextjs${NC}"
93+
echo -e"${YELLOW}========================================${NC}\n"
94+
95+
mkdir CurrentDirTest
96+
cd CurrentDirTest
97+
node"$CREATE_NET_SCRIPT" nextjs
98+
check_project"CurrentDirTest""."
99+
cd ..
100+
101+
# Test 4: Error case - Directory already exists
102+
echo -e"\n${YELLOW}========================================${NC}"
103+
echo -e"${YELLOW}Test 4: Error handling - Directory exists${NC}"
104+
echo -e"${YELLOW}Command: node$CREATE_NET_SCRIPT nextjs AcmeCorp (should fail)${NC}"
105+
echo -e"${YELLOW}========================================${NC}\n"
106+
107+
if node"$CREATE_NET_SCRIPT" nextjs AcmeCorp2>&1| grep -q"already exists";then
108+
echo -e"${GREEN}✓ PASSED: Correctly detected existing directory${NC}"
109+
((TESTS_PASSED++))
110+
else
111+
echo -e"${RED}✗ FAILED: Should have detected existing directory${NC}"
112+
((TESTS_FAILED++))
113+
fi
114+
115+
# Test 5: Error case - Non-empty current directory
116+
echo -e"\n${YELLOW}========================================${NC}"
117+
echo -e"${YELLOW}Test 5: Error handling - Non-empty directory${NC}"
118+
echo -e"${YELLOW}Commands: mkdir NonEmptyTest && cd NonEmptyTest && touch file.txt && node$CREATE_NET_SCRIPT nextjs${NC}"
119+
echo -e"${YELLOW}========================================${NC}\n"
120+
121+
mkdir NonEmptyTest
122+
cd NonEmptyTest
123+
touch file.txt
124+
if node"$CREATE_NET_SCRIPT" nextjs2>&1| grep -q"not empty";then
125+
echo -e"${GREEN}✓ PASSED: Correctly detected non-empty directory${NC}"
126+
((TESTS_PASSED++))
127+
else
128+
echo -e"${RED}✗ FAILED: Should have detected non-empty directory${NC}"
129+
((TESTS_FAILED++))
130+
fi
131+
cd ..
132+
133+
# Summary
134+
echo -e"\n${YELLOW}========================================${NC}"
135+
echo -e"${YELLOW}Test Summary${NC}"
136+
echo -e"${YELLOW}========================================${NC}"
137+
echo -e"${GREEN}Passed:$TESTS_PASSED${NC}"
138+
echo -e"${RED}Failed:$TESTS_FAILED${NC}"
139+
140+
# Clean up
141+
cd ..
142+
echo -e"\n${YELLOW}Cleaning up test directory...${NC}"
143+
rm -rf"$TEST_DIR"
144+
145+
if [$TESTS_FAILED-eq 0 ];then
146+
echo -e"\n${GREEN}All tests passed! ✓${NC}\n"
147+
exit 0
148+
else
149+
echo -e"\n${RED}Some tests failed! ✗${NC}\n"
150+
exit 1
151+
fi

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp