|
1 |
| -import { assert, assertEquals, assertThrows } from 'https://deno.land/[email protected]/testing/asserts.ts' |
| 1 | +import { |
| 2 | + assert, assertEquals, assertThrows, |
| 3 | + assertExists, assertNotEquals |
| 4 | +} from 'https://deno.land/[email protected]/testing/asserts.ts' |
2 | 5 | import { SEP } from "https://deno.land/[email protected]/path/separator.ts"
|
3 |
| -import { existsDir, existsDirSync, existsFile, existsFileSync } from './fs.ts' |
| 6 | +import { |
| 7 | + existsDir, existsDirSync, existsFile, existsFileSync, |
| 8 | + ensureTextFile, lazyRemove |
| 9 | +} from './fs.ts' |
4 | 10 |
|
5 | 11 |
|
6 | 12 | Deno.test(`fs existsDirSync`, () => {
|
@@ -45,16 +51,45 @@ Deno.test(`fs async existsFile`, async () => {
|
45 | 51 | // false test cases
|
46 | 52 | assertEquals(await existsFile(getAbsolutePath(`.${SEP}shared${SEP}foobar.ts`)), false)
|
47 | 53 | // error test cases
|
48 |
| - existsDir({} as string).then(err => { |
| 54 | + existsFile({} as string).then(err => { |
49 | 55 | assert(err instanceof Error)
|
50 | 56 | }).catch(e => console.error(e))
|
51 | 57 | })
|
52 | 58 |
|
53 |
| -Deno.test('ensureTextFile', () => { |
54 |
| - |
| 59 | +Deno.test('ensureTextFile', async () => { |
| 60 | + // true test case |
| 61 | + const dirPath = await Deno.makeTempDir() |
| 62 | + const textFilePath = `${dirPath}${SEP}test.txt` |
| 63 | + const content = 'This is a test' |
| 64 | + await ensureTextFile(textFilePath, content) |
| 65 | + assert(await existsFile(textFilePath)) |
| 66 | + const testContent = await Deno.readTextFile(textFilePath) |
| 67 | + assertEquals(testContent, content) |
| 68 | + // FIXME: false test case |
| 69 | + // illegal folder name |
| 70 | + // const textFilePath2 = `${SEP}test2.txt` |
| 71 | + // let testContent2 = '' |
| 72 | + // try { |
| 73 | + // await ensureTextFile(textFilePath2, content) |
| 74 | + // testContent2 = await Deno.readTextFile(textFilePath2) |
| 75 | + // } catch (error) { |
| 76 | + // assertNotEquals(testContent2, content) |
| 77 | + // } |
55 | 78 | })
|
56 | 79 |
|
57 |
| -Deno.test('lazyRemove', () => { |
| 80 | +Deno.test('lazyRemove', async () => { |
| 81 | + // true test |
| 82 | + const filePath = await Deno.makeTempFile() |
| 83 | + await lazyRemove(filePath) |
| 84 | + assertEquals(existsFileSync(filePath), false) |
| 85 | + // false test |
| 86 | + const dirPath = await Deno.makeTempDir() |
| 87 | + await lazyRemove(`${dirPath}${SEP}asdfsdf.txt`) |
| 88 | + assert(await existsDir(dirPath)) |
| 89 | + // error test |
| 90 | + lazyRemove({} as string).then(err => { |
| 91 | + assert(err instanceof Error) |
| 92 | + }).catch(e => console.error(e)) |
58 | 93 |
|
59 | 94 | })
|
60 | 95 |
|
|
0 commit comments