@verdaccio/middleware 6.0.0-6-next.38 → 6.0.0-6-next.39

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/index.d.ts +3 -0
  3. package/build/index.js +24 -0
  4. package/build/index.js.map +1 -1
  5. package/build/middlewares/rate-limit.d.ts +2 -0
  6. package/build/middlewares/rate-limit.js +13 -0
  7. package/build/middlewares/rate-limit.js.map +1 -0
  8. package/build/middlewares/user-agent.d.ts +2 -0
  9. package/build/middlewares/user-agent.js +14 -0
  10. package/build/middlewares/user-agent.js.map +1 -0
  11. package/build/middlewares/validation.d.ts +2 -3
  12. package/build/middlewares/validation.js +2 -2
  13. package/build/middlewares/validation.js.map +1 -1
  14. package/build/middlewares/web/index.d.ts +1 -0
  15. package/build/middlewares/web/index.js +14 -0
  16. package/build/middlewares/web/index.js.map +1 -0
  17. package/build/middlewares/web/render-web.d.ts +1 -0
  18. package/build/middlewares/web/render-web.js +103 -0
  19. package/build/middlewares/web/render-web.js.map +1 -0
  20. package/build/middlewares/web/security.d.ts +1 -0
  21. package/build/middlewares/web/security.js +19 -0
  22. package/build/middlewares/web/security.js.map +1 -0
  23. package/build/middlewares/web/utils/manifest.d.ts +6 -0
  24. package/build/middlewares/web/utils/manifest.js +18 -0
  25. package/build/middlewares/web/utils/manifest.js.map +1 -0
  26. package/build/middlewares/web/utils/renderHTML.d.ts +7 -0
  27. package/build/middlewares/web/utils/renderHTML.js +133 -0
  28. package/build/middlewares/web/utils/renderHTML.js.map +1 -0
  29. package/build/middlewares/web/utils/template.d.ts +13 -0
  30. package/build/middlewares/web/utils/template.js +38 -0
  31. package/build/middlewares/web/utils/template.js.map +1 -0
  32. package/build/middlewares/web/utils/web-utils.d.ts +2 -0
  33. package/build/middlewares/web/utils/web-utils.js +24 -0
  34. package/build/middlewares/web/utils/web-utils.js.map +1 -0
  35. package/build/middlewares/web/web-api.d.ts +1 -0
  36. package/build/middlewares/web/web-api.js +32 -0
  37. package/build/middlewares/web/web-api.js.map +1 -0
  38. package/build/middlewares/web/web-middleware.d.ts +2 -0
  39. package/build/middlewares/web/web-middleware.js +25 -0
  40. package/build/middlewares/web/web-middleware.js.map +1 -0
  41. package/package.json +10 -5
  42. package/src/index.ts +3 -0
  43. package/src/middlewares/rate-limit.ts +8 -0
  44. package/src/middlewares/user-agent.ts +10 -0
  45. package/src/middlewares/validation.ts +2 -16
  46. package/src/middlewares/web/index.ts +1 -0
  47. package/src/middlewares/web/render-web.ts +99 -0
  48. package/src/middlewares/web/security.ts +13 -0
  49. package/src/middlewares/web/utils/manifest.ts +23 -0
  50. package/src/middlewares/web/utils/renderHTML.ts +134 -0
  51. package/src/middlewares/web/utils/template.ts +50 -0
  52. package/src/middlewares/web/utils/web-utils.ts +18 -0
  53. package/src/middlewares/web/web-api.ts +27 -0
  54. package/src/middlewares/web/web-middleware.ts +15 -0
  55. package/test/__snapshots__/template.test.ts.snap +151 -0
  56. package/test/_helper.ts +8 -0
  57. package/test/config/default-test.yaml +28 -0
  58. package/test/config/login-disabled.yaml +29 -0
  59. package/test/config/web.yaml +23 -0
  60. package/test/manifest.test.ts +11 -0
  61. package/test/partials/htmlParser.ts +1 -0
  62. package/test/partials/manifest/manifest.json +64 -0
  63. package/test/render.spec.ts +106 -0
  64. package/test/static/main.js +3 -0
  65. package/test/static/vendor.js +3 -0
  66. package/test/template.test.ts +74 -0
  67. package/test/utils.spec.ts +13 -0
  68. package/tsconfig.json +6 -0
@@ -0,0 +1,151 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`template custom body after 1`] = `
4
+ "
5
+ <!DOCTYPE html>
6
+ <html lang="en-us">
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <base href="http://domain.com">
10
+ <title></title>
11
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
12
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
13
+ <script>
14
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
15
+ </script>
16
+
17
+ </head>
18
+ <body class="body">
19
+
20
+ <div id="root"></div>
21
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
22
+ <script src="foo"/>
23
+ </body>
24
+ </html>
25
+ "
26
+ `;
27
+
28
+ exports[`template custom body before 1`] = `
29
+ "
30
+ <!DOCTYPE html>
31
+ <html lang="en-us">
32
+ <head>
33
+ <meta charset="utf-8">
34
+ <base href="http://domain.com">
35
+ <title></title>
36
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
37
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
38
+ <script>
39
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
40
+ </script>
41
+
42
+ </head>
43
+ <body class="body">
44
+ <script src="fooBefore"/><script src="barBefore"/>
45
+ <div id="root"></div>
46
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
47
+
48
+ </body>
49
+ </html>
50
+ "
51
+ `;
52
+
53
+ exports[`template custom render 1`] = `
54
+ "
55
+ <!DOCTYPE html>
56
+ <html lang="en-us">
57
+ <head>
58
+ <meta charset="utf-8">
59
+ <base href="http://domain.com">
60
+ <title></title>
61
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
62
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
63
+ <script>
64
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
65
+ </script>
66
+
67
+ </head>
68
+ <body class="body">
69
+
70
+ <div id="root"></div>
71
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
72
+
73
+ </body>
74
+ </html>
75
+ "
76
+ `;
77
+
78
+ exports[`template custom title 1`] = `
79
+ "
80
+ <!DOCTYPE html>
81
+ <html lang="en-us">
82
+ <head>
83
+ <meta charset="utf-8">
84
+ <base href="http://domain.com">
85
+ <title>foo title</title>
86
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
87
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
88
+ <script>
89
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com","title":"foo title"}
90
+ </script>
91
+
92
+ </head>
93
+ <body class="body">
94
+
95
+ <div id="root"></div>
96
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
97
+
98
+ </body>
99
+ </html>
100
+ "
101
+ `;
102
+
103
+ exports[`template custom title 2`] = `
104
+ "
105
+ <!DOCTYPE html>
106
+ <html lang="en-us">
107
+ <head>
108
+ <meta charset="utf-8">
109
+ <base href="http://domain.com">
110
+ <title>foo title</title>
111
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
112
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
113
+ <script>
114
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com","title":"foo title"}
115
+ </script>
116
+
117
+ </head>
118
+ <body class="body">
119
+
120
+ <div id="root"></div>
121
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
122
+
123
+ </body>
124
+ </html>
125
+ "
126
+ `;
127
+
128
+ exports[`template meta scripts 1`] = `
129
+ "
130
+ <!DOCTYPE html>
131
+ <html lang="en-us">
132
+ <head>
133
+ <meta charset="utf-8">
134
+ <base href="http://domain.com">
135
+ <title></title>
136
+ <link rel="icon" href="http://domain.com-/static/favicon.ico"/>
137
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
138
+ <script>
139
+ window.__VERDACCIO_BASENAME_UI_OPTIONS={"base":"http://domain.com"}
140
+ </script>
141
+ <style>.someclass{font-size:10px;}</style>
142
+ </head>
143
+ <body class="body">
144
+
145
+ <div id="root"></div>
146
+ <script defer="defer" src="http://domain.com/-/static/runtime.6126058572f989c948b1.js"></script><script defer="defer" src="http://domain.com/-/static/main.6126058572f989c948b1.js"></script>
147
+
148
+ </body>
149
+ </html>
150
+ "
151
+ `;
@@ -0,0 +1,8 @@
1
+ import path from 'path';
2
+
3
+ import { parseConfigFile } from '@verdaccio/config';
4
+
5
+ export const getConf = (configName: string) => {
6
+ const configPath = path.join(__dirname, 'config', configName);
7
+ return parseConfigFile(configPath);
8
+ };
@@ -0,0 +1,28 @@
1
+ auth:
2
+ auth-memory:
3
+ users:
4
+ test:
5
+ name: test
6
+ password: test
7
+
8
+ web:
9
+ title: verdaccio
10
+
11
+ publish:
12
+ allow_offline: false
13
+
14
+ uplinks:
15
+
16
+ log: { type: stdout, format: pretty, level: trace }
17
+
18
+ packages:
19
+ '@*/*':
20
+ access: $anonymous
21
+ publish: $anonymous
22
+ '**':
23
+ access: $anonymous
24
+ publish: $anonymous
25
+ _debug: true
26
+
27
+ flags:
28
+ changePassword: true
@@ -0,0 +1,29 @@
1
+ auth:
2
+ auth-memory:
3
+ users:
4
+ test:
5
+ name: test
6
+ password: test
7
+
8
+ web:
9
+ title: verdaccio
10
+ login: false
11
+
12
+ publish:
13
+ allow_offline: false
14
+
15
+ uplinks:
16
+
17
+ log: { type: stdout, format: pretty, level: trace }
18
+
19
+ packages:
20
+ '@*/*':
21
+ access: $anonymous
22
+ publish: $anonymous
23
+ '**':
24
+ access: $anonymous
25
+ publish: $anonymous
26
+ _debug: true
27
+
28
+ flags:
29
+ changePassword: true
@@ -0,0 +1,23 @@
1
+ web:
2
+ title: verdaccio web
3
+ login: true
4
+ scope: '@scope'
5
+ pkgManagers:
6
+ - pnpm
7
+ - yarn
8
+ showInfo: true
9
+ showSettings: true
10
+ showSearch: true
11
+ showFooter: true
12
+ showThemeSwitch: true
13
+ showDownloadTarball: true
14
+ showRaw: true
15
+ primary_color: '#ffffff'
16
+ logoURI: 'http://logo.org/logo.png'
17
+
18
+ url_prefix: /prefix
19
+
20
+ log: { type: stdout, format: pretty, level: trace }
21
+
22
+ flags:
23
+ changePassword: true
@@ -0,0 +1,11 @@
1
+ import { getManifestValue } from '../src/middlewares/web/utils/manifest';
2
+
3
+ const manifest = require('./partials/manifest/manifest.json');
4
+
5
+ describe('manifest', () => {
6
+ test('getManifestValue', () => {
7
+ expect(getManifestValue(['main.js'], manifest)).toEqual([
8
+ '/-/static/main.6126058572f989c948b1.js',
9
+ ]);
10
+ });
11
+ });
@@ -0,0 +1 @@
1
+ export const parseHtml = (html) => require('node-html-parser').parse(html);
@@ -0,0 +1,64 @@
1
+ {
2
+ "main.js": "/-/static/main.6126058572f989c948b1.js",
3
+ "main.css": "/-/static/main.6f2f2cccce0c813b509f.css",
4
+ "main.woff2": "/-/static/fonts/roboto-latin-900italic.woff2",
5
+ "main.woff": "/-/static/fonts/roboto-latin-900italic.woff",
6
+ "main.svg": "/-/static/93df1ce974e744e7d98f5d842da74ba0.svg",
7
+ "runtime.js": "/-/static/runtime.6126058572f989c948b1.js",
8
+ "NotFound.js": "/-/static/NotFound.6126058572f989c948b1.js",
9
+ "NotFound.svg": "/-/static/4743f1431b042843890a8644e89bb852.svg",
10
+ "Provider.js": "/-/static/Provider.6126058572f989c948b1.js",
11
+ "Version.css": "/-/static/454.97490e2b7f0dca05ddf3.css",
12
+ "Home.js": "/-/static/Home.6126058572f989c948b1.js",
13
+ "Home.css": "/-/static/268.97490e2b7f0dca05ddf3.css",
14
+ "Versions.js": "/-/static/Versions.6126058572f989c948b1.js",
15
+ "UpLinks.js": "/-/static/UpLinks.6126058572f989c948b1.js",
16
+ "Dependencies.js": "/-/static/Dependencies.6126058572f989c948b1.js",
17
+ "Engines.js": "/-/static/Engines.6126058572f989c948b1.js",
18
+ "Engines.svg": "/-/static/737531cc93ceb77b82b1c2e074a2557a.svg",
19
+ "Engines.png": "/-/static/2939f26c293bff8f35ba87194742aea8.png",
20
+ "Dist.js": "/-/static/Dist.6126058572f989c948b1.js",
21
+ "Install.js": "/-/static/Install.6126058572f989c948b1.js",
22
+ "Install.svg": "/-/static/1f07aa4bad48cd09088966736d1ed121.svg",
23
+ "Repository.js": "/-/static/Repository.6126058572f989c948b1.js",
24
+ "Repository.png": "/-/static/728ff5a8e44d74cd0f2359ef0a9ec88a.png",
25
+ "vendors.js": "/-/static/vendors.6126058572f989c948b1.js",
26
+ "38.6126058572f989c948b1.js": "/-/static/38.6126058572f989c948b1.js",
27
+ "26.6126058572f989c948b1.js": "/-/static/26.6126058572f989c948b1.js",
28
+ "761.6126058572f989c948b1.js": "/-/static/761.6126058572f989c948b1.js",
29
+ "4743f1431b042843890a8644e89bb852.svg": "/-/static/4743f1431b042843890a8644e89bb852.svg",
30
+ "node.png": "/-/static/2939f26c293bff8f35ba87194742aea8.png",
31
+ "fonts/roboto-latin-900italic.woff": "/-/static/fonts/roboto-latin-900italic.woff",
32
+ "fonts/roboto-latin-300italic.woff": "/-/static/fonts/roboto-latin-300italic.woff",
33
+ "fonts/roboto-latin-500italic.woff": "/-/static/fonts/roboto-latin-500italic.woff",
34
+ "fonts/roboto-latin-400italic.woff": "/-/static/fonts/roboto-latin-400italic.woff",
35
+ "fonts/roboto-latin-100italic.woff": "/-/static/fonts/roboto-latin-100italic.woff",
36
+ "fonts/roboto-latin-700italic.woff": "/-/static/fonts/roboto-latin-700italic.woff",
37
+ "fonts/roboto-latin-500.woff": "/-/static/fonts/roboto-latin-500.woff",
38
+ "fonts/roboto-latin-900.woff": "/-/static/fonts/roboto-latin-900.woff",
39
+ "fonts/roboto-latin-100.woff": "/-/static/fonts/roboto-latin-100.woff",
40
+ "fonts/roboto-latin-700.woff": "/-/static/fonts/roboto-latin-700.woff",
41
+ "fonts/roboto-latin-300.woff": "/-/static/fonts/roboto-latin-300.woff",
42
+ "fonts/roboto-latin-400.woff": "/-/static/fonts/roboto-latin-400.woff",
43
+ "fonts/roboto-latin-900italic.woff2": "/-/static/fonts/roboto-latin-900italic.woff2",
44
+ "fonts/roboto-latin-300italic.woff2": "/-/static/fonts/roboto-latin-300italic.woff2",
45
+ "fonts/roboto-latin-400italic.woff2": "/-/static/fonts/roboto-latin-400italic.woff2",
46
+ "fonts/roboto-latin-500italic.woff2": "/-/static/fonts/roboto-latin-500italic.woff2",
47
+ "fonts/roboto-latin-700italic.woff2": "/-/static/fonts/roboto-latin-700italic.woff2",
48
+ "fonts/roboto-latin-100italic.woff2": "/-/static/fonts/roboto-latin-100italic.woff2",
49
+ "fonts/roboto-latin-500.woff2": "/-/static/fonts/roboto-latin-500.woff2",
50
+ "fonts/roboto-latin-700.woff2": "/-/static/fonts/roboto-latin-700.woff2",
51
+ "fonts/roboto-latin-100.woff2": "/-/static/fonts/roboto-latin-100.woff2",
52
+ "fonts/roboto-latin-300.woff2": "/-/static/fonts/roboto-latin-300.woff2",
53
+ "fonts/roboto-latin-400.woff2": "/-/static/fonts/roboto-latin-400.woff2",
54
+ "fonts/roboto-latin-900.woff2": "/-/static/fonts/roboto-latin-900.woff2",
55
+ "favicon.ico": "/-/static/favicon.ico",
56
+ "git.png": "/-/static/728ff5a8e44d74cd0f2359ef0a9ec88a.png",
57
+ "logo.svg": "/-/static/93df1ce974e744e7d98f5d842da74ba0.svg",
58
+ "pnpm.svg": "/-/static/81ca2d852b9bc86713fe993bf5c7104c.svg",
59
+ "yarn.svg": "/-/static/1f07aa4bad48cd09088966736d1ed121.svg",
60
+ "logo-black-and-white.svg": "/-/static/983328eca26f265748c004651ca0e6c8.svg",
61
+ "npm.svg": "/-/static/737531cc93ceb77b82b1c2e074a2557a.svg",
62
+ "index.html": "/-/static/index.html",
63
+ "package.svg": "/-/static/4743f1431b042843890a8644e89bb852.svg"
64
+ }
@@ -0,0 +1,106 @@
1
+ import express from 'express';
2
+ import { JSDOM } from 'jsdom';
3
+ import path from 'path';
4
+ import supertest from 'supertest';
5
+
6
+ import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
7
+ import { setup } from '@verdaccio/logger';
8
+
9
+ import { webMiddleware } from '../src';
10
+ import { getConf } from './_helper';
11
+
12
+ const pluginOptions = {
13
+ manifestFiles: {
14
+ js: ['runtime.js', 'vendors.js', 'main.js'],
15
+ },
16
+ staticPath: path.join(__dirname, 'static'),
17
+ manifest: require('./partials/manifest/manifest.json'),
18
+ };
19
+
20
+ const initializeServer = (configName: string, middlewares = {}) => {
21
+ const app = express();
22
+ app.use(webMiddleware(getConf(configName), middlewares, pluginOptions));
23
+ return app;
24
+ };
25
+
26
+ setup({});
27
+
28
+ describe('test web server', () => {
29
+ describe('render', () => {
30
+ describe('output', () => {
31
+ const render = async (config = 'default-test.yaml') => {
32
+ const response = await supertest(initializeServer(config))
33
+ .get('/')
34
+ .set('Accept', HEADERS.TEXT_HTML)
35
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
36
+ .expect(HTTP_STATUS.OK);
37
+ return new JSDOM(response.text, { runScripts: 'dangerously' });
38
+ };
39
+
40
+ test('should match render set ui properties', async () => {
41
+ const {
42
+ window: { __VERDACCIO_BASENAME_UI_OPTIONS },
43
+ } = await render('web.yaml');
44
+ expect(__VERDACCIO_BASENAME_UI_OPTIONS).toEqual(
45
+ expect.objectContaining({
46
+ showInfo: true,
47
+ showSettings: true,
48
+ showThemeSwitch: true,
49
+ showFooter: true,
50
+ showSearch: true,
51
+ showDownloadTarball: true,
52
+ darkMode: false,
53
+ url_prefix: '/prefix',
54
+ basename: '/prefix/',
55
+ primaryColor: '#ffffff',
56
+ // FIXME: mock these values, avoid random
57
+ // base: 'http://127.0.0.1:60864/prefix/',
58
+ // version: '6.0.0-6-next.28',
59
+ logoURI: '',
60
+ flags: { changePassword: true },
61
+ login: true,
62
+ pkgManagers: ['pnpm', 'yarn'],
63
+ title: 'verdaccio web',
64
+ scope: '@scope',
65
+ language: 'es-US',
66
+ })
67
+ );
68
+ });
69
+
70
+ test.todo('should default title');
71
+ test.todo('should need html cache');
72
+ });
73
+
74
+ describe('status', () => {
75
+ test('should return the http status 200 for root', async () => {
76
+ return supertest(await initializeServer('default-test.yaml'))
77
+ .get('/')
78
+ .set('Accept', HEADERS.TEXT_HTML)
79
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
80
+ .expect(HTTP_STATUS.OK);
81
+ });
82
+
83
+ test('should return the body for a package detail page', async () => {
84
+ return supertest(await initializeServer('default-test.yaml'))
85
+ .get('/-/web/section/some-package')
86
+ .set('Accept', HEADERS.TEXT_HTML)
87
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
88
+ .expect(HTTP_STATUS.OK);
89
+ });
90
+
91
+ test('should static file not found', async () => {
92
+ return supertest(await initializeServer('default-test.yaml'))
93
+ .get('/-/static/not-found.js')
94
+ .set('Accept', HEADERS.TEXT_HTML)
95
+ .expect(HTTP_STATUS.NOT_FOUND);
96
+ });
97
+
98
+ test('should static file found', async () => {
99
+ return supertest(await initializeServer('default-test.yaml'))
100
+ .get('/-/static/main.js')
101
+ .set('Accept', HEADERS.TEXT_HTML)
102
+ .expect(HTTP_STATUS.OK);
103
+ });
104
+ });
105
+ });
106
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ main: '';
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ 'vendors': '';
3
+ }
@@ -0,0 +1,74 @@
1
+ import template from '../src/middlewares/web/utils/template';
2
+
3
+ const manifest = require('./partials/manifest/manifest.json');
4
+
5
+ const exampleManifest = {
6
+ css: ['main.css'],
7
+ js: ['runtime.js', 'main.js'],
8
+ ico: '/static/foo.ico',
9
+ };
10
+
11
+ describe('template', () => {
12
+ test('custom render', () => {
13
+ expect(
14
+ template({ options: { base: 'http://domain.com' }, manifest: exampleManifest }, manifest)
15
+ ).toMatchSnapshot();
16
+ });
17
+
18
+ test('custom title', () => {
19
+ expect(
20
+ template(
21
+ { options: { base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest },
22
+ manifest
23
+ )
24
+ ).toMatchSnapshot();
25
+ });
26
+
27
+ test('custom title', () => {
28
+ expect(
29
+ template(
30
+ { options: { base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest },
31
+ manifest
32
+ )
33
+ ).toMatchSnapshot();
34
+ });
35
+
36
+ test('meta scripts', () => {
37
+ expect(
38
+ template(
39
+ {
40
+ options: { base: 'http://domain.com' },
41
+ metaScripts: [`<style>.someclass{font-size:10px;}</style>`],
42
+ manifest: exampleManifest,
43
+ },
44
+ manifest
45
+ )
46
+ ).toMatchSnapshot();
47
+ });
48
+
49
+ test('custom body after', () => {
50
+ expect(
51
+ template(
52
+ {
53
+ options: { base: 'http://domain.com' },
54
+ scriptsBodyAfter: [`<script src="foo"/>`],
55
+ manifest: exampleManifest,
56
+ },
57
+ manifest
58
+ )
59
+ ).toMatchSnapshot();
60
+ });
61
+
62
+ test('custom body before', () => {
63
+ expect(
64
+ template(
65
+ {
66
+ options: { base: 'http://domain.com' },
67
+ scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
68
+ manifest: exampleManifest,
69
+ },
70
+ manifest
71
+ )
72
+ ).toMatchSnapshot();
73
+ });
74
+ });
@@ -0,0 +1,13 @@
1
+ import { validatePrimaryColor } from '../src/middlewares/web/utils/web-utils';
2
+
3
+ describe('Utilities', () => {
4
+ describe('validatePrimaryColor', () => {
5
+ test('is valid', () => {
6
+ expect(validatePrimaryColor('#222222')).toEqual('#222222');
7
+ expect(validatePrimaryColor('#222fff')).toEqual('#222fff');
8
+ });
9
+ test('is invalid', () => {
10
+ expect(validatePrimaryColor('fff')).toBeUndefined();
11
+ });
12
+ });
13
+ });
package/tsconfig.json CHANGED
@@ -10,6 +10,12 @@
10
10
  {
11
11
  "path": "../auth"
12
12
  },
13
+ {
14
+ "path": "../core/url"
15
+ },
16
+ {
17
+ "path": "../core/core"
18
+ },
13
19
  {
14
20
  "path": "../logger/logger"
15
21
  },