UNPKG

sharyn

Version:

Combines all the other packages under one.

59 lines (56 loc) 3.85 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault"); var _htmlBase = _interopRequireDefault(require("./html-base")); var exampleWindowVarPairs = [['__A__', { a: "<script>alert('xss')</script>" }], ['__B__', 'plop'], ['__C__', true], ['__D__', 666]]; 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>"; 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>"; 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>"; 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>"; 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>"; 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>"; test('htmlBase', function () { expect((0, _htmlBase.default)({ windowVars: exampleWindowVarPairs })).toBe(expectedWithVars); expect((0, _htmlBase.default)({})).toBe(expectedWithoutVars); expect((0, _htmlBase.default)({ swPath: '/sw.js' })).toBe(expectedWithSwPath); expect((0, _htmlBase.default)({ appHtml: 'Hello' })).toBe(expectedWithAppHtml); expect((0, _htmlBase.default)({ css: 'body { color: red }' })).toBe(expectedWithCss); expect((0, _htmlBase.default)({ helmet: { htmlAttributes: { toString: function toString() { return 'lang="en"'; } }, bodyAttributes: { toString: function toString() { return 'foo="foo"'; } }, title: { toString: function toString() { return '<title>hello</title>'; } }, meta: { toString: function toString() { return '<meta />'; } }, link: { toString: function toString() { return '<link />'; } } } })).toBe(expectedWithHelmet); });