diff --git a/nyc.config.js b/nyc.config.js index 43e77d3e5..34797312a 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -17,7 +17,7 @@ module.exports = { checkCoverage: true, statements: 85, - branches: 65, + branches: 70, functions: 90, lines: 85, diff --git a/packages/cli/lib/config.js b/packages/cli/lib/config.js index 0a73f91b1..42f88f44f 100644 --- a/packages/cli/lib/config.js +++ b/packages/cli/lib/config.js @@ -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 @@ -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' + diff --git a/test/cli/cases/build.config.error-workspace-absolute/build.config.error-workspace-absolute.spec.js b/test/cli/cases/build.config.error-workspace-absolute/build.config.error-workspace-absolute.spec.js new file mode 100644 index 000000000..6b971df02 --- /dev/null +++ b/test/cli/cases/build.config.error-workspace-absolute/build.config.error-workspace-absolute.spec.js @@ -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(); + }); + +}); \ No newline at end of file diff --git a/test/cli/cases/build.config.error-workspace-absolute/greenwood.config.js b/test/cli/cases/build.config.error-workspace-absolute/greenwood.config.js new file mode 100644 index 000000000..29c78a6e1 --- /dev/null +++ b/test/cli/cases/build.config.error-workspace-absolute/greenwood.config.js @@ -0,0 +1,5 @@ +const path = require('path'); + +module.exports = { + workspace: path.join(__dirname, 'noop') +}; \ No newline at end of file diff --git a/test/cli/cases/build.config.workspace-custom/build.config.workspace-custom.spec.js b/test/cli/cases/build.config.workspace-custom/build.config.workspace-custom.spec.js index 1c6ec2328..b3fa2de3b 100644 --- a/test/cli/cases/build.config.workspace-custom/build.config.workspace-custom.spec.js +++ b/test/cli/cases/build.config.workspace-custom/build.config.workspace-custom.spec.js @@ -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 @@ -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'); @@ -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() { diff --git a/test/cli/cases/build.config.workspace-custom/www/.gitkeep b/test/cli/cases/build.config.workspace-custom/www/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/cli/cases/build.config.workspace-custom/www/pages/about.md b/test/cli/cases/build.config.workspace-custom/www/pages/about.md new file mode 100644 index 000000000..e228c1606 --- /dev/null +++ b/test/cli/cases/build.config.workspace-custom/www/pages/about.md @@ -0,0 +1,3 @@ +### Nested Custom About Page + +This is a custom about page built by Greenwood. \ No newline at end of file diff --git a/test/cli/cases/build.config.workspace-custom/www/pages/index.md b/test/cli/cases/build.config.workspace-custom/www/pages/index.md new file mode 100644 index 000000000..1c1a50fbb --- /dev/null +++ b/test/cli/cases/build.config.workspace-custom/www/pages/index.md @@ -0,0 +1,3 @@ +### Greenwood + +This is the home page built by Greenwood. Make your own pages in src/pages/index.js! \ No newline at end of file