代码拉取完成,页面将自动刷新
import {
assert,
assertEquals,
assertStringIncludes
} from 'std/testing/asserts.ts'
import { emptyDir } from 'std/fs/mod.ts'
import { BufReader } from 'std/io/bufio.ts'
import { DOMParser } from 'https://deno.land/x/deno_dom@v0.1.15-alpha/deno-dom-wasm.ts'
Deno.test('integration: dev command', async () => {
const distDir = './examples/hello-world/dist'
await emptyDir(distDir)
localStorage.removeItem('count')
const buildCmd = aleph(['dev', './examples/hello-world', '--port', '8080'])
try {
const port = await waitForServerToStart(buildCmd)
// Call /api/counter/increase twice
let res = await fetch(`http://localhost:${port}/api/counter/increase`)
assert(res.ok)
assertEquals(await res.json(), { count: 1 })
res = await fetch(`http://localhost:${port}/api/counter/increase`)
assert(res.ok)
assertEquals(await res.json(), { count: 2 })
// Get index page
const parser = new DOMParser()
res = await fetch(`http://localhost:${port}`)
const html = await res.text()
const doc = parser.parseFromString(html, 'text/html')
assert(doc)
const copyinfo = doc.querySelector('.copyinfo')
assert(copyinfo)
assertStringIncludes(copyinfo.textContent, 'Built by Aleph.js in Deno')
} finally {
cleanupAlephProcess(buildCmd)
}
})
function aleph(cmd: Array<string>): Deno.Process {
return Deno.run({
cmd: [
Deno.execPath(),
'run',
'-A',
'--unstable',
'--location=http://localhost',
'cli.ts',
...cmd
],
env: {
'ALEPH_DEV': 'true',
'NO_COLOR': 'true'
},
stdout: "piped",
})
}
function cleanupAlephProcess(process: Deno.Process): void {
if (process.stdout) {
process.stdout.close()
}
process.close()
}
// Waits for the aleph server to start and returns a port
async function waitForServerToStart(process: Deno.Process): Promise<number> {
assert(process.stdout)
const buf = BufReader.create(process.stdout)
const decoder = new TextDecoder()
while (true) {
const result = await buf.readLine()
if (result == null) {
throw new Error('Unexpected EOF')
}
const { line } = result
const match = /^INFO Server ready on http:\/\/localhost:(\d+).*$/.exec(decoder.decode(line))
if (match) {
const [, port] = match
return parseInt(port)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。