get tests passing in the browser
This commit is contained in:
45
packages/nostr/test/browser/server.ts
Normal file
45
packages/nostr/test/browser/server.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Serve tests in the browser.
|
||||
*/
|
||||
|
||||
import express from "express"
|
||||
import * as path from "path"
|
||||
import * as fs from "fs"
|
||||
|
||||
const port = 33543
|
||||
const app = express()
|
||||
|
||||
app.use("/", (req: express.Request, res: express.Response) => {
|
||||
if (req.path === "/") {
|
||||
const index = fs.readFileSync(path.join(__dirname, "index.html"), {
|
||||
encoding: "utf8",
|
||||
})
|
||||
const tests = fs
|
||||
.readdirSync(path.join(__dirname, "..", "..", "dist", "test"))
|
||||
.filter(
|
||||
(f) =>
|
||||
f.startsWith("test.") && !f.endsWith(".map") && !f.endsWith(".d.ts")
|
||||
)
|
||||
.map((src) => `<script src="${src}"></script>`)
|
||||
.join("\n")
|
||||
res.set("Content-Type", "text/html")
|
||||
res.send(index.replace("<!-- TESTS -->", tests))
|
||||
res.end()
|
||||
} else if (req.path === "/favicon.ico") {
|
||||
res.status(404)
|
||||
res.end()
|
||||
} else {
|
||||
const file = path.join(__dirname, "..", "..", "dist", "test", req.path)
|
||||
res.sendFile(file, (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
res.status(404)
|
||||
}
|
||||
res.end()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Browser tests: http://localhost:${port}`)
|
||||
})
|
Reference in New Issue
Block a user