Skip to content

Commit 72d0b38

Browse files
committed
ci: use fs promises
1 parent b13c74f commit 72d0b38

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/core/RoutesFolderWatcher.spec.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {
1414
} from './RoutesFolderWatcher'
1515
import { resolveOptions, RoutesFolderOption } from '../options'
1616
import pathe from 'pathe'
17-
import fs from 'node:fs'
17+
import fs from 'node:fs/promises'
1818
import { tmpdir } from 'node:os'
19-
import { delay } from '../../tests/utils'
2019

2120
const FIXTURES_ROOT = pathe.resolve(
2221
pathe.join(tmpdir(), 'vue-router-' + Date.now())
@@ -25,22 +24,22 @@ const FIXTURES_ROOT = pathe.resolve(
2524
const TEST_TIMEOUT = 4000
2625

2726
describe('RoutesFolderWatcher', () => {
28-
beforeAll(() => {
29-
fs.mkdirSync(FIXTURES_ROOT, { recursive: true })
27+
beforeAll(async () => {
28+
await fs.mkdir(FIXTURES_ROOT, { recursive: true })
3029
})
3130

3231
// keep track of all watchers to close them after the tests
3332
let watcherList: RoutesFolderWatcher[] = []
3433
let testId = 0
35-
function createWatcher(routesFolderOptions: RoutesFolderOption) {
34+
async function createWatcher(routesFolderOptions: RoutesFolderOption) {
3635
const rootDir = pathe.join(FIXTURES_ROOT, `test-${testId++}`)
3736
const srcDir = pathe.join(rootDir, routesFolderOptions.src)
3837
const options = resolveFolderOptions(
3938
resolveOptions({ root: rootDir }),
4039
routesFolderOptions
4140
)
4241

43-
fs.mkdirSync(srcDir, { recursive: true })
42+
await fs.mkdir(srcDir, { recursive: true })
4443

4544
const watcher = new RoutesFolderWatcher(options)
4645
watcherList.push(watcher)
@@ -75,17 +74,16 @@ describe('RoutesFolderWatcher', () => {
7574
}
7675

7776
it('triggers when new pages are added', async () => {
78-
const { watcher, srcDir } = createWatcher({ src: 'src/pages' })
77+
const { watcher, srcDir } = await createWatcher({ src: 'src/pages' })
7978

8079
const add = vi.fn<(ctx: HandlerContext) => void>()
81-
// watcher.on('add', add)
82-
// chokidar triggers change instead of add
80+
// chokidar triggers change and/or add ???
81+
watcher.on('add', add)
8382
watcher.on('change', add)
8483

8584
expect(add).toHaveBeenCalledTimes(0)
86-
await delay(200)
8785

88-
fs.writeFileSync(pathe.join(srcDir, 'a.vue'), '', 'utf-8')
86+
await fs.writeFile(pathe.join(srcDir, 'a.vue'), '', 'utf-8')
8987

9088
await waitForSpy(add)
9189
})

0 commit comments

Comments
 (0)