-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preload scripts and load styles in <head> (#1659)
- Loading branch information
1 parent
cf64c59
commit 94a60ac
Showing
10 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
|
||
const ReserveSpot = (props, context) => { | ||
if (props.saveId) { | ||
const spot = context.output.reserve(); | ||
context.user[props.saveId] = spot; | ||
} | ||
}; | ||
|
||
module.exports = ReserveSpot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"use strict"; | ||
|
||
const { load } = require("../../lib"); | ||
const utils = require("../../lib/util"); | ||
const Path = require("path"); | ||
const reserveSpot = require("../../lib/ReserveSpot"); | ||
const RenderOutput = require("electrode-react-webapp/lib/render-output"); | ||
|
||
describe("load", function () { | ||
const statsPath = Path.join(__dirname, "../data/dev-stats.json"); | ||
const { assets } = utils.loadAssetsFromStats(statsPath); | ||
let context; | ||
let setUpContext; | ||
let props; | ||
|
||
beforeEach(() => { | ||
setUpContext = { | ||
routeOptions: { | ||
cdn: {}, | ||
__internals: { | ||
assets | ||
} | ||
} | ||
}; | ||
context = { | ||
user: { | ||
request: { app: {} }, | ||
assets, | ||
includedBundles: {} | ||
}, | ||
transform: x => x | ||
}; | ||
props = { | ||
props: { | ||
serverSideRendering: false | ||
} | ||
}; | ||
utils.resetCdn(); | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.NODE_ENV; | ||
delete process.env.APP_SRC_DIR; | ||
}); | ||
|
||
it("should load bundles for the subapp", done => { | ||
process.env.APP_SRC_DIR = "test/subapps"; | ||
const loadToken = load(setUpContext, { props: { name: "mainbody" } }); | ||
|
||
context.send = results => { | ||
expect(results).to.not.be.empty; | ||
expect(context.user.includedBundles).to.include({ mainbody: true }); | ||
expect(results).to.include(`<script src="mainbody.bundle.dev.js" async></script>`); | ||
expect(results).to.include( | ||
`<script src="ae56dc06d35e1170d047.vendors~280289005828299c685d173f73011e79.js" async></script>` | ||
); | ||
expect(context.user.headEntries).to.not.be.ok; | ||
done(); | ||
}; | ||
context.output = new RenderOutput(context); | ||
|
||
loadToken.process(context, props); | ||
context.output.close(); | ||
}); | ||
|
||
it("should load preload tags for scripts", done => { | ||
process.env.APP_SRC_DIR = "test/subapps"; | ||
const loadToken = load(setUpContext, { props: { name: "mainbody" } }); | ||
|
||
context.send = results => { | ||
expect(results).to.not.be.empty; | ||
expect(results).to.include(`<link rel="preload" href="mainbody.bundle.dev.js" as="script">`); | ||
expect(results).to.include(`<script src="mainbody.bundle.dev.js" async></script>`); | ||
expect(context.user.includedBundles).to.include({ mainbody: true }); | ||
done(); | ||
}; | ||
context.output = new RenderOutput(context); | ||
reserveSpot({ saveId: "headEntries" }, context); | ||
|
||
loadToken.process(context, props); | ||
context.output.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
foo: () => 123 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
name: "mainbody" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
name: "mainbody", | ||
subAppDir: "Subapp1/src", | ||
entry: "index.js", | ||
serverEntry: "server.js" | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/subapp-web/test/subapps/subapp1/src/subapp-manifest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
name: "mainbody", | ||
subAppDir: "subapp1/src", | ||
entry: "index.js", | ||
serverEntry: "server.js" | ||
}; |