mockaton 13.3.0 → 13.3.1
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.
package/package.json
CHANGED
package/src/client/app-store.js
CHANGED
package/src/client/app.css
CHANGED
|
@@ -432,7 +432,7 @@ main {
|
|
|
432
432
|
}
|
|
433
433
|
|
|
434
434
|
&.canProxy {
|
|
435
|
-
margin-left:
|
|
435
|
+
margin-left: 124px;
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
|
|
@@ -480,8 +480,15 @@ main {
|
|
|
480
480
|
|
|
481
481
|
.FolderName {
|
|
482
482
|
margin-left: 125px;
|
|
483
|
+
&.canProxy {
|
|
484
|
+
margin-left: 155px;
|
|
485
|
+
}
|
|
486
|
+
|
|
483
487
|
&.groupedByMethod {
|
|
484
488
|
margin-left: 79px;
|
|
489
|
+
&.canProxy {
|
|
490
|
+
margin-left: 109px;
|
|
491
|
+
}
|
|
485
492
|
}
|
|
486
493
|
}
|
|
487
494
|
|
package/src/client/app.js
CHANGED
|
@@ -120,7 +120,12 @@ function FolderGroups(groups) {
|
|
|
120
120
|
},
|
|
121
121
|
r('summary', null,
|
|
122
122
|
r('span', { className: CSS.FolderChevron }, ChevronDownIcon()),
|
|
123
|
-
r('span', {
|
|
123
|
+
r('span', {
|
|
124
|
+
className: classNames(
|
|
125
|
+
CSS.FolderName,
|
|
126
|
+
store.groupByMethod && CSS.groupedByMethod,
|
|
127
|
+
store.canProxy && CSS.canProxy)
|
|
128
|
+
},
|
|
124
129
|
folder + '…')),
|
|
125
130
|
children.map(Row))
|
|
126
131
|
})
|
package/src/server/MockBroker.js
CHANGED
|
@@ -36,10 +36,10 @@ export class MockBroker {
|
|
|
36
36
|
|
|
37
37
|
unregister(file) {
|
|
38
38
|
this.mocks = this.mocks.filter(f => f !== file)
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
39
|
+
const brokerIsEmpty = !this.mocks.length
|
|
40
|
+
if (!brokerIsEmpty && this.file === file)
|
|
41
41
|
this.selectDefaultFile()
|
|
42
|
-
return
|
|
42
|
+
return brokerIsEmpty
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
hasMock = file => this.mocks.includes(file)
|
|
@@ -7,7 +7,7 @@ import { mkdtempSync } from 'node:fs'
|
|
|
7
7
|
import { randomUUID } from 'node:crypto'
|
|
8
8
|
import { equal, deepEqual, match } from 'node:assert/strict'
|
|
9
9
|
import { describe, test, before, beforeEach, after } from 'node:test'
|
|
10
|
-
import { unlink, mkdir, readFile, rename, readdir, writeFile } from 'node:fs/promises'
|
|
10
|
+
import { unlink, mkdir, readFile, rename, readdir, writeFile, rm } from 'node:fs/promises'
|
|
11
11
|
|
|
12
12
|
import { mimeFor } from './utils/mime.js'
|
|
13
13
|
import { parseFilename } from '../client/Filename.js'
|
|
@@ -26,8 +26,15 @@ const proc = spawn(join(import.meta.dirname, 'cli.js'), [
|
|
|
26
26
|
'--no-open'
|
|
27
27
|
])
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
proc.
|
|
29
|
+
const DEBUG = false
|
|
30
|
+
proc.stdout.on('data', data => {
|
|
31
|
+
stdout.push(data.toString())
|
|
32
|
+
DEBUG && process.stdout.write(stdout.at(-1))
|
|
33
|
+
})
|
|
34
|
+
proc.stderr.on('data', data => {
|
|
35
|
+
stderr.push(data.toString())
|
|
36
|
+
DEBUG && process.stderr.write(stdout.at(-1))
|
|
37
|
+
})
|
|
31
38
|
|
|
32
39
|
const serverAddr = await new Promise((resolve, reject) => {
|
|
33
40
|
proc.stdout.once('data', () => {
|
|
@@ -41,12 +48,14 @@ after(() => proc.kill('SIGUSR2'))
|
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
const rmFromMocksDir = f => unlink(join(mocksDir, f))
|
|
44
|
-
const listFromMocksDir = d => readdir(join(mocksDir, d))
|
|
45
51
|
const readFromMocksDir = f => readFile(join(mocksDir, f), 'utf8')
|
|
46
52
|
const writeInMocksDir = (f, data) => writeFile(join(mocksDir, f), data)
|
|
47
|
-
const makeDirInMocks = dir => mkdir(join(mocksDir, dir), { recursive: true })
|
|
48
53
|
const renameInMocksDir = (src, target) => rename(join(mocksDir, src), join(mocksDir, target))
|
|
49
54
|
|
|
55
|
+
const listFromMocksDir = d => readdir(join(mocksDir, d))
|
|
56
|
+
const rmDirFromMocks = d => rm(join(mocksDir, d), { recursive: true })
|
|
57
|
+
const makeDirInMocks = dir => mkdir(join(mocksDir, dir), { recursive: true })
|
|
58
|
+
|
|
50
59
|
|
|
51
60
|
const api = new Commander(serverAddr)
|
|
52
61
|
|
|
@@ -1120,6 +1129,16 @@ describe('Registering Mocks', () => {
|
|
|
1120
1129
|
equal(s.brokersByMethod.GET['/reg1/runtime0'].file, 'reg1/runtime0.GET.200.txt')
|
|
1121
1130
|
})
|
|
1122
1131
|
})
|
|
1132
|
+
|
|
1133
|
+
test('deleting a folder unregisters mocks in it', async () => {
|
|
1134
|
+
const fx = new Fixture('api/bulk-delete/bar.GET.200.json')
|
|
1135
|
+
await fx.write()
|
|
1136
|
+
await sleep(0)
|
|
1137
|
+
const nextVerPromise = resolveOnNextSyncVersion()
|
|
1138
|
+
await rmDirFromMocks('api/bulk-delete')
|
|
1139
|
+
await nextVerPromise
|
|
1140
|
+
equal(await fx.fetchBroker(), undefined)
|
|
1141
|
+
})
|
|
1123
1142
|
})
|
|
1124
1143
|
|
|
1125
1144
|
|
|
@@ -47,7 +47,6 @@ export function registerMock(file, isFromWatcher = false) {
|
|
|
47
47
|
collection[method] ??= {}
|
|
48
48
|
|
|
49
49
|
let broker = collection[method][urlMask]
|
|
50
|
-
|
|
51
50
|
if (!broker)
|
|
52
51
|
broker = collection[method][urlMask] = new MockBroker(file)
|
|
53
52
|
else
|
|
@@ -61,15 +60,26 @@ export function registerMock(file, isFromWatcher = false) {
|
|
|
61
60
|
|
|
62
61
|
export function unregisterMock(file) {
|
|
63
62
|
const broker = brokerByFilename(file)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
if (broker) {
|
|
64
|
+
const brokerIsEmpty = broker.unregister(file)
|
|
65
|
+
if (brokerIsEmpty) {
|
|
66
|
+
const { method, urlMask } = parseFilename(file)
|
|
67
|
+
delete collection[method][urlMask]
|
|
68
|
+
if (!Object.keys(collection[method]).length)
|
|
69
|
+
delete collection[method]
|
|
70
|
+
}
|
|
70
71
|
}
|
|
72
|
+
else for (const f of filesInDir(file)) // maybe it was a dir
|
|
73
|
+
unregisterMock(f)
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
function filesInDir(dir) {
|
|
77
|
+
const files = []
|
|
78
|
+
forEachBroker(b => {
|
|
79
|
+
files.push(...(b.mocks.filter(m => m.startsWith(dir + '/'))))
|
|
80
|
+
})
|
|
81
|
+
return files
|
|
82
|
+
}
|
|
73
83
|
|
|
74
84
|
/** @returns {MockBroker | undefined} */
|
|
75
85
|
export function brokerByFilename(file) {
|