service-core/test/util.test.mjs

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-01-11 16:51:15 +00:00
import { Eltro as t, assert} from 'eltro'
import fs from 'fs/promises'
import Util from '../core/util.mjs'
const isWindows = process.platform === 'win32'
t.describe('#getPathFromRoot()', function() {
t.test('should return file relative to root', async function() {
var util = new Util(import.meta.url)
let path = util.getPathFromRoot('')
if (isWindows) {
assert.ok(path.endsWith('\\test\\'))
} else {
assert.ok(path.endsWith('/test/'))
}
path = util.getPathFromRoot('../core/http.mjs')
if (isWindows) {
assert.ok(path.endsWith('\\core\\http.mjs'))
} else {
assert.ok(path.endsWith('/core/http.mjs'))
}
let stat = await fs.stat(util.getPathFromRoot('../manage/.gitkeep'))
assert.strictEqual(stat.size, 0)
})
})
t.describe('#getUrlFromRoot()', function() {
t.test('should return an import compatible path', async function() {
var util = new Util(import.meta.url)
let data = await import(util.getUrlFromRoot('template.mjs'))
assert.deepEqual(data.default, { a: 1 })
})
})