-
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.
- Loading branch information
1 parent
a755671
commit e95afbd
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
packages/cli/test/cases/build.config.mode-mpa/build.config.mode-mpa.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,149 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood with mode setting in Greenwood config set to mpa. | ||
* | ||
* User Result | ||
* Should generate a bare bones Greenwood build with bundle JavaScript and routes. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* { | ||
* mode: 'mpa' | ||
* } | ||
* | ||
* User Workspace | ||
* Greenwood default w/ nested page | ||
* src/ | ||
* pages/ | ||
* about.md | ||
* index.md | ||
*/ | ||
const expect = require('chai').expect; | ||
const fs = require('fs'); | ||
const glob = require('glob-promise'); | ||
const { JSDOM } = require('jsdom'); | ||
const path = require('path'); | ||
const TestBed = require('../../../../../test/test-bed'); | ||
|
||
describe('Build Greenwood With: ', function() { | ||
const LABEL = 'Custom Mode'; | ||
let setup; | ||
|
||
before(async function() { | ||
setup = new TestBed(); | ||
|
||
const greenwoodRouterLibs = (await glob(`${process.cwd()}/packages/cli/src/lib/router.js`)).map((lib) => { | ||
return { | ||
dir: 'node_modules/@greenwood/cli/src/lib/', | ||
name: path.basename(lib) | ||
}; | ||
}); | ||
|
||
this.context = await setup.setupTestBed(__dirname, [ | ||
...greenwoodRouterLibs | ||
]); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
|
||
before(async function() { | ||
await setup.runGreenwoodCommand('build'); | ||
}); | ||
|
||
describe('MPA (Multi Page Application)', function() { | ||
let dom; | ||
let aboutDom; | ||
let partials; | ||
|
||
before(async function() { | ||
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'index.html')); | ||
aboutDom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'about/index.html')); | ||
partials = await glob(`${this.context.publicDir}/_routes/**/*.html`); | ||
}); | ||
|
||
it('should have one <script> tag in the <head> for the router', function() { | ||
const scriptTags = dom.window.document.querySelectorAll('head > script[type]'); | ||
|
||
expect(scriptTags.length).to.be.equal(1); | ||
expect(scriptTags[0].href).to.be.contain(/router.*.js/); | ||
expect(scriptTags[0].type).to.be.equal('module'); | ||
}); | ||
|
||
it('should have one router.js file in the output directory', function() { | ||
const routerJsFiles = fs.readdirSync(this.context.publicDir).filter(file => file.indexOf('router') === 0); | ||
|
||
expect(routerJsFiles.length).to.be.equal(1); | ||
}); | ||
|
||
it('should have one expected inline <script> tag in the <head> for router global variables', function() { | ||
const inlineScriptTags = Array.from(dom.window.document.querySelectorAll('head > script')) | ||
.filter(tag => !tag.type); | ||
|
||
expect(inlineScriptTags.length).to.be.equal(1); | ||
expect(inlineScriptTags[0].textContent).to.contain('window.__greenwood = window.__greenwood || {};'); | ||
expect(inlineScriptTags[0].textContent).to.contain('window.__greenwood.currentTemplate = "page"'); | ||
}); | ||
|
||
it('should have one <router-outlet> tag in the <body> for the content', function() { | ||
const routerOutlets = dom.window.document.querySelectorAll('body > router-outlet'); | ||
|
||
expect(routerOutlets.length).to.be.equal(1); | ||
}); | ||
|
||
it('should have two <greenwood-route> tags in the <body> for the content', function() { | ||
const routeTags = dom.window.document.querySelectorAll('body > greenwood-route'); | ||
|
||
expect(routeTags.length).to.be.equal(2); | ||
}); | ||
|
||
it('should have the expected properties for each <greenwood-route> tag for the about page', function() { | ||
const aboutRouteTag = Array | ||
.from(dom.window.document.querySelectorAll('body > greenwood-route')) | ||
.filter(tag => tag.dataset.route === '/about/'); | ||
const dataset = aboutRouteTag[0].dataset; | ||
|
||
expect(aboutRouteTag.length).to.be.equal(1); | ||
expect(dataset.template).to.be.equal('test'); | ||
expect(dataset.key).to.be.equal('/_routes/about/index.html'); | ||
}); | ||
|
||
it('should have the expected properties for each <greenwood-route> tag for the home page', function() { | ||
const aboutRouteTag = Array | ||
.from(dom.window.document.querySelectorAll('body > greenwood-route')) | ||
.filter(tag => tag.dataset.route === '/'); | ||
const dataset = aboutRouteTag[0].dataset; | ||
|
||
expect(aboutRouteTag.length).to.be.equal(1); | ||
expect(dataset.template).to.be.equal('page'); | ||
expect(dataset.key).to.be.equal('/_routes/index.html'); | ||
}); | ||
|
||
it('should have the expected number of _route partials in the output directory for each page', function() { | ||
expect(partials.length).to.be.equal(2); | ||
}); | ||
|
||
it('should have the expected partial output to match the contents of the page in the <router-outlet> tag in the <body>', function() { | ||
const aboutPartial = fs.readFileSync(path.join(this.context.publicDir, '_routes/about/index.html'), 'utf-8'); | ||
const aboutRouterOutlet = aboutDom.window.document.querySelectorAll('body > router-outlet')[0]; | ||
|
||
expect(aboutRouterOutlet.innerHTML).to.contain(aboutPartial); | ||
}); | ||
|
||
it('should have the expected partial output to match the contents of the about in the <router-outlet> tag in the <body>', function() { | ||
const homePartial = fs.readFileSync(path.join(this.context.publicDir, '_routes/index.html'), 'utf-8'); | ||
const homeRouterOutlet = dom.window.document.querySelectorAll('body > router-outlet')[0]; | ||
|
||
expect(homeRouterOutlet.innerHTML).to.contain(homePartial); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
after(function() { | ||
setup.teardownTestBed(); | ||
}); | ||
|
||
}); |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/build.config.mode-mpa/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 @@ | ||
module.exports = { | ||
mode: 'mpa' | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/cli/test/cases/build.config.mode-mpa/src/pages/about.md
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 @@ | ||
--- | ||
template: test | ||
--- | ||
|
||
### Greenwood | ||
|
||
This is the about page built by Greenwood. |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/build.config.mode-mpa/src/pages/index.md
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 @@ | ||
### Greenwood | ||
|
||
This is the home page built by Greenwood. |