-
Notifications
You must be signed in to change notification settings - Fork 0
310 lines (268 loc) · 8.94 KB
/
Copy pathruntime-compat.yml
File metadata and controls
310 lines (268 loc) · 8.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
name: Runtime Compatibility
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
deno:
name: Deno
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Run tests
run: deno task test
node:
name: Node.js
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [lts/*, 25]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
npm init -y
npm pkg set type=module
npm install vite rollup multiformats
npx jsr add @std/path
- name: Create test file
run: |
cat > test-node.ts << 'EOF'
import { generateCID } from './src/cid.ts';
import { cid } from './src/index.ts';
// Test CID generation
try {
const testCid = await generateCID('Hello, Node.js!');
if (!testCid || !testCid.startsWith('bafkrei')) {
throw new Error('CID generation failed');
}
console.log('✓ CID generation successful:', testCid);
} catch (err) {
console.error('✗ CID generation failed:', (err as Error).message);
process.exit(1);
}
// Test plugin creation
try {
const plugin = cid();
if (!plugin || typeof plugin.name !== 'string') {
throw new Error('Plugin creation failed');
}
console.log('✓ Plugin created successfully:', plugin.name);
} catch (err) {
console.error('✗ Plugin creation failed:', (err as Error).message);
process.exit(1);
}
EOF
- name: Run test
run: node --experimental-strip-types --experimental-transform-types test-node.ts
bun:
name: Bun
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: |
bun install vite rollup multiformats
bun x jsr add @std/path
- name: Create test file
run: |
cat > test-bun.ts << 'EOF'
import { generateCID } from './src/cid.ts';
import { cid } from './src/index.ts';
// Test CID generation
try {
const testCid = await generateCID('Hello, Bun!');
if (!testCid || !testCid.startsWith('bafkrei')) {
throw new Error('CID generation failed');
}
console.log('✓ CID generation successful:', testCid);
} catch (err) {
console.error('✗ CID generation failed:', (err as Error).message);
process.exit(1);
}
// Test plugin creation
try {
const plugin = cid();
if (!plugin || typeof plugin.name !== 'string') {
throw new Error('Plugin creation failed');
}
console.log('✓ Plugin created successfully:', plugin.name);
} catch (err) {
console.error('✗ Plugin creation failed:', (err as Error).message);
process.exit(1);
}
EOF
- name: Run test
run: bun run test-bun.ts
cloudflare:
name: Cloudflare Workers
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Wrangler
run: npm install -g wrangler
- name: Install dependencies
run: |
npm init -y
npm install multiformats
npx jsr add @std/path
- name: Create worker test
run: |
cat > wrangler.toml << 'EOF'
name = "vite-plugin-cid-test"
main = "worker.ts"
compatibility_date = "2024-11-30"
EOF
cat > worker.ts << 'EOF'
import { generateCID } from './src/cid.ts';
export default {
async fetch(request: Request, env: any, ctx: any) {
try {
const cid = await generateCID('Hello, Cloudflare Workers!');
if (!cid || !cid.startsWith('bafkrei')) {
throw new Error('CID generation failed');
}
return new Response('✓ CID generation successful: ' + cid, { status: 200 });
} catch (err) {
return new Response('✗ Error: ' + (err as Error).message, { status: 500 });
}
}
};
EOF
- name: Test worker locally
run: |
timeout 20s wrangler dev --local --test-scheduled &
sleep 10
response=$(curl -s http://localhost:8787 || echo "✗ Failed to connect")
echo "$response"
if [[ "$response" == *"✓"* ]]; then
echo "Worker test passed"
exit 0
else
echo "Worker test failed"
exit 1
fi
browser:
name: Browser
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Playwright
run: |
npm install -D playwright @playwright/test
npx playwright install chromium firefox webkit
- name: Install dependencies
run: |
npm install vite rollup multiformats
npx jsr add @std/path
- name: Create browser test
run: |
mkdir -p test-browser
cat > test-browser/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head><title>Browser Test</title></head>
<body>
<div id="result">Testing...</div>
<script type="module" src="/main.ts"></script>
</body>
</html>
EOF
cat > test-browser/main.ts << 'EOF'
import { generateCID } from '@fusionstrings/vite-plugin-cid/cid';
async function test() {
try {
const cid = await generateCID('Hello, Browser!');
if (!cid || !cid.startsWith('bafkrei')) {
throw new Error('CID generation failed');
}
document.getElementById('result').textContent = '✓ CID generation successful: ' + cid;
(window as any).testPassed = true;
} catch (err) {
document.getElementById('result').textContent = '✗ Error: ' + (err as Error).message;
(window as any).testPassed = false;
}
}
test();
EOF
cat > test-browser/vite.config.ts << 'EOF'
import { defineConfig } from 'vite';
export default defineConfig({
root: '.',
server: { port: 3000 },
resolve: {
alias: {
'@std/path': 'https://esm.sh/@std/path@1.0.8',
'@fusionstrings/vite-plugin-cid/cid': '../src/cid.ts',
'@fusionstrings/vite-plugin-cid': '../src/index.ts'
}
}
});
EOF
cat > playwright.config.js << 'EOF'
export default {
testDir: './tests',
timeout: 30000,
use: {
baseURL: 'http://localhost:3000',
},
webServer: {
command: 'npx vite test-browser --port 3000',
port: 3000,
reuseExistingServer: false,
},
};
EOF
mkdir -p tests
cat > tests/browser.spec.js << 'EOF'
import { test, expect } from '@playwright/test';
test('CID generation in browser', async ({ page }) => {
await page.goto('/');
await page.waitForFunction(() => window.testPassed !== undefined, { timeout: 10000 });
const passed = await page.evaluate(() => window.testPassed);
expect(passed).toBe(true);
const result = await page.textContent('#result');
expect(result).toContain('✓');
});
EOF
- name: Run browser tests
run: npx playwright test
summary:
name: Runtime Compatibility Summary
needs: [deno, node, bun, cloudflare, browser]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check results
run: |
echo "## Runtime Compatibility Test Results"
echo "- Deno: ${{ needs.deno.result }}"
echo "- Node.js: ${{ needs.node.result }}"
echo "- Bun: ${{ needs.bun.result }}"
echo "- Cloudflare Workers: ${{ needs.cloudflare.result }}"
echo "- Browser: ${{ needs.browser.result }}"