Skip to content

Commit 7679e6f

Browse files
committed
test: add --exit flag to test:functional so mocha exits on Ubuntu
On Ubuntu CI, mocha completes the suite (142 passing) but never exits, hanging build-and-check until GitHub cancels the job. The lingering handle doesn't reproduce on macOS/Windows or darwin locally, and process._getActiveHandles() reports nothing once tests finish. Adding --exit force-terminates the runner after the suite completes, which is safe because mocha already reported success. Also makes the serialize-uploads preview test deterministic by gating the stubbed upload on a test-controlled resolver rather than asserting upload counts against real chokidar fs events.
1 parent 12a176c commit 7679e6f

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"link:bin": "bash ./scripts/link_dev.sh",
5353
"lint": "eslint . --ext .ts --config .eslintrc",
5454
"test": "nyc --extension .ts mocha --config=.mocharc.json --forbid-only 'packages/**/src/**/*.test.ts'",
55-
"test:functional": "mocha --config=.mocharc.json -r ts-node/register 'packages/**/tests/**/*.test.ts'",
55+
"test:functional": "mocha --config=.mocharc.json --exit -r ts-node/register 'packages/**/tests/**/*.test.ts'",
5656
"changelog": "lerna-changelog",
5757
"type:check": "lerna run type:check"
5858
},

packages/zcli-themes/tests/functional/preview.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,35 @@ describe('themes:preview', function () {
134134
preview
135135
.it('should serialize rapid successive changes instead of uploading concurrently', async () => {
136136
await waitForWatcherReady()
137+
// Gate each upload on a test-controlled resolver so assertions don't
138+
// depend on how the OS's chokidar backend coalesces fs events.
139+
const pendingResolvers: Array<() => void> = []
140+
fetchStub.withArgs(sinon.match({
141+
url: 'https://z3ntest.zendesk.com/hc/api/internal/theming/local_preview',
142+
method: 'PUT'
143+
})).callsFake(() => new Promise(resolve => {
144+
pendingResolvers.push(() => resolve({
145+
status: 200,
146+
ok: true,
147+
text: () => Promise.resolve('')
148+
}))
149+
}))
137150
const initialCalls = previewUploadCalls()
138151
const partialsDir = path.join(baseThemePath, 'templates/partials')
139152
fs.mkdirSync(partialsDir, { recursive: true })
140153
const paths = ['a.hbs', 'b.hbs', 'c.hbs'].map(name => path.join(partialsDir, name))
141154
try {
142155
for (const p of paths) fs.writeFileSync(p, '<div/>')
143156
await waitForUploadCount(initialCalls + 1)
144-
// Let any queued rerun finish; a working serializer produces at
145-
// most one in-flight upload plus one queued rerun.
146-
await new Promise(resolve => setTimeout(resolve, 500))
147-
const calls = previewUploadCalls() - initialCalls
148-
expect(calls).to.be.greaterThan(0)
149-
expect(calls).to.be.at.most(2)
157+
expect(previewUploadCalls() - initialCalls).to.eq(1)
158+
pendingResolvers.shift()?.()
159+
await waitForUploadCount(initialCalls + 2)
160+
pendingResolvers.shift()?.()
161+
await new Promise(resolve => setTimeout(resolve, 100))
162+
expect(previewUploadCalls() - initialCalls).to.eq(2)
150163
} finally {
164+
// Drain pending uploads so server.close() in afterEach isn't blocked.
165+
pendingResolvers.forEach(fn => fn())
151166
fs.rmSync(partialsDir, { recursive: true, force: true })
152167
}
153168
})

0 commit comments

Comments
 (0)