forked from yocontra/node-gdal-next
-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
api_fs.test.ts
58 lines (57 loc) · 2.24 KB
/
api_fs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as gdal from 'gdal-async'
import * as fs from 'fs'
import * as path from 'path'
import { assert } from 'chai'
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
chai.use(chaiAsPromised)
describe('gdal.fs', () => {
describe('stat()', () => {
it('should return information on file system objects', () => {
const stat = gdal.fs.stat(path.resolve(__dirname, 'data', 'sample.tif'))
assert.equal(stat.size, 794079)
assert.isTrue((stat.mode & fs.constants.S_IFREG) === fs.constants.S_IFREG)
})
it('should support BigInt results', () => {
const stat = gdal.fs.stat(path.resolve(__dirname, 'data', 'sample.tif'), true)
assert.equal(stat.size, BigInt(794079))
})
it('should throw on non-existent files', () => {
assert.throws(() => {
gdal.fs.stat(path.resolve(__dirname, 'data', 'sample2.tif'))
})
})
})
describe('statAsync()', () => {
it('should return information on file system objects', () => {
const stat = gdal.fs.statAsync(path.resolve(__dirname, 'data', 'sample.tif'))
return assert.eventually.propertyVal(stat, 'size', 794079)
})
it('should support BigInt results', () => {
const stat = gdal.fs.statAsync(path.resolve(__dirname, 'data', 'sample.tif'), true)
return assert.eventually.propertyVal(stat, 'size', BigInt(794079))
})
it('should reject on non-existent files', () =>
assert.isRejected(gdal.fs.statAsync(path.resolve(__dirname, 'data', 'sample2.tif'))))
})
describe('readDir()', () => {
it('should return all files in a directory', () => {
const list = gdal.fs.readDir(path.resolve(__dirname, 'data'))
assert.include(list, 'sample.tif')
})
it('should throw on non-existent directories', () => {
assert.throws(() => {
gdal.fs.readDir(path.resolve(__dirname, 'data2'))
})
})
})
describe('readDirAsync()', () => {
it('should return all files in a directory', () => {
const list = gdal.fs.readDirAsync(path.resolve(__dirname, 'data'))
return assert.eventually.include(list, 'sample.tif')
})
it('should throw on non-existent directories', () =>
assert.isRejected(gdal.fs.readDirAsync(path.resolve(__dirname, 'data2')))
)
})
})