-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug/issue 1072 serve command not serving prerendered ssr content (#1073)
* fix serving of prerendered SSR pages for serve command * improve detection of hybrid router for serve command and add static export SSR serve command specs * nest spec setup inside describe block
- Loading branch information
1 parent
59b4e3b
commit 15dac4d
Showing
25 changed files
with
631 additions
and
18 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
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 |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
* greenwood build | ||
* | ||
* User Config | ||
* None | ||
* { | ||
* prerender: true | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
|
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
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/serve.default.ssr-prerender/greenwood.config.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,3 @@ | ||
export default { | ||
prerender: true | ||
}; |
118 changes: 118 additions & 0 deletions
118
packages/cli/test/cases/serve.default.ssr-prerender/serve.default.ssr-prerender.spec.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,118 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood with an SSR route that is prerender using configuration. | ||
* | ||
* User Result | ||
* Should generate a bare bones Greenwood build for hosting a prerender SSR application. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* { | ||
* prerender: true | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* footer.js | ||
* pages/ | ||
* index.js | ||
* templates/ | ||
* app.html | ||
*/ | ||
import chai from 'chai'; | ||
import { JSDOM } from 'jsdom'; | ||
import path from 'path'; | ||
import { getSetupFiles, getOutputTeardownFiles } from '../../../../../test/utils.js'; | ||
import request from 'request'; | ||
import { runSmokeTest } from '../../../../../test/smoke-test.js'; | ||
import { Runner } from 'gallinago'; | ||
import { fileURLToPath, URL } from 'url'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Serve Greenwood With: ', function() { | ||
const LABEL = 'A Server Rendered Application (SSR) with prerender configuration'; | ||
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); | ||
const hostname = 'http://127.0.0.1:8080'; | ||
const outputPath = fileURLToPath(new URL('.', import.meta.url)); | ||
let runner; | ||
|
||
before(async function() { | ||
this.context = { | ||
publicDir: path.join(outputPath, 'public'), | ||
hostname | ||
}; | ||
runner = new Runner(); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
|
||
before(async function() { | ||
await runner.setup(outputPath, getSetupFiles(outputPath)); | ||
|
||
return new Promise(async (resolve) => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, 10000); | ||
|
||
await runner.runCommand(cliPath, 'serve'); | ||
}); | ||
}); | ||
|
||
runSmokeTest(['public', 'index', 'serve'], LABEL); | ||
|
||
describe('Serve command that prerenders SSR pages', function() { | ||
let dom; | ||
let response; | ||
|
||
before(async function() { | ||
return new Promise((resolve, reject) => { | ||
request.get(`${hostname}/`, (err, res, body) => { | ||
if (err) { | ||
reject(); | ||
} | ||
|
||
response = res; | ||
response.body = body; | ||
dom = new JSDOM(body); | ||
|
||
resolve(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Serve command with HTML response for the home page', function() { | ||
it('should return a 200 status', function(done) { | ||
expect(response.statusCode).to.equal(200); | ||
done(); | ||
}); | ||
|
||
it('should return the correct content type', function(done) { | ||
expect(response.headers['content-type']).to.contain('text/html'); | ||
done(); | ||
}); | ||
|
||
it('should return a response body', function(done) { | ||
expect(response.body).to.not.be.undefined; | ||
done(); | ||
}); | ||
|
||
it('should have the expected output for the page', function() { | ||
const headings = dom.window.document.querySelectorAll('body > h1'); | ||
|
||
expect(headings.length).to.equal(1); | ||
expect(headings[0].textContent).to.equal('This is the home page.'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
runner.teardown(getOutputTeardownFiles(outputPath)); | ||
runner.stopCommand(); | ||
}); | ||
|
||
}); |
16 changes: 16 additions & 0 deletions
16
packages/cli/test/cases/serve.default.ssr-prerender/src/components/footer.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,16 @@ | ||
const template = document.createElement('template'); | ||
|
||
template.innerHTML = '<footer>This is the footer component.</footer>'; | ||
|
||
export default class FooterComponent extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
|
||
connectedCallback() { | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
} | ||
|
||
customElements.define('app-footer', FooterComponent); |
7 changes: 7 additions & 0 deletions
7
packages/cli/test/cases/serve.default.ssr-prerender/src/pages/index.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,7 @@ | ||
export default class HomePage extends HTMLElement { | ||
connectedCallback() { | ||
this.innerHTML = ` | ||
<h1>This is the home page.</h1> | ||
`; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/cli/test/cases/serve.default.ssr-prerender/src/templates/app.html
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" prefix="og:http://ogp.me/ns#"> | ||
<head> | ||
<title>Default Title</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<script type="module" src="/components/footer.js"></script> | ||
</head> | ||
<body> | ||
<app-footer></app-footer> | ||
<page-outlet></page-outlet> | ||
</body> | ||
</html> |
6 changes: 6 additions & 0 deletions
6
packages/cli/test/cases/serve.default.ssr-static-export/package.json
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 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"lit": "^2.0.0" | ||
} | ||
} |
Oops, something went wrong.