forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
45 lines (36 loc) · 1.16 KB
/
helpers.js
File metadata and controls
45 lines (36 loc) · 1.16 KB
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
import path from 'path'
import fs from 'fs-extra'
import { fileURLToPath } from 'url'
import supertest from 'supertest'
import { createApp } from '../lib/server.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
let testCounter = 0
export function createTestApp (options = {}) {
const testDir = path.join(__dirname, `tmp-${process.pid}-${++testCounter}`)
fs.mkdirpSync(testDir)
const serverUri = options.serverUri || 'https://localhost:8443'
const app = createApp({
root: testDir,
serverUri,
skipAuth: options.skipAuth !== undefined ? options.skipAuth : true,
...options
})
const request = supertest(app)
return { app, request, testDir, serverUri }
}
export function cleanTestDir (testDir) {
try {
fs.removeSync(testDir)
} catch { /* ignore */ }
}
export function createFile (testDir, relativePath, content = '', options = {}) {
const filePath = path.join(testDir, relativePath)
fs.mkdirpSync(path.dirname(filePath))
fs.writeFileSync(filePath, content)
return filePath
}
export function createDir (testDir, relativePath) {
const dirPath = path.join(testDir, relativePath)
fs.mkdirpSync(dirPath)
return dirPath
}