mockaton 6.0.0 → 6.1.0

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/README.md CHANGED
@@ -51,7 +51,6 @@ interface Config {
51
51
  onReady?: (dashboardUrl: string) => void // defaults to trying to open macOS default browser. pass a noop to prevent opening the dashboard
52
52
  cookies?: object
53
53
  proxyFallback?: string // e.g. http://localhost:9999 Target for relaying routes without mocks
54
- allowedExt?: RegExp // /\.(json|js|txt)$/ Just for excluding temporary editor files (e.g. JetBrains appends a ~)
55
54
  extraHeaders?: []
56
55
  }
57
56
  ```
@@ -118,8 +117,6 @@ The delay is globally configurable via `Config.delay = 1200` (milliseconds).
118
117
 
119
118
  The **file extension** can be anything, but `.md` is reserved for documentation.
120
119
 
121
- The `Config.allowedExt` regex defaults to: `/\.(md|json|txt|js)$/`
122
-
123
120
 
124
121
  ### Dynamic Parameters
125
122
  Anything within square brackets. For example:
package/Tests.js CHANGED
@@ -354,7 +354,6 @@ async function testInvalidFilenamesAreIgnored() {
354
354
  const consoleErrorSpy = t.mock.method(console, 'error')
355
355
  consoleErrorSpy.mock.mockImplementation(() => {}) // so they don’t render in the test report
356
356
 
357
- // An extension is needed for testing because of `Config.allowedExt`
358
357
  write('api/_INVALID_FILENAME_CONVENTION_.json', '')
359
358
  write('api/bad-filename.GET._INVALID_STATUS_.json', '')
360
359
  write('api/bad-filename._INVALID_METHOD_.200.json', '')
package/index.d.ts CHANGED
@@ -9,7 +9,6 @@ interface Config {
9
9
  onReady?: (address: string) => void
10
10
  cookies?: object
11
11
  proxyFallback?: string
12
- allowedExt?: RegExp
13
12
  extraHeaders?: [string, string][]
14
13
  }
15
14
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "6.0.0",
5
+ "version": "6.1.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Config.js CHANGED
@@ -12,7 +12,6 @@ export const Config = {
12
12
  cookies: {}, // defaults to the first kv
13
13
  onReady: openInBrowser,
14
14
  proxyFallback: '', // e.g. http://localhost:9999
15
- allowedExt: /\.(json|js|txt)$/, // Just for excluding temporary editor files (e.g. JetBrains appends a ~)
16
15
  extraHeaders: []
17
16
  }
18
17
 
@@ -27,7 +26,6 @@ export function setup(options) {
27
26
  cookies: is(Object),
28
27
  onReady: is(Function),
29
28
  proxyFallback: optional(URL.canParse),
30
- allowedExt: is(RegExp),
31
29
  extraHeaders: Array.isArray
32
30
  })
33
31
  }
@@ -5,6 +5,7 @@ import { Route } from './Route.js'
5
5
  import { Config } from './Config.js'
6
6
  import { cookie } from './cookie.js'
7
7
  import { isFile } from './utils/fs.js'
8
+ import { mimeFor } from './utils/mime.js'
8
9
  import { MockBroker } from './MockBroker.js'
9
10
 
10
11
 
@@ -25,7 +26,7 @@ export function init() {
25
26
  cookie.init(Config.cookies)
26
27
 
27
28
  const files = readDir(Config.mocksDir, { recursive: true })
28
- .filter(f => Config.allowedExt.test(f) && isFile(join(Config.mocksDir, f)))
29
+ .filter(f => isFile(join(Config.mocksDir, f)) && mimeFor(f))
29
30
  .sort()
30
31
 
31
32
  for (const file of files) {
package/src/utils/mime.js CHANGED
@@ -1,9 +1,28 @@
1
1
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
2
+ // m = {};
3
+ // for (const row of tbody.children)
4
+ // m[row.children[0].querySelector('code').innerText] = row.children[2].querySelector('code').innerText
5
+
2
6
  const mimes = {
3
- aac: 'audio/acc',
7
+ '3g2': 'video/3gpp2',
8
+ '3gp': 'video/3gpp',
9
+ '7z': 'application/x-7z-compressed',
10
+ aac: 'audio/aac',
11
+ abw: 'application/x-abiword',
4
12
  apng: 'image/apng',
13
+ arc: 'application/x-freearc',
14
+ avi: 'video/x-msvideo',
5
15
  avif: 'image/avif',
16
+ azw: 'application/vnd.amazon.ebook',
17
+ bin: 'application/octet-stream',
18
+ bmp: 'image/bmp',
19
+ bz2: 'application/x-bzip2',
20
+ bz: 'application/x-bzip',
21
+ cda: 'application/x-cdf',
22
+ cjs: 'text/javascript',
23
+ csh: 'application/x-csh',
6
24
  css: 'text/css',
25
+ csv: 'text/csv',
7
26
  doc: 'application/msword',
8
27
  docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
9
28
  eot: 'application/vnd.ms-fontobject',
@@ -14,34 +33,59 @@ const mimes = {
14
33
  html: 'text/html',
15
34
  ico: 'image/vnd.microsoft.icon',
16
35
  ics: 'text/calendar',
36
+ jar: 'application/java-archive',
17
37
  jpeg: 'image/jpeg',
18
38
  jpg: 'image/jpeg',
19
- js: 'application/javascript',
39
+ js: 'text/javascript',
20
40
  json: 'application/json',
21
41
  jsonld: 'application/ld+json',
22
- md: 'text/markdown',
42
+ mid: 'audio/midi',
23
43
  mjs: 'text/javascript',
24
44
  mp3: 'audio/mpeg',
25
45
  mp4: 'video/mp4',
26
- oft: 'font/otf',
46
+ mpeg: 'video/mpeg',
47
+ mpkg: 'application/vnd.apple.installer+xml',
48
+ odp: 'application/vnd.oasis.opendocument.presentation',
49
+ ods: 'application/vnd.oasis.opendocument.spreadsheet',
50
+ odt: 'application/vnd.oasis.opendocument.text',
51
+ oga: 'audio/ogg',
52
+ ogv: 'video/ogg',
53
+ ogx: 'application/ogg',
54
+ opus: 'audio/ogg',
55
+ otf: 'font/otf',
27
56
  pdf: 'application/pdf',
57
+ php: 'application/x-httpd-php',
28
58
  png: 'image/png',
59
+ ppt: 'application/vnd.ms-powerpoint',
60
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
61
+ rar: 'application/vnd.rar',
62
+ rtf: 'application/rtf',
63
+ sh: 'application/x-sh',
64
+ svg: 'image/svg+xml',
65
+ tar: 'application/x-tar',
66
+ tif: 'image/tiff',
67
+ ts: 'video/mp2t',
29
68
  ttf: 'font/ttf',
30
- txt: 'plain/text',
69
+ txt: 'text/plain',
70
+ vsd: 'application/vnd.visio',
31
71
  wav: 'audio/wav',
32
72
  weba: 'audio/webm',
33
73
  webm: 'video/webm',
34
74
  webp: 'image/webp',
35
75
  woff2: 'font/woff2',
36
76
  woff: 'font/woff',
77
+ xhtml: 'application/xhtml+xml',
78
+ xls: 'application/vnd.ms-excel',
79
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
37
80
  xml: 'application/xml',
81
+ xul: 'application/vnd.mozilla.xul+xml',
38
82
  zip: 'application/zip'
39
83
  }
40
84
 
41
85
  export function mimeFor(filename) {
42
- const ext = filename.replace(/.*\./, '')
86
+ const ext = filename.replace(/.*\./, '').toLowerCase()
43
87
  const mime = mimes[ext] || ''
44
88
  if (!mime)
45
- console.error(`Missing MIME for ${filename}`)
89
+ console.info(`Missing MIME for ${filename}`)
46
90
  return mime
47
- }
91
+ }