UNPKG

3.3 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
5var _htmlBase = _interopRequireDefault(require("./html-base"));
6
7var exampleWindowVarPairs = [['__A__', {
8 a: "<script>alert('xss')</script>"
9}], ['__B__', 'plop'], ['__C__', true], ['__D__', 666]];
10var 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 <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>";
11var 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 <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
12var 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 <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
13var 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 <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
14var 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 <script src=\"/static/js/bundle.js\"></script>\n </body>\n</html>";
15test('htmlBase', function () {
16 expect((0, _htmlBase.default)({
17 windowVars: exampleWindowVarPairs
18 })).toBe(expectedWithVars);
19 expect((0, _htmlBase.default)({})).toBe(expectedWithoutVars);
20 expect((0, _htmlBase.default)({
21 appHtml: 'Hello'
22 })).toBe(expectedWithAppHtml);
23 expect((0, _htmlBase.default)({
24 css: 'body { color: red }'
25 })).toBe(expectedWithCss);
26 expect((0, _htmlBase.default)({
27 helmet: {
28 htmlAttributes: {
29 toString: function toString() {
30 return 'lang="en"';
31 }
32 },
33 bodyAttributes: {
34 toString: function toString() {
35 return 'foo="foo"';
36 }
37 },
38 title: {
39 toString: function toString() {
40 return '<title>hello</title>';
41 }
42 },
43 meta: {
44 toString: function toString() {
45 return '<meta />';
46 }
47 },
48 link: {
49 toString: function toString() {
50 return '<link />';
51 }
52 }
53 }
54 })).toBe(expectedWithHelmet);
55});
\No newline at end of file