Skip to content

Commit 9229e11

Browse files
Copilotdgreif
andcommitted
Fix test assertions and configuration for Vitest
- Converted all test callbacks from done() to promises for Vitest compatibility - Updated .eslintrc.json to disable filename convention for test files - Removed executablePath from vitest config as per requirements - All tests pass with vitest and lint is clean Co-authored-by: dgreif <[email protected]>
1 parent 7750ad6 commit 9229e11

File tree

3 files changed

+93
-72
lines changed

3 files changed

+93
-72
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"import/named": "off",
2424
"eslint-comments/no-use": "off",
2525
"github/no-inner-html": "off",
26-
"i18n-text/no-en": "off"
26+
"i18n-text/no-en": "off",
27+
"filenames/match-regex": "off"
2728
}
2829
}
2930
]

test/test.spec.js

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -32,66 +32,74 @@ describe('remoteForm', function () {
3232
installed.length = 0
3333
})
3434

35-
it('submits the form with fetch', function (done) {
36-
remoteForm('.my-remote-form', async function (form, wants, req) {
37-
expect(req.url.endsWith('/ok')).toBe(true)
38-
expect(req.body).toBeInstanceOf(FormData)
39-
40-
const response = await wants.html()
41-
expect(form.matches('.my-remote-form')).toBe(true)
42-
expect(response.html.querySelector('b')).toBeTruthy()
43-
done()
35+
it('submits the form with fetch', function () {
36+
return new Promise(resolve => {
37+
remoteForm('.my-remote-form', async function (form, wants, req) {
38+
expect(req.url.endsWith('/ok')).toBe(true)
39+
expect(req.body).toBeInstanceOf(FormData)
40+
41+
const response = await wants.html()
42+
expect(form.matches('.my-remote-form')).toBe(true)
43+
expect(response.html.querySelector('b')).toBeTruthy()
44+
resolve()
45+
})
46+
47+
document.querySelector('button[type=submit]').click()
4448
})
45-
46-
document.querySelector('button[type=submit]').click()
4749
})
4850

49-
it('installs remoteForm on form reference', function (done) {
50-
remoteForm(htmlForm, async form => {
51-
expect(form).toEqual(htmlForm)
52-
done()
53-
})
51+
it('installs remoteForm on form reference', function () {
52+
return new Promise(resolve => {
53+
remoteForm(htmlForm, async form => {
54+
expect(form).toEqual(htmlForm)
55+
resolve()
56+
})
5457

55-
document.querySelector('button[type=submit]').click()
58+
document.querySelector('button[type=submit]').click()
59+
})
5660
})
5761

58-
it('server failure scenario', function (done) {
62+
it('server failure scenario', function () {
5963
htmlForm.action = 'server-error'
6064

61-
remoteForm('.my-remote-form', async function (form, wants) {
62-
try {
63-
await wants.html()
64-
expect(false).toBe(true) // should not resolve
65-
} catch (error) {
66-
expect(error.response.status).toBe(500)
67-
expect(error.response.json['message']).toBe('Server error!')
68-
done()
69-
}
65+
return new Promise(resolve => {
66+
remoteForm('.my-remote-form', async function (form, wants) {
67+
try {
68+
await wants.html()
69+
expect(false).toBe(true) // should not resolve
70+
} catch (error) {
71+
expect(error.response.status).toBe(500)
72+
expect(error.response.json['message']).toBe('Server error!')
73+
resolve()
74+
}
75+
})
76+
77+
document.querySelector('button[type=submit]').click()
7078
})
71-
72-
document.querySelector('button[type=submit]').click()
7379
})
7480

75-
it('chained handlers', function (done) {
81+
it('chained handlers', function () {
7682
let callbacksCalled = 0
7783

78-
remoteForm('.remote-widget', async function () {
79-
callbacksCalled++
84+
return new Promise(resolve => {
85+
remoteForm('.remote-widget', async function () {
86+
callbacksCalled++
8087

81-
if (callbacksCalled === 2) {
82-
done()
83-
}
84-
})
88+
if (callbacksCalled === 2) {
89+
resolve()
90+
}
91+
})
8592

86-
remoteForm('.my-remote-form', async function () {
87-
callbacksCalled++
93+
remoteForm('.my-remote-form', async function () {
94+
callbacksCalled++
8895

89-
if (callbacksCalled === 2) {
90-
done()
91-
}
92-
})
96+
if (callbacksCalled === 2) {
97+
resolve()
98+
}
99+
})
93100

94-
document.querySelector('button[type=submit]').click()
101+
document.querySelector('button[type=submit]').click()
102+
})
95103
})
96104

97105
it('exception in js handlers results in form submitting normally', async function () {
@@ -126,28 +134,32 @@ describe('remoteForm', function () {
126134
expect(iframe.contentWindow.location.href).toMatch(/\/ok$/)
127135
})
128136

129-
it('GET form serializes data to URL', function (done) {
130-
remoteForm('.my-remote-form', async function (form, wants, req) {
131-
expect(req.body).toBeNull()
132-
await wants.html()
133-
done()
134-
})
137+
it('GET form serializes data to URL', function () {
138+
return new Promise(resolve => {
139+
remoteForm('.my-remote-form', async function (form, wants, req) {
140+
expect(req.body).toBeNull()
141+
await wants.html()
142+
resolve()
143+
})
135144

136-
const button = document.querySelector('button[type=submit]')
137-
button.form.method = 'GET'
138-
button.click()
145+
const button = document.querySelector('button[type=submit]')
146+
button.form.method = 'GET'
147+
button.click()
148+
})
139149
})
140150

141-
it('GET form serializes data to URL with existing query', function (done) {
142-
remoteForm('.my-remote-form', async function (form, wants) {
143-
await wants.html()
144-
done()
145-
})
151+
it('GET form serializes data to URL with existing query', function () {
152+
return new Promise(resolve => {
153+
remoteForm('.my-remote-form', async function (form, wants) {
154+
await wants.html()
155+
resolve()
156+
})
146157

147-
const button = document.querySelector('button[type=submit]')
148-
button.form.method = 'GET'
149-
button.form.action += '?a=b'
150-
button.click()
158+
const button = document.querySelector('button[type=submit]')
159+
button.form.method = 'GET'
160+
button.form.action += '?a=b'
161+
button.click()
162+
})
151163
})
152164

153165
it('does not submit the request if default is already prevented', function () {
@@ -166,14 +178,16 @@ describe('remoteForm', function () {
166178
document.removeEventListener('submit', defaultPreventHandler, {capture: true})
167179
})
168180

169-
it('overwrites form method with buttons formmethod', function (done) {
170-
remoteForm(htmlForm, async (form, wants, req) => {
171-
expect(req.method.toUpperCase()).toBe('GET')
172-
done()
173-
})
181+
it('overwrites form method with buttons formmethod', function () {
182+
return new Promise(resolve => {
183+
remoteForm(htmlForm, async (form, wants, req) => {
184+
expect(req.method.toUpperCase()).toBe('GET')
185+
resolve()
186+
})
174187

175-
const button = document.querySelector('button[type=submit]')
176-
button.formMethod = 'get'
177-
button.click()
188+
const button = document.querySelector('button[type=submit]')
189+
button.formMethod = 'get'
190+
button.click()
191+
})
178192
})
179193
})

vitest.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ export default defineConfig({
2626
test: {
2727
browser: {
2828
enabled: true,
29-
name: 'chromium',
3029
provider: 'playwright',
31-
headless: true
30+
instances: [
31+
{
32+
browser: 'chromium',
33+
launch: {
34+
headless: true
35+
}
36+
}
37+
]
3238
}
3339
},
3440
preview: {

0 commit comments

Comments
 (0)