Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed absolute path config bug and improved workspace related specs #82

Merged
merged 3 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member Author

@thescientist13 thescientist13 May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆 😎

functions: 90,
lines: 85,

Expand Down
8 changes: 6 additions & 2 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,6 +35,11 @@ module.exports = readAndMergeConfig = async() => {
customConfig.workspace = path.join(process.cwd(), workspace);
}

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

if (!fs.existsSync(workspace)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about changing this line from this

if (!fs.existsSync(workspace)) {

to this

if (!fs.existsSync(customConfig.workspace)) {

this will make just help ensure we're validating against our own internal logic.

reject('Error: greenwood.config.js workspace doesn\'t exist! \n' +
'common issues to check might be: \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!