|
| 1 | +/* eslint-env node */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const expect = require('chai').expect; |
| 5 | +const helpers = require('broccoli-test-helper'); |
| 6 | +const createBuilder = helpers.createBuilder; |
| 7 | +const createTempDir = helpers.createTempDir; |
| 8 | +const HTMLWriter = require('../lib/broccoli/html-writer'); |
| 9 | + |
| 10 | +describe('HTML Writer', function () { |
| 11 | + let input; |
| 12 | + let output; |
| 13 | + let subject; |
| 14 | + |
| 15 | + beforeEach(async function () { |
| 16 | + input = await createTempDir(); |
| 17 | + subject = new HTMLWriter(input.path(), { |
| 18 | + fastbootConfig: { |
| 19 | + 'basic-app': { |
| 20 | + modulePrefix: 'basic-app', |
| 21 | + environment: 'development', |
| 22 | + rootURL: '/', |
| 23 | + locationType: 'auto', |
| 24 | + EmberENV: { |
| 25 | + FEATURES: {}, |
| 26 | + EXTEND_PROTOTYPES: { |
| 27 | + Date: false, |
| 28 | + }, |
| 29 | + _APPLICATION_TEMPLATE_WRAPPER: false, |
| 30 | + _DEFAULT_ASYNC_OBSERVERS: true, |
| 31 | + _JQUERY_INTEGRATION: false, |
| 32 | + _TEMPLATE_ONLY_GLIMMER_COMPONENTS: true, |
| 33 | + }, |
| 34 | + APP: { |
| 35 | + name: 'basic-app', |
| 36 | + version: '0.1.0+aec2e45f', |
| 37 | + autoboot: false, |
| 38 | + }, |
| 39 | + fastboot: { |
| 40 | + hostWhitelist: [ |
| 41 | + 'example.com', |
| 42 | + 'subdomain.example.com', |
| 43 | + '/localhost:\\d+/', |
| 44 | + ], |
| 45 | + }, |
| 46 | + exportApplicationGlobal: true, |
| 47 | + }, |
| 48 | + 'example-addon': { |
| 49 | + foo: 'bar', |
| 50 | + }, |
| 51 | + }, |
| 52 | + appName: 'basic-app', |
| 53 | + manifest: { |
| 54 | + appFiles: [ |
| 55 | + 'assets/basic-app.js', |
| 56 | + 'assets/basic-app-fastboot.js', |
| 57 | + 'example-addon/bar.js', |
| 58 | + ], |
| 59 | + vendorFiles: [ |
| 60 | + 'example-addon/foo.js', |
| 61 | + 'assets/vendor.js', |
| 62 | + 'assets/auto-import-fastboot.js', |
| 63 | + 'ember-fetch/fetch-fastboot.js', |
| 64 | + ], |
| 65 | + htmlFile: 'index.html', |
| 66 | + }, |
| 67 | + appJsPath: '/assets/basic-app.js', |
| 68 | + outputPaths: { |
| 69 | + app: { |
| 70 | + css: { |
| 71 | + app: '/assets/basic-app.css', |
| 72 | + }, |
| 73 | + js: '/assets/basic-app.js', |
| 74 | + html: 'index.html', |
| 75 | + }, |
| 76 | + tests: { |
| 77 | + js: '/assets/tests.js', |
| 78 | + }, |
| 79 | + vendor: { |
| 80 | + css: '/assets/vendor.css', |
| 81 | + js: '/assets/vendor.js', |
| 82 | + }, |
| 83 | + testSupport: { |
| 84 | + css: '/assets/test-support.css', |
| 85 | + js: { |
| 86 | + testSupport: '/assets/test-support.js', |
| 87 | + testLoader: '/assets/test-loader.js', |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }); |
| 92 | + output = createBuilder(subject); |
| 93 | + }); |
| 94 | + |
| 95 | + afterEach(async function () { |
| 96 | + await input.dispose(); |
| 97 | + await output.dispose(); |
| 98 | + }); |
| 99 | + |
| 100 | + it('it writes correct base page HTML', async function () { |
| 101 | + input.write({ |
| 102 | + 'index.html': `<!DOCTYPE html> |
| 103 | +<html> |
| 104 | + <head> |
| 105 | + <meta charset="utf-8"> |
| 106 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 107 | + <title>BasicApp</title> |
| 108 | + <meta name="description" content=""> |
| 109 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 110 | +
|
| 111 | +
|
| 112 | +<meta name="basic-app/config/environment" content="%7B%22modulePrefix%22%3A%22basic-app%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_DEFAULT_ASYNC_OBSERVERS%22%3Atrue%2C%22_JQUERY_INTEGRATION%22%3Afalse%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22name%22%3A%22basic-app%22%2C%22version%22%3A%220.1.0%2Baec2e45f%22%7D%2C%22fastboot%22%3A%7B%22hostWhitelist%22%3A%5B%22example.com%22%2C%22subdomain.example.com%22%2C%22%2Flocalhost%3A%5C%5Cd%2B%2F%22%5D%7D%2C%22exportApplicationGlobal%22%3Atrue%7D" /> |
| 113 | +<!-- EMBER_CLI_FASTBOOT_TITLE --><!-- EMBER_CLI_FASTBOOT_HEAD --> |
| 114 | +
|
| 115 | + <link integrity="" rel="stylesheet" href="/assets/vendor.css"> |
| 116 | + <link integrity="" rel="stylesheet" href="/assets/basic-app.css"> |
| 117 | +
|
| 118 | +
|
| 119 | + </head> |
| 120 | + <body> |
| 121 | + <!-- EMBER_CLI_FASTBOOT_BODY --> |
| 122 | +
|
| 123 | + <script src="/assets/vendor.js"></script> |
| 124 | + <script src="/assets/basic-app.js"></script> |
| 125 | +
|
| 126 | +
|
| 127 | + </body> |
| 128 | +</html>`, |
| 129 | + }); |
| 130 | + |
| 131 | + await output.build(); |
| 132 | + |
| 133 | + expect( |
| 134 | + output.read()['index.html'].replace(/(^[ \t]*\n)/gm, '') |
| 135 | + ).to.deep.equal( |
| 136 | + `<!DOCTYPE html><html><head> |
| 137 | + <meta charset="utf-8"> |
| 138 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 139 | + <title>BasicApp</title> |
| 140 | + <meta name="description" content=""> |
| 141 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 142 | +
|
| 143 | +
|
| 144 | +<meta name="basic-app/config/environment" content="%7B%22modulePrefix%22%3A%22basic-app%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_DEFAULT_ASYNC_OBSERVERS%22%3Atrue%2C%22_JQUERY_INTEGRATION%22%3Afalse%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22name%22%3A%22basic-app%22%2C%22version%22%3A%220.1.0%2Baec2e45f%22%7D%2C%22fastboot%22%3A%7B%22hostWhitelist%22%3A%5B%22example.com%22%2C%22subdomain.example.com%22%2C%22%2Flocalhost%3A%5C%5Cd%2B%2F%22%5D%7D%2C%22exportApplicationGlobal%22%3Atrue%7D"> |
| 145 | +<!-- EMBER_CLI_FASTBOOT_TITLE --><!-- EMBER_CLI_FASTBOOT_HEAD --> |
| 146 | +
|
| 147 | + <link integrity="" rel="stylesheet" href="/assets/vendor.css"> |
| 148 | + <link integrity="" rel="stylesheet" href="/assets/basic-app.css"> |
| 149 | +
|
| 150 | +
|
| 151 | + <meta name="basic-app/config/fastboot-environment" content="%7B%22modulePrefix%22%3A%22basic-app%22%2C%22environment%22%3A%22development%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_DEFAULT_ASYNC_OBSERVERS%22%3Atrue%2C%22_JQUERY_INTEGRATION%22%3Afalse%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22name%22%3A%22basic-app%22%2C%22version%22%3A%220.1.0%2Baec2e45f%22%2C%22autoboot%22%3Afalse%7D%2C%22fastboot%22%3A%7B%22hostWhitelist%22%3A%5B%22example.com%22%2C%22subdomain.example.com%22%2C%22%2Flocalhost%3A%5C%5Cd%2B%2F%22%5D%7D%2C%22exportApplicationGlobal%22%3Atrue%7D"> |
| 152 | +<meta name="example-addon/config/fastboot-environment" content="%7B%22foo%22%3A%22bar%22%7D"> |
| 153 | +
|
| 154 | +</head> |
| 155 | + <body> |
| 156 | + <!-- EMBER_CLI_FASTBOOT_BODY --> |
| 157 | +
|
| 158 | + <script src="/assets/vendor.js"></script> |
| 159 | + <fastboot-script src="example-addon/foo.js"></fastboot-script> |
| 160 | +<fastboot-script src="assets/auto-import-fastboot.js"></fastboot-script> |
| 161 | +<fastboot-script src="ember-fetch/fetch-fastboot.js"></fastboot-script> |
| 162 | +<fastboot-script src="assets/basic-app-fastboot.js"></fastboot-script> |
| 163 | +<fastboot-script src="example-addon/bar.js"></fastboot-script> |
| 164 | +<script src="/assets/basic-app.js"></script> |
| 165 | +
|
| 166 | +</body></html>`.replace(/(^[ \t]*\n)/gm, '') |
| 167 | + ); |
| 168 | + }); |
| 169 | +}); |
0 commit comments