rsnext/test/unit/recursive-delete.test.ts
JJ Kasper 005b13f1ac
Move unit tests to one folder and migrate them to TypeScript (#28427)
* Move unit tests to one folder

* Migrate unit tests to TypeScript

* add test types to lint

* Ensure ts(x) tests are run with util

* Add tsx extension to jest config

* bump
2021-08-24 07:52:45 -05:00

43 lines
1.4 KiB
TypeScript

/* eslint-env jest */
import { recursiveDelete } from 'next/dist/lib/recursive-delete'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
import { recursiveCopy } from 'next/dist/lib/recursive-copy'
import { join } from 'path'
const resolveDataDir = join(__dirname, 'isolated', '_resolvedata')
const testResolveDataDir = join(__dirname, 'isolated', 'test_resolvedata')
const testpreservefileDir = join(__dirname, 'isolated', 'preservefiles')
describe('recursiveDelete', () => {
it('should work', async () => {
expect.assertions(1)
try {
await recursiveCopy(resolveDataDir, testResolveDataDir)
await recursiveDelete(testResolveDataDir)
const result = await recursiveReadDir(testResolveDataDir, /.*/)
expect(result.length).toBe(0)
} finally {
await recursiveDelete(testResolveDataDir)
}
})
it('should exclude', async () => {
expect.assertions(2)
try {
await recursiveCopy(resolveDataDir, testpreservefileDir, {
overwrite: true,
})
// preserve cache dir
await recursiveDelete(testpreservefileDir, /^cache/)
const result = await recursiveReadDir(testpreservefileDir, /.*/)
expect(result.length).toBe(1)
} finally {
// Ensure test cleanup
await recursiveDelete(testpreservefileDir)
const cleanupResult = await recursiveReadDir(testpreservefileDir, /.*/)
expect(cleanupResult.length).toBe(0)
}
})
})