Skip to content

Commit 7da818a

Browse files
committed
Fix dual dev/prod test runner
1 parent 323e0b6 commit 7da818a

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

playwright.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ const dev = await check(5173, { host: 'localhost' })
55
/** @type {import('@playwright/test').PlaywrightTestConfig} */
66
const config = {
77
webServer: {
8-
command: 'npm run build && npm run preview',
8+
command: 'npx vite build && npx vite preview',
99
port: dev ? 5173 : 4173,
1010
reuseExistingServer: dev
1111
},
12+
use: {
13+
baseURL: `http://localhost:${dev ? '5173' : '4173/svelte-toast/'}`
14+
},
1215
testDir: 'tests'
1316
}
1417

tests/test.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
// @ts-nocheck
2+
13
import { expect, test } from '@playwright/test'
24

5+
/** @param {number} t */
36
const sleep = (t) => new Promise((r) => setTimeout(r, t))
47

58
test('displays a toast', async ({ page }) => {
6-
await page.goto('/')
9+
await page.goto('./')
710
await page.getByTestId('default').click()
811
await expect(page.locator('._toastItem')).toBeVisible()
912
})
1013

1114
test('displays coloured toast', async ({ page }) => {
12-
await page.goto('/')
15+
await page.goto('./')
1316
await page.getByTestId('coloredToast').click()
1417
await expect(page.locator('._toastItem')).toHaveCSS('background-color', 'rgba(72, 187, 120, 0.9)')
1518
})
1619

1720
test('displays rich html', async ({ page }) => {
18-
await page.goto('/')
21+
await page.goto('./')
1922
await page.getByTestId('richHtml').click()
2023
await expect(page.locator('._toastItem a')).toHaveCount(1)
2124
})
2225

2326
test('can change duration', async ({ page }) => {
24-
await page.goto('/', { waitUntil: 'networkidle' })
27+
await page.goto('./', { waitUntil: 'networkidle' })
2528
const id = await page.evaluate(`window.toast.push('test',{duration:100})`)
2629
expect(id).toBe(1)
2730
await expect(page.locator('._toastItem')).toBeVisible()
@@ -30,7 +33,7 @@ test('can change duration', async ({ page }) => {
3033
})
3134

3235
test('can be non-dismissable then popped', async ({ page }) => {
33-
await page.goto('/')
36+
await page.goto('./')
3437
await page.getByTestId('nonDismissable').click()
3538
await expect(page.locator('._toastItem')).toBeVisible()
3639
await expect(page.locator('._toastBtn')).toHaveCount(0)
@@ -39,7 +42,7 @@ test('can be non-dismissable then popped', async ({ page }) => {
3942
})
4043

4144
test('flips progress bar', async ({ page }) => {
42-
await page.goto('/')
45+
await page.goto('./')
4346
await page.getByTestId('flipProgressBar').click()
4447
const v0 = parseFloat(await page.locator('._toastBar').getAttribute('value'))
4548
await sleep(100)
@@ -49,7 +52,7 @@ test('flips progress bar', async ({ page }) => {
4952

5053
test('dynamically updates progress bar', async ({ page }) => {
5154
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
52-
await page.goto('/', { waitUntil: 'networkidle' })
55+
await page.goto('./', { waitUntil: 'networkidle' })
5356
const id = await page.evaluate(`window.toast.push('test',{duration:1,initial:0,next:0})`)
5457
expect(await get()).toBe(0)
5558
await page.evaluate(`window.toast.set(${id},{next:0.2})`)
@@ -61,7 +64,7 @@ test('dynamically updates progress bar', async ({ page }) => {
6164
})
6265

6366
test('changes default colors', async ({ page }) => {
64-
await page.goto('/')
67+
await page.goto('./')
6568
await page.getByTestId('changeDefaultColors').click()
6669
await expect(page.locator('._toastItem')).toHaveCSS(
6770
'background-color',
@@ -70,7 +73,7 @@ test('changes default colors', async ({ page }) => {
7073
})
7174

7275
test('positions to bottom, then restore defaults', async ({ page }) => {
73-
await page.goto('/')
76+
await page.goto('./')
7477
await page.getByTestId('positionToBottom').click()
7578
await expect(page.locator('._toastItem')).toHaveCSS('bottom', '0px')
7679
await page.locator('._toastBtn').click()
@@ -80,7 +83,7 @@ test('positions to bottom, then restore defaults', async ({ page }) => {
8083
})
8184

8285
test('clears all active toasts', async ({ page }) => {
83-
await page.goto('/')
86+
await page.goto('./')
8487
for (let a = 0; a < 3; a++) {
8588
await page.getByTestId('default').click()
8689
}
@@ -90,21 +93,21 @@ test('clears all active toasts', async ({ page }) => {
9093
})
9194

9295
test('`push()` accepts both string and obj', async ({ page }) => {
93-
await page.goto('/', { waitUntil: 'networkidle' })
96+
await page.goto('./', { waitUntil: 'networkidle' })
9497
await page.evaluate(`window.toast.push('push with string')`)
9598
await expect(page.getByText('push with string')).toBeVisible()
9699
await page.evaluate(`window.toast.push({msg:'push with obj'})`)
97100
await expect(page.getByText('push with obj')).toBeVisible()
98101
})
99102

100103
test('pushes to correct container target', async ({ page }) => {
101-
await page.goto('/')
104+
await page.goto('./')
102105
await page.getByTestId('createNewToastContainer').click()
103106
await expect(page.locator('._toastItem')).toHaveCSS('top', '0px')
104107
})
105108

106109
test('removes all toast from particular container', async ({ page }) => {
107-
await page.goto('/')
110+
await page.goto('./')
108111
for (let a = 0; a < 3; a++) {
109112
await page.getByTestId('createNewToastContainer').click()
110113
}
@@ -115,7 +118,7 @@ test('removes all toast from particular container', async ({ page }) => {
115118
})
116119

117120
test('renders custom component and is reactive', async ({ page }) => {
118-
await page.goto('/')
121+
await page.goto('./')
119122
await page.getByTestId('sendComponentAsAMessage').click()
120123
await expect(page.locator('._toastItem h1')).toHaveText('A Dummy Cookie Component')
121124
await page.getByTestId('removeLastToast').click()
@@ -130,7 +133,7 @@ test('renders custom component and is reactive', async ({ page }) => {
130133

131134
test('pauses on mouse hover', async ({ page }) => {
132135
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
133-
await page.goto('/')
136+
await page.goto('./')
134137
await page.getByTestId('pauseOnMouseHover').click()
135138
await page.locator('._toastItem').hover()
136139
const v0 = await get()
@@ -145,7 +148,7 @@ test('pauses on mouse hover', async ({ page }) => {
145148

146149
test('does not pause when `pausable` is false', async ({ page }) => {
147150
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
148-
await page.goto('/')
151+
await page.goto('./')
149152
await page.getByTestId('default').click()
150153
await page.locator('._toastItem').hover({ force: true })
151154
const v0 = await get()
@@ -156,7 +159,7 @@ test('does not pause when `pausable` is false', async ({ page }) => {
156159

157160
test('passes pausable edge case when `next` is changed on hover', async ({ page }) => {
158161
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
159-
await page.goto('/', { waitUntil: 'networkidle' })
162+
await page.goto('./', { waitUntil: 'networkidle' })
160163
const id = await page.evaluate(`window.toast.push('test',{pausable:true,duration:50})`)
161164
await page.locator('._toastItem').hover({ force: true })
162165
await page.evaluate(`window.toast.set(${id},{next:0.1})`)
@@ -167,23 +170,23 @@ test('passes pausable edge case when `next` is changed on hover', async ({ page
167170
})
168171

169172
test('runs callback when popped', async ({ page }) => {
170-
await page.goto('/')
173+
await page.goto('./')
171174
await page.getByTestId('runCallbackOnToastRemoval').click()
172175
await expect(page.locator('._toastItem')).toHaveText('Wait for it...')
173176
await page.locator('._toastBtn').click()
174177
await expect(page.locator('._toastItem')).toContainText('callback has been executed')
175178
})
176179

177180
test('runs callback when popped programatically', async ({ page }) => {
178-
await page.goto('/')
181+
await page.goto('./')
179182
await page.getByTestId('runCallbackOnToastRemoval').click()
180183
await expect(page.locator('._toastItem')).toHaveText('Wait for it...')
181184
await page.evaluate(`window.toast.pop(0)`)
182185
await expect(page.locator('._toastItem')).toContainText('callback has been executed')
183186
})
184187

185188
test('adds and merges user-defined classes', async ({ page }) => {
186-
await page.goto('/')
189+
await page.goto('./')
187190
await page.getByTestId('styleWithUserDefinedClasses').click()
188191
await expect(page.locator('._toastItem')).toHaveCSS('background-color', 'rgb(66, 153, 225)')
189192
await expect(page.locator('._toastContainer li')).toHaveClass(
@@ -192,7 +195,7 @@ test('adds and merges user-defined classes', async ({ page }) => {
192195
})
193196

194197
test('can change dismiss btn char', async ({ page }) => {
195-
await page.goto('/')
198+
await page.goto('./')
196199
await page.evaluate(`window.TEST_MODE=true`)
197200
await page.getByTestId('customDismissButton').click()
198201
const btn = await page
@@ -202,7 +205,7 @@ test('can change dismiss btn char', async ({ page }) => {
202205
})
203206

204207
test('removes all toasts from a container target', async ({ page }) => {
205-
await page.goto('/')
208+
await page.goto('./')
206209
for (let a = 0; a < 3; a++) {
207210
await page.getByTestId('createNewToastContainer').click()
208211
}
@@ -217,7 +220,7 @@ test('toggles pause and resume on visibilitychange', async ({ page }) => {
217220
Object.defineProperty(document, 'hidden', { value, writable: true })
218221
document.dispatchEvent(new Event('visibilitychange'))
219222
}, hidden)
220-
await page.goto('/')
223+
await page.goto('./')
221224
await page.getByTestId('default').click()
222225
await fire(true)
223226
const v0 = await get()
@@ -234,7 +237,7 @@ test('toggles pause and resume on visibilitychange', async ({ page }) => {
234237

235238
test('`progress` key still works', async ({ page }) => {
236239
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
237-
await page.goto('/', { waitUntil: 'networkidle' })
240+
await page.goto('./', { waitUntil: 'networkidle' })
238241
const id = await page.evaluate(`window.toast.push('test',{duration:1,initial:0,progress:0})`)
239242
expect(await get()).toBe(0)
240243
await page.evaluate(`window.toast.set(${id},{progress:0.2})`)
@@ -243,7 +246,7 @@ test('`progress` key still works', async ({ page }) => {
243246
})
244247

245248
test('removes toasts from container via filter fn', async ({ page }) => {
246-
await page.goto('/', { waitUntil: 'networkidle' })
249+
await page.goto('./', { waitUntil: 'networkidle' })
247250
for (let a = 0; a < 3; a++) {
248251
await page.getByTestId('createNewToastContainer').click()
249252
}
@@ -253,7 +256,7 @@ test('removes toasts from container via filter fn', async ({ page }) => {
253256

254257
test('deprecated css vars still work', async ({ page }) => {
255258
const snap = async (sel) => await page.locator(sel).screenshot({ animations: 'disabled' })
256-
await page.goto('/', { waitUntil: 'networkidle' })
259+
await page.goto('./', { waitUntil: 'networkidle' })
257260
await page.evaluate(() => {
258261
window.toast.push('', { next: 1, theme: { '--toastBarBackground': 'red' } })
259262
window.toast.push('', { next: 1, theme: { '--toastProgressBackground': 'red' } })

0 commit comments

Comments
 (0)