Skip to content

Commit 11bb702

Browse files
committed
test improvements
1 parent 1578b1f commit 11bb702

File tree

6 files changed

+134
-31
lines changed

6 files changed

+134
-31
lines changed

.github/workflows/ci.yml

Lines changed: 107 additions & 3 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,23 +24,128 @@ 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: |
107+
dist/widget.*
108+
dist/style.css
109+
retention-days: 1
110+
111+
test-widget:
112+
runs-on: ubuntu-latest
113+
needs: build-widget
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- name: Setup Node.js
118+
uses: actions/setup-node@v4
119+
with:
120+
node-version: '18'
121+
cache: 'npm'
122+
123+
- name: Install dependencies
124+
run: npm ci
125+
126+
- name: Download widget build
127+
uses: actions/download-artifact@v4
128+
with:
129+
name: widget-build
130+
path: dist/
131+
132+
- name: Verify downloaded files
133+
run: |
134+
echo "Contents of dist directory:"
135+
ls -la dist/
136+
echo "Checking for required files..."
137+
test -f dist/widget.umd.js || (echo "widget.umd.js not found!" && exit 1)
138+
test -f dist/style.css || (echo "style.css not found!" && exit 1)
139+
echo "Contents of root directory:"
140+
ls -la
141+
echo "Checking test-widget-embed.html exists:"
142+
test -f test-widget-embed.html && echo "test-widget-embed.html found" || echo "test-widget-embed.html NOT found"
143+
40144
- name: Install Playwright
41145
run: npx playwright install chromium
42146

43147
- name: Run widget tests
44-
run: npm run test:ci
148+
run: npm run test:ci:only
45149

46150
- name: Upload test results
47151
if: always()

.github/workflows/publish.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,7 @@ jobs:
5555
- name: Build widget
5656
run: npm run build:widget
5757

58-
- name: Install Playwright
59-
run: npx playwright install chromium
60-
61-
- name: Run widget tests
62-
run: npm run test:ci
63-
6458
- name: Publish to npm
6559
run: npm publish
6660
env:
6761
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
68-
69-
- name: Upload test results
70-
if: always()
71-
uses: actions/upload-artifact@v4
72-
with:
73-
name: playwright-report
74-
path: playwright-report/
75-
retention-days: 30

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
"test": "npm run test:widget",
4141
"test:widget": "npm run build:widget && playwright test",
4242
"test:widget:ui": "npm run build:widget && playwright test --ui",
43-
"test:serve": "serve -s . -p 3000",
44-
"test:ci": "npm run build:widget && playwright test --reporter=list"
43+
"test:serve": "serve -l 4200 .",
44+
"test:ci": "npm run build:widget && playwright test --reporter=list",
45+
"test:ci:only": "playwright test --reporter=list"
4546
},
4647
"author": {
4748
"name": "Vapi AI",

playwright.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export default defineConfig({
1010
forbidOnly: !!process.env.CI,
1111
retries: process.env.CI ? 2 : 0,
1212
workers: process.env.CI ? 1 : undefined,
13-
reporter: 'html',
13+
reporter: process.env.CI ? 'list' : 'html',
1414
use: {
15-
baseURL: 'http://localhost:3000',
15+
baseURL: 'http://localhost:4200',
1616
trace: 'on-first-retry',
1717
},
1818
projects: [
@@ -22,8 +22,11 @@ export default defineConfig({
2222
},
2323
],
2424
webServer: {
25-
command: 'npm run test:serve',
26-
port: 3000,
25+
command: 'npx serve -l 4200 .',
26+
port: 4200,
27+
timeout: 60 * 1000, // 1 minute timeout
2728
reuseExistingServer: !process.env.CI,
29+
stdout: process.env.CI ? 'pipe' : 'ignore',
30+
stderr: 'pipe',
2831
},
2932
});

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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ test.describe('VapiWidget Embed Tests', () => {
1010
test('should load widget from script tag with data attributes', async ({
1111
page,
1212
}) => {
13-
// Navigate to the test page
14-
await page.goto('/test-widget-embed.html');
13+
await page.goto('/test-widget-embed');
1514

1615
// Wait for the widget script to load
1716
await page.waitForFunction(
@@ -30,7 +29,7 @@ test.describe('VapiWidget Embed Tests', () => {
3029
return element && (element.shadowRoot || element.children.length > 0);
3130
},
3231
'#vapi-widget-1',
33-
{ timeout: 5000 }
32+
{ timeout: 3000 }
3433
);
3534

3635
// Verify the widget has created some content (React root or shadow DOM)
@@ -50,7 +49,7 @@ test.describe('VapiWidget Embed Tests', () => {
5049
test('should load widget from script tag with data-props JSON', async ({
5150
page,
5251
}) => {
53-
await page.goto('/test-widget-embed.html');
52+
await page.goto('/test-widget-embed');
5453

5554
// Wait for the widget script to load
5655
await page.waitForFunction(
@@ -69,7 +68,7 @@ test.describe('VapiWidget Embed Tests', () => {
6968
return element && (element.shadowRoot || element.children.length > 0);
7069
},
7170
'#vapi-widget-2',
72-
{ timeout: 5000 }
71+
{ timeout: 3000 }
7372
);
7473

7574
// Verify the widget has been initialized
@@ -86,9 +85,15 @@ test.describe('VapiWidget Embed Tests', () => {
8685
});
8786

8887
test('should expose WidgetLoader globally', async ({ page }) => {
89-
await page.goto('/test-widget-embed.html');
88+
await page.goto('/test-widget-embed');
89+
90+
// Wait for WidgetLoader to be available
91+
await page.waitForFunction(
92+
() => typeof (window as any).WidgetLoader === 'function',
93+
{ timeout: 5000 }
94+
);
9095

91-
// Check if WidgetLoader is available globally
96+
// Verify WidgetLoader is a function
9297
const hasWidgetLoader = await page.evaluate(() => {
9398
return typeof (window as any).WidgetLoader === 'function';
9499
});

0 commit comments

Comments
 (0)