Skip to content

Commit 487ff45

Browse files
committed
added some configs to debug test
1 parent 1578b1f commit 487ff45

File tree

6 files changed

+183
-5
lines changed

6 files changed

+183
-5
lines changed

.github/workflows/ci.yml

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ on:
77
branches: [main]
88

99
jobs:
10-
test:
10+
lint:
1111
runs-on: ubuntu-latest
12-
1312
steps:
1413
- uses: actions/checkout@v4
1514

@@ -25,18 +24,109 @@ jobs:
2524
- name: Run linting
2625
run: npm run lint
2726

27+
type-check:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '18'
36+
cache: 'npm'
37+
38+
- name: Install dependencies
39+
run: npm ci
40+
2841
- name: Run type checking
2942
run: npm run type-check
3043

44+
format-check:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Setup Node.js
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: '18'
53+
cache: 'npm'
54+
55+
- name: Install dependencies
56+
run: npm ci
57+
3158
- name: Check formatting
3259
run: npm run format:check
3360

61+
build-library:
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Setup Node.js
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version: '18'
70+
cache: 'npm'
71+
72+
- name: Install dependencies
73+
run: npm ci
74+
3475
- name: Build library
3576
run: npm run build
3677

78+
- name: Upload library build
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: library-build
82+
path: dist/
83+
retention-days: 1
84+
85+
build-widget:
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Setup Node.js
91+
uses: actions/setup-node@v4
92+
with:
93+
node-version: '18'
94+
cache: 'npm'
95+
96+
- name: Install dependencies
97+
run: npm ci
98+
3799
- name: Build widget
38100
run: npm run build:widget
39101

102+
- name: Upload widget build
103+
uses: actions/upload-artifact@v4
104+
with:
105+
name: widget-build
106+
path: dist/widget.*
107+
retention-days: 1
108+
109+
test-widget:
110+
runs-on: ubuntu-latest
111+
needs: build-widget
112+
steps:
113+
- uses: actions/checkout@v4
114+
115+
- name: Setup Node.js
116+
uses: actions/setup-node@v4
117+
with:
118+
node-version: '18'
119+
cache: 'npm'
120+
121+
- name: Install dependencies
122+
run: npm ci
123+
124+
- name: Download widget build
125+
uses: actions/download-artifact@v4
126+
with:
127+
name: widget-build
128+
path: dist/
129+
40130
- name: Install Playwright
41131
run: npx playwright install chromium
42132

.github/workflows/debug-tests.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Debug Widget Tests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
paths:
8+
- 'tests/**'
9+
- 'src/widget/**'
10+
- 'playwright.config.ts'
11+
- '.github/workflows/debug-tests.yml'
12+
13+
jobs:
14+
debug:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '18'
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Build widget
30+
run: npm run build:widget
31+
32+
- name: List built files
33+
run: |
34+
echo "=== Contents of dist directory ==="
35+
ls -la dist/
36+
echo "=== Size of widget.umd.js ==="
37+
wc -c dist/widget.umd.js
38+
39+
- name: Test serve command
40+
run: |
41+
echo "=== Testing serve command ==="
42+
npx serve --version
43+
npx serve -s . -p 3000 &
44+
SERVER_PID=$!
45+
echo "Server started with PID: $SERVER_PID"
46+
sleep 5
47+
48+
echo "=== Testing server responses ==="
49+
curl -I http://localhost:3000/test-widget-embed.html || echo "Failed to access HTML"
50+
curl -I http://localhost:3000/dist/widget.umd.js || echo "Failed to access JS"
51+
curl -I http://localhost:3000/dist/style.css || echo "Failed to access CSS"
52+
53+
kill $SERVER_PID
54+
55+
- name: Run single test with debug
56+
run: |
57+
echo "=== Running test with debug output ==="
58+
DEBUG=pw:api npx playwright test tests/widget-embed.spec.ts:9:3 --reporter=list || true
59+
60+
- name: Check widget content
61+
run: |
62+
echo "=== First 50 lines of widget.umd.js ==="
63+
head -n 50 dist/widget.umd.js
64+
echo "=== Last 50 lines of widget.umd.js ==="
65+
tail -n 50 dist/widget.umd.js
66+
echo "=== Searching for WidgetLoader in widget.umd.js ==="
67+
grep -n "WidgetLoader" dist/widget.umd.js | head -20 || echo "WidgetLoader not found"
68+
69+
- name: Upload test results
70+
if: always()
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: debug-results
74+
path: |
75+
test-results/
76+
playwright-report/
77+
retention-days: 7

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig({
2424
webServer: {
2525
command: 'npm run test:serve',
2626
port: 3000,
27+
timeout: 60 * 1000,
2728
reuseExistingServer: !process.env.CI,
2829
},
2930
});

src/widget/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function initializeWidgets() {
171171
});
172172
}
173173

174+
// Initialize widgets when DOM is ready
174175
if (document.readyState === 'loading') {
175176
document.addEventListener('DOMContentLoaded', initializeWidgets);
176177
} else {
@@ -183,6 +184,9 @@ declare global {
183184
}
184185
}
185186

186-
window.WidgetLoader = WidgetLoader;
187+
// Ensure WidgetLoader is exposed globally for UMD builds
188+
if (typeof window !== 'undefined') {
189+
(window as any).WidgetLoader = WidgetLoader;
190+
}
187191

188192
export default WidgetLoader;

tests/widget-embed.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test.describe('VapiWidget Embed Tests', () => {
1616
// Wait for the widget script to load
1717
await page.waitForFunction(
1818
() => (window as any).WidgetLoader !== undefined,
19-
{ timeout: 5000 }
19+
{ timeout: 10000 }
2020
);
2121

2222
// Check if widget container exists
@@ -55,7 +55,7 @@ test.describe('VapiWidget Embed Tests', () => {
5555
// Wait for the widget script to load
5656
await page.waitForFunction(
5757
() => (window as any).WidgetLoader !== undefined,
58-
{ timeout: 5000 }
58+
{ timeout: 10000 }
5959
);
6060

6161
// Check if widget container exists
@@ -88,6 +88,9 @@ test.describe('VapiWidget Embed Tests', () => {
8888
test('should expose WidgetLoader globally', async ({ page }) => {
8989
await page.goto('/test-widget-embed.html');
9090

91+
// Wait a bit for script to load
92+
await page.waitForTimeout(1000);
93+
9194
// Check if WidgetLoader is available globally
9295
const hasWidgetLoader = await page.evaluate(() => {
9396
return typeof (window as any).WidgetLoader === 'function';

vite.widget.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default defineConfig({
2525
external: [],
2626
output: {
2727
globals: {},
28+
name: 'WidgetLoader',
29+
footer:
30+
'if(typeof window !== "undefined" && typeof WidgetLoader !== "undefined") { window.WidgetLoader = WidgetLoader; }',
2831
},
2932
},
3033
// Ensure all CSS is bundled into a single file for embedding

0 commit comments

Comments
 (0)