Skip to content

Commit

Permalink
Merge pull request #183 from francois2metz/fix-ember4
Browse files Browse the repository at this point in the history
Insert the global ember import on production build
  • Loading branch information
shilman authored Aug 16, 2023
2 parents 27bf1b4 + 57ab785 commit 33cb2b2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function generatePreviewHead(parsedConfig) {
continue;
}
doc.push(`<${key} ${objectToHTMLAttributes(value)}></${key}>`);
if(value.src.indexOf('assets/vendor.js') > -1) {
if(value.src.match(/assets\/vendor[^.]*\.js/)) {
// make sure we push this right after vendor to ensure the application does not bind to the window.
doc.push('<script>window.Ember = require("ember").default; runningTests = true; Ember.testing=true;</script>');
}
Expand Down
10 changes: 10 additions & 0 deletions node-tests/__snapshots__/util.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ exports[`util @generatePreviewHead should work with file created with \`ember bu
<script src=\\"./assets/component.js\\" type=\\"module\\"></script>"
`;
exports[`util @generatePreviewHead should work with file created with \`ember build\` in production env 1`] = `
"<!-- This file is auto-generated by ember-cli-storybook -->
<meta name=\\"before-storybook/config/environment\\" content=\\"%7B%22modulePrefix%22%3A%22before-storybook%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22history%22%2C%22EmberENV%22%3A%7B%22EXTEND_PROTOTYPES%22%3Afalse%2C%22FEATURES%22%3A%7B%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%22before-storybook%22%2C%22version%22%3A%220.0.0%22%7D%7D\\" />
<link rel=\\"stylesheet\\" href=\\"./assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css\\" />
<link rel=\\"stylesheet\\" href=\\"./assets/before-storybook-d41d8cd98f00b204e9800998ecf8427e.css\\" />
<script src=\\"./assets/vendor-b6ca89ba21b4a11ce607688b017119f0.js\\"></script>
<script>window.Ember = require(\\"ember\\").default; runningTests = true; Ember.testing=true;</script>
<script src=\\"./assets/before-storybook-0c543b7d02d9385b2e4f5e2f3aab96f3.js\\"></script>"
`;
exports[`util @generatePreviewHead should work with file created with \`ember serve\` (should append livereload pointing at serve instance) 1`] = `
"<!-- This file is auto-generated by ember-cli-storybook -->
<meta name=\\"storybook-ember-3-1/config/environment\\" content=\\"%7B%22modulePrefix%22%3A%22storybook-ember-3-1%22%2C%22environment%22%3A%22test%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22none%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%7D%2C%22APP%22%3A%7B%22LOG_ACTIVE_GENERATION%22%3Afalse%2C%22LOG_VIEW_LOOKUPS%22%3Afalse%2C%22rootElement%22%3A%22%23ember-testing%22%2C%22autoboot%22%3Afalse%2C%22name%22%3A%22storybook-ember-3-1%22%2C%22version%22%3A%220.0.0+eebe77e5%22%7D%2C%22exportApplicationGlobal%22%3Atrue%7D\\" />
Expand Down
25 changes: 25 additions & 0 deletions node-tests/fixtures/build-production.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>BeforeStorybook</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="before-storybook/config/environment" content="%7B%22modulePrefix%22%3A%22before-storybook%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22history%22%2C%22EmberENV%22%3A%7B%22EXTEND_PROTOTYPES%22%3Afalse%2C%22FEATURES%22%3A%7B%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%22before-storybook%22%2C%22version%22%3A%220.0.0%22%7D%7D" />

<link integrity="" rel="stylesheet" href="/assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css">
<link integrity="" rel="stylesheet" href="/assets/before-storybook-d41d8cd98f00b204e9800998ecf8427e.css">


</head>
<body>


<script src="/assets/vendor-b6ca89ba21b4a11ce607688b017119f0.js" integrity="sha256-xEnKGeXv/szEZUKPrUWXMa+3hMTjDsHB4DTnBC+slPQ= sha512-SoY3kNC+Rb9e9q/W6I0dTCBxrirj4HI045d5qDjHNdtJX/FTFyVUuxMUjcBG4EexVbVWq/+mVfsnG3VVtdy0Zg==" ></script>
<script src="/assets/before-storybook-0c543b7d02d9385b2e4f5e2f3aab96f3.js" integrity="sha256-OdVFz9KJr+mIemcF6IFQqLplshzK/XWLptwgYH2f6gg= sha512-25iPzuW+zrG6zEdSy5uwSU9BnixYbDGiCpMrFoIt+JYa/nG9+K2hxbTT1CQ9xi85izxyzvTwtPTYiJoTrrSQUQ==" ></script>


</body>
</html>
8 changes: 8 additions & 0 deletions node-tests/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ Object {
expect(generatePreviewHead(parse(fileContent))).toMatchSnapshot()
})

it('should work with file created with `ember build` in production env', () => {
expect.assertions(1);

const fileContent = fs.readFileSync(path.resolve(__dirname, 'fixtures', 'build-production.html'), 'utf8');

expect(generatePreviewHead(parse(fileContent))).toMatchSnapshot()
})

it('should work with file created with `ember serve` (should append livereload pointing at serve instance)', () => {
expect.assertions(1);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"test:ember-compatibility": "ember try:each"
},
"devDependencies": {
"@embroider/test-setup": "^1.8.3",
"@ember/optional-features": "^1.3.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.8.0",
"@embroider/test-setup": "^2.0.2",
"babel-eslint": "^10.1.0",
Expand Down

0 comments on commit 33cb2b2

Please sign in to comment.