Skip to content

Commit

Permalink
fix(ui): list tests on ui when --standalone (#6577)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Sep 26, 2024
1 parent 445367b commit d0bf89d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/ui/client/composables/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,22 @@ watch(
ws.addEventListener('open', async () => {
status.value = 'OPEN'
client.state.filesMap.clear()
const [remoteFiles, _config, errors] = await Promise.all([
let [files, _config, errors] = await Promise.all([
client.rpc.getFiles(),
client.rpc.getConfig(),
client.rpc.getUnhandledErrors(),
])
if (_config.standalone) {
const filenames = await client.rpc.getTestFiles()
const files = filenames.map<File>(([{ name, root }, filepath]) => {
return /* #__PURE__ */ createFileTask(filepath, root, name)
files = filenames.map(([{ name, root }, filepath]) => {
const file = createFileTask(filepath, root, name)
file.mode = 'skip'
return file
})
client.state.collectFiles(files)
}
else {
explorerTree.loadFiles(remoteFiles)
client.state.collectFiles(remoteFiles)
explorerTree.startRun()
}
explorerTree.loadFiles(files)
client.state.collectFiles(files)
explorerTree.startRun()
unhandledErrors.value = (errors || []).map(parseError)
config.value = _config
})
Expand Down
43 changes: 43 additions & 0 deletions test/ui/test/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,46 @@ test.describe('ui', () => {
await expect(page.getByTestId('details-panel').getByText('fixtures/task-name.test.ts', { exact: true })).toBeVisible()
})
})

test.describe('standalone', () => {
let vitest: Vitest | undefined

test.beforeAll(async () => {
// silence Vitest logs
const stdout = new Writable({ write: (_, __, callback) => callback() })
const stderr = new Writable({ write: (_, __, callback) => callback() })
vitest = await startVitest('test', [], {
watch: true,
ui: true,
standalone: true,
open: false,
api: { port },
reporters: [],
}, {}, {
stdout,
stderr,
})
expect(vitest).toBeDefined()
})

test.afterAll(async () => {
await vitest?.close()
})

test('basic', async ({ page }) => {
await page.goto(pageUrl)

// initially no stats
await expect(page.locator('[aria-labelledby=tests]')).toContainText('0 Pass 0 Fail 0 Total')

// run single file
await page.getByText('fixtures/sample.test.ts').hover()
await page.getByRole('button', { name: 'Run current test' }).click()

// check results
await page.getByText('PASS (1)').click()
expect(vitest?.state.getFiles().map(f => [f.name, f.result?.state])).toEqual([
['fixtures/sample.test.ts', 'pass'],
])
})
})

0 comments on commit d0bf89d

Please sign in to comment.