Skip to content

Commit

Permalink
fixed absolute path config bug and improved workspace related specs (#82
Browse files Browse the repository at this point in the history
)

* fixed absolute path config bug and improved workspace related specs

* fix specs and bump coverage

* validate final workspace choice
  • Loading branch information
thescientist13 authored May 16, 2019
1 parent 344319d commit 3cd967a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 8 deletions.
2 changes: 1 addition & 1 deletion nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
checkCoverage: true,

statements: 85,
branches: 65,
branches: 70,
functions: 90,
lines: 85,

Expand Down
10 changes: 7 additions & 3 deletions packages/cli/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = readAndMergeConfig = async() => {
let customConfig = JSON.parse(JSON.stringify(defaultConfig));

if (fs.existsSync(path.join(process.cwd(), 'greenwood.config.js'))) {
const userCfgFile = require(path.join(process.cwd(), 'greenwood.config.js'));

const userCfgFile = require(path.join(process.cwd(), 'greenwood.config.js'));
const { workspace, devServer, publicPath, title, meta } = userCfgFile;

// workspace validation
Expand All @@ -36,7 +35,12 @@ module.exports = readAndMergeConfig = async() => {
customConfig.workspace = path.join(process.cwd(), workspace);
}

if (!fs.existsSync(workspace)) {
if (path.isAbsolute(workspace)) {
// use the users provided path
customConfig.workspace = workspace;
}

if (!fs.existsSync(customConfig.workspace)) {
reject('Error: greenwood.config.js workspace doesn\'t exist! \n' +
'common issues to check might be: \n' +
'- typo in your workspace directory name, or in greenwood.config.js \n' +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Use Case
* Run Greenwood build command with a bad value for workspace directory (that doesn't exist) in a custom config.
*
* User Result
* Should throw an error.
*
* User Command
* greenwood build
*
* User Config
* {
* workspace: path.join(__dirname, 'noop')
* }
*
* User Workspace
* Greenwood default
*/
const expect = require('chai').expect;
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', () => {
let setup;

before(async () => {
setup = new TestBed();
setup.setupTestBed(__dirname);
});

describe('Custom Configuration with a bad value (absolute path) for Workspace', () => {
it('should throw an error that workspace path must exist', async () => {
try {
await setup.runGreenwoodCommand('build');
} catch (err) {
expect(err).to.contain('greenwood.config.js workspace doesn\'t exist!');
}
});
});

after(function() {
setup.teardownTestBed();
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path');

module.exports = {
workspace: path.join(__dirname, 'noop')
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Use Case
* Run Greenwood build command with custom workspace directory and Greenwood defaults.
* Run Greenwood build command with custom workspace directory (absolute path) and custom pages.
*
* User Result
* Should generate a bare bones Greenwood build from www directory.
* Should generate a Greenwood build from www directory with about and index pages.
*
* User Command
* greenwood build
Expand All @@ -14,8 +14,15 @@
* }
*
* User Workspace
* Greenwood default
* www/
* pages/
* about.md
* index.md
*/
const expect = require('chai').expect;
const fs = require('fs');
const { JSDOM } = require('jsdom');
const path = require('path');
const runSmokeTest = require('../../smoke-test');
const TestBed = require('../../test-bed');

Expand All @@ -32,7 +39,32 @@ describe('Build Greenwood With: ', function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});
runSmokeTest(['public', 'index', 'not-found', 'hello', 'meta'], LABEL);

runSmokeTest(['public', 'index', 'not-found', 'meta'], LABEL);

describe('Custom About page', function() {
let dom;

beforeEach(async function() {
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'about', './index.html'));
});

it('should output an index.html file within the custom about page directory', function() {
expect(fs.existsSync(path.join(this.context.publicDir, 'about', './index.html'))).to.be.true;
});

it('should have the expected heading text within the custom about page in the about directory', async function() {
const heading = dom.window.document.querySelector('h3').textContent;

expect(heading).to.equal('Nested Custom About Page');
});

it('should have the expected paragraph text within the custom about page in the about directory', async function() {
let paragraph = dom.window.document.querySelector('p').textContent;

expect(paragraph).to.equal('This is a custom about page built by Greenwood.');
});
});
});

after(function() {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Nested Custom About Page

This is a custom about page built by Greenwood.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Greenwood

This is the home page built by Greenwood. Make your own pages in src/pages/index.js!

0 comments on commit 3cd967a

Please sign in to comment.