-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3160 from Zemnmez/next-server
Implement next dev server and tests.
- Loading branch information
Showing
4 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import child_process from 'node:child_process'; | ||
import http from 'node:http'; | ||
import * as readline from 'node:readline/promises'; | ||
|
||
import { isDefined, isNotNull, must } from 'ts/guard'; | ||
|
||
test('next.js dev server launch!', async () => { | ||
const next_server_binary = 'ts/next.js/testing/example/dev.sh'; | ||
const BAZEL_BINDIR = must(isDefined)(process?.env?.BAZEL_BINDIR); | ||
|
||
const proc = child_process.execFile(next_server_binary, { | ||
env: { BAZEL_BINDIR }, | ||
}); | ||
|
||
console.info('Waiting for process to go up...'); | ||
|
||
await new Promise((ok, err) => { | ||
proc.once('error', err); | ||
proc.once('spawn', ok); | ||
}); | ||
|
||
const output: NodeJS.WritableStream = must(isNotNull)(proc.stdin); | ||
const input: NodeJS.ReadableStream = must(isNotNull)(proc.stdout); | ||
|
||
for await (const line of readline.createInterface({ | ||
input, // not really needed, we're not asking Qs. | ||
output, | ||
})) { | ||
console.info(line); | ||
const m = /https:\/\/localhost:\d+/g.exec(line); | ||
if (m?.[0]) { | ||
// attempt to connect to the port | ||
const resp: http.IncomingMessage = await new Promise(ok => | ||
http.get(m?.[0], resp => ok(resp)) | ||
); | ||
expect(resp.statusCode).toBe(200); | ||
|
||
break; | ||
} | ||
} | ||
}); |