mockaton 13.11.0 → 13.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,19 +4,17 @@ import { createServer } from 'node:http'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { equal } from 'node:assert/strict'
6
6
  import { join } from 'node:path'
7
- import { rm } from 'node:fs/promises'
7
+ import { rmdir } from 'node:fs/promises'
8
8
 
9
9
  import { ServerResponse } from './HttpServerResponse.js'
10
10
 
11
- describe('ServerResponse', () => {
11
+ describe('ServerResponse', { concurrency: true }, () => {
12
12
  const FILE = '0123456789'
13
+ const tmpDir = mkdtempSync(join(tmpdir(), 'response-'))
14
+ writeFileSync(join(tmpDir, 'test.txt'), FILE)
13
15
 
14
- let tmpDir, tmpFile, server, addr
16
+ let server, addr
15
17
  before(async () => {
16
- tmpDir = mkdtempSync(join(tmpdir(), 'response-'))
17
- tmpFile = join(tmpDir, 'test.txt')
18
- writeFileSync(tmpFile, FILE)
19
-
20
18
  server = createServer({ ServerResponse }, (req, response) => {
21
19
  const file = join(tmpDir, req.url)
22
20
  if (req.headers.range)
@@ -26,14 +24,14 @@ describe('ServerResponse', () => {
26
24
  })
27
25
 
28
26
  await new Promise(resolve => server.listen(0, () => {
29
- addr = `http://127.0.0.1:${(server.address().port)}`
27
+ addr = `http://127.0.0.1:${server.address().port}`
30
28
  resolve()
31
29
  }))
32
30
  })
33
31
 
34
32
  after(async () => {
35
33
  server?.close()
36
- await rm(tmpDir, { recursive: true, force: true })
34
+ await rmdir(tmpDir, { recursive: true, force: true })
37
35
  })
38
36
 
39
37
 
@@ -12,7 +12,7 @@ const devClientWatcher = new class extends EventEmitter {
12
12
  // Although `client/IndexHtml.js` is watched, it returns a stale version.
13
13
  // i.e., it would need to be a dynamic import + cache busting.
14
14
  export function watchDevSPA(dir) {
15
- watch(dir, (_, file) => {
15
+ watch(dir, { recursive: true }, (_, file) => {
16
16
  devClientWatcher.emit(file)
17
17
  })
18
18
  }
@@ -34,7 +34,7 @@ export async function rm(path) {
34
34
  export async function resolveIn(baseDir, file) {
35
35
  try {
36
36
  const parent = await realpath(baseDir)
37
- const child = resolve(join(parent, file))
37
+ const child = resolve(join(parent, file)) // realpath not needed because we don't write symlinks
38
38
  return child.startsWith(join(parent, sep))
39
39
  ? child
40
40
  : null
@@ -11,22 +11,27 @@ export const openInBrowser = (async () => {
11
11
  })()
12
12
 
13
13
  function _openInBrowser(address) {
14
- let opener
14
+ let command = ''
15
+ let args = [address]
16
+
15
17
  switch (process.platform) {
16
18
  case 'darwin':
17
- opener = 'open'
19
+ command = '/usr/bin/open'
18
20
  break
21
+
19
22
  case 'win32':
20
- opener = 'start'
23
+ command = 'cmd'
24
+ args = ['/c', 'start', '', address]
21
25
  break
26
+
22
27
  default:
23
- opener = ['xdg-open', 'gnome-open', 'kde-open'].find(hasCommand)
28
+ command = ['xdg-open', 'gnome-open', 'kde-open'].find(function hasCommand(cmd) {
29
+ const { status } = spawnSync('command', ['-v', cmd], { stdio: 'ignore' })
30
+ return status === 0
31
+ })
24
32
  }
25
- if (opener)
26
- spawnSync(opener, [address])
27
- }
28
33
 
29
- function hasCommand(cmd) {
30
- const { status } = spawnSync('command', ['-v', cmd], { stdio: 'ignore' })
31
- return status === 0
34
+ if (command)
35
+ spawnSync(command, args)
32
36
  }
37
+