1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
4 |
|
5 | var _htmlBase = _interopRequireDefault(require("./html-base"));
|
6 |
|
7 | var exampleWindowVarPairs = [['__A__', {
|
8 | a: "<script>alert('xss')</script>"
|
9 | }], ['__B__', 'plop'], ['__C__', true], ['__D__', 666]];
|
10 | var expectedWithVars = "<!doctype html>\n<html >\n <head>\n <meta charset=\"utf-8\">\n\n\n\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n\n </head>\n <body >\n <div id=\"app\"></div>\n\n <script>window.__A__ = {\"a\":\"\\u003Cscript\\u003Ealert('xss')\\u003C\\u002Fscript\\u003E\"}</script>\n <script>window.__B__ = \"plop\"</script>\n <script>window.__C__ = true</script>\n <script>window.__D__ = 666</script>\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
11 | var expectedWithSwPath = "<!doctype html>\n<html >\n <head>\n <meta charset=\"utf-8\">\n\n\n\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n\n </head>\n <body >\n <div id=\"app\"></div>\n <script>navigator.serviceWorker && window.addEventListener('load', () => navigator.serviceWorker.register('/sw.js'))</script>\n\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
12 | var expectedWithoutVars = "<!doctype html>\n<html >\n <head>\n <meta charset=\"utf-8\">\n\n\n\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n\n </head>\n <body >\n <div id=\"app\"></div>\n\n\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
13 | var expectedWithAppHtml = "<!doctype html>\n<html >\n <head>\n <meta charset=\"utf-8\">\n\n\n\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n\n </head>\n <body >\n <div id=\"app\">Hello</div>\n\n\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
14 | var expectedWithCss = "<!doctype html>\n<html >\n <head>\n <meta charset=\"utf-8\">\n\n\n\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n <style id=\"jss-ssr\">body{color:red}</style>\n </head>\n <body >\n <div id=\"app\"></div>\n\n\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
15 | var expectedWithHelmet = "<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n<title>hello</title>\n<meta />\n<link />\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" />\n\n </head>\n <body foo=\"foo\">\n <div id=\"app\"></div>\n\n\n <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
|
16 | test('htmlBase', function () {
|
17 | expect((0, _htmlBase.default)({
|
18 | windowVars: exampleWindowVarPairs
|
19 | })).toBe(expectedWithVars);
|
20 | expect((0, _htmlBase.default)({})).toBe(expectedWithoutVars);
|
21 | expect((0, _htmlBase.default)({
|
22 | swPath: '/sw.js'
|
23 | })).toBe(expectedWithSwPath);
|
24 | expect((0, _htmlBase.default)({
|
25 | appHtml: 'Hello'
|
26 | })).toBe(expectedWithAppHtml);
|
27 | expect((0, _htmlBase.default)({
|
28 | css: 'body { color: red }'
|
29 | })).toBe(expectedWithCss);
|
30 | expect((0, _htmlBase.default)({
|
31 | helmet: {
|
32 | htmlAttributes: {
|
33 | toString: function toString() {
|
34 | return 'lang="en"';
|
35 | }
|
36 | },
|
37 | bodyAttributes: {
|
38 | toString: function toString() {
|
39 | return 'foo="foo"';
|
40 | }
|
41 | },
|
42 | title: {
|
43 | toString: function toString() {
|
44 | return '<title>hello</title>';
|
45 | }
|
46 | },
|
47 | meta: {
|
48 | toString: function toString() {
|
49 | return '<meta />';
|
50 | }
|
51 | },
|
52 | link: {
|
53 | toString: function toString() {
|
54 | return '<link />';
|
55 | }
|
56 | }
|
57 | }
|
58 | })).toBe(expectedWithHelmet);
|
59 | }); |
\ | No newline at end of file |