Skip to content

Commit

Permalink
Technical/issue 56 organize tests smoke test refactor (#75)
Browse files Browse the repository at this point in the history
* integrating smoke tests

* full smoke test integration

* cleanup

* fix linting

* improve error message

* Fix test async and teardown (#77)

* fix: removed smoke test promises, implemented shared context using this

* fix: remove TODO
  • Loading branch information
thescientist13 authored May 11, 2019
1 parent 91d91b7 commit aef54d7
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 269 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"http-server": "^0.11.1",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
Expand Down
22 changes: 11 additions & 11 deletions test/cli/cases/build.config.default/build.config.default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
const runSmokeTest = require('../../smoke-test');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', async () => {
describe('Build Greenwood With: ', async function() {
const LABEL = 'Empty Configuration and Default Workspace';
let setup;
let context;

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

describe('Empty Configuration and Default Workspace', () => {
before(async () => {
describe(LABEL, function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});

it('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Empty Configuration and Default Workspace');
});
runSmokeTest(['public', 'index', 'not-found', 'hello'], LABEL);
});

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

});
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ describe('Build Greenwood With: ', () => {
});

describe('Custom Configuration with a bad value for Public Path', () => {
it('should throw an error that publicPath must be a dtring', async () => {
it('should throw an error that publicPath must be a string', async () => {
try {
await setup.runGreenwoodCommand('build');
} catch (err) {
expect(err).to.contain('greenwood.config.js publicPath must be a string');
}
});
});

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

});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Build Greenwood With: ', () => {
});

describe('Custom Configuration with a bad value for Workspace', () => {
it('should throw an error that workspace path must be a dtring', async () => {
it('should throw an error that workspace path must be a string', async () => {
try {
await setup.runGreenwoodCommand('build');
} catch (err) {
Expand All @@ -37,4 +37,8 @@ describe('Build Greenwood With: ', () => {
});
});

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

});
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
const runSmokeTest = require('../../smoke-test');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', () => {
describe('Build Greenwood With: ', function() {
const LABEL = 'Custom Configuration for Workspace (www) and Default Greenwood configuration';
let setup;
let context;

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

describe('Custom Configuration for Workspace (www) and Default Greenwood configuration', () => {
before(async () => {
describe(LABEL, function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});

it('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Custom Configuration for Workspace (www) and Default Greenwood configuration');
});
runSmokeTest(['public', 'index', 'not-found'], LABEL);
});

after(function() {
setup.teardownTestBed();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,52 @@ const path = require('path');
const TestBed = require('../../test-bed');

// TODO why does this case need a src/pages/index.md?
describe('Build Greenwood With: ', () => {
describe('Build Greenwood With: ', function() {
const LABEL = 'Default Greenwood Configuration and Default Workspace w/ Nested Directories';
let setup;
let context;

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

describe('Default Greenwood Configuration and Default Workspace w/ Nested Directories', () => {
before(async () => {
describe(LABEL, function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});

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

xit('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Default Greenwood Configuration and Default Workspace w/ Nested Directories');
});

it('should create a default blog page directory', () => {
expect(fs.existsSync(path.join(context.publicDir, './blog'))).to.be.true;
it('should create a default blog page directory', function() {
expect(fs.existsSync(path.join(this.context.publicDir, './blog'))).to.be.true;
});

describe('Custom blog page directory', () => {
describe('Custom blog page directory', function() {
let dom;

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

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

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

expect(heading).to.equal('Blog Page');
});

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

expect(paragraph).to.equal('This is the test blog page built by Greenwood.');
});
});
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,89 @@ const { JSDOM } = require('jsdom');
const path = require('path');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', () => {
describe('Build Greenwood With: ', function() {
const LABEL = 'Default Greenwood Configuration and Workspace w/Custom App Template';
let setup;
let context;

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

describe('Default Greenwood Configuration and Workspace w/Custom App Template', () => {
describe(LABEL, function() {
let dom;

before(async () => {
await setup.runGreenwoodCommand('build');
});

xit('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Default Greenwood Configuration and Workspace w/Custom App Template');
runSmokeTest(['public', 'not-found', 'hello'], LABEL);

describe('Custom Index (Home) page', function() {
const indexPageHeading = 'Greenwood';
const indexPageBody = 'This is the home page built by Greenwood. Make your own pages in src/pages/index.js!';
let dom;

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

it('should have a <title> tag in the <head>', function() {
const title = dom.window.document.querySelector('head title').textContent;

expect(title).to.be.equal('My App');
});

it('should have a <script> tag in the <body>', function() {
const scriptTag = dom.window.document.querySelectorAll('body script');

expect(scriptTag.length).to.be.equal(1);
});

it('should have a router outlet tag in the <body>', function() {
const outlet = dom.window.document.querySelectorAll('body eve-app');

expect(outlet.length).to.be.equal(1);
});

// no 404 route in our custom app-template.js, like greenwood does
it('should have the correct route tags in the <body>', function() {
const routes = dom.window.document.querySelectorAll('body lit-route');

expect(routes.length).to.be.equal(2);
});

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

expect(heading).to.equal(indexPageHeading);
});

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

expect(paragraph).to.equal(indexPageBody);
});
});

describe('Custom App Template', () => {
before(async() => {
dom = await JSDOM.fromFile(path.resolve(context.publicDir, 'index.html'));
describe('Custom App Template', function() {
before(async function() {
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, 'index.html'));
});

it('should output a single index.html file using our custom app template', () => {
expect(fs.existsSync(path.join(context.publicDir, './index.html'))).to.be.true;
it('should output a single index.html file using our custom app template', function() {
expect(fs.existsSync(path.join(this.context.publicDir, './index.html'))).to.be.true;
});

it('should have the specific element we added as part of our custom app template', () => {
it('should have the specific element we added as part of our custom app template', function() {
const customParagraph = dom.window.document.querySelector('p#custom-app-template').textContent;

expect(customParagraph).to.equal('My Custom App Template');
});

after(async () => {
setup.teardownTestBed();
});
});
});

after(function() {
setup.teardownTestBed();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,43 @@ const { JSDOM } = require('jsdom');
const path = require('path');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', () => {
describe('Build Greenwood With: ', function() {
const LABEL = 'Default Greenwood Configuration and Workspace w/Custom Page Template';
let setup;
let context;

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

describe('Default Greenwood Configuration and Workspace w/Custom Page Template', () => {
before(async() => {
describe(LABEL, function() {
before(async function() {
await setup.runGreenwoodCommand('build');
});

xit('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Default Greenwood Configuration and Workspace w/Custom Page Template');
});
runSmokeTest(['public', 'index', 'not-found', 'hello'], LABEL);

describe('Custom Page Template', () => {
describe('Custom Page Template', function() {
let dom;

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

it('should output a single index.html file using our custom app template', () => {
expect(fs.existsSync(path.join(context.publicDir, './index.html'))).to.be.true;
it('should output a single index.html file using our custom app template', function() {
expect(fs.existsSync(path.join(this.context.publicDir, './index.html'))).to.be.true;
});

it('should have the specific element we added as part of our custom page template', () => {
it('should have the specific element we added as part of our custom page template', function() {
const customElement = dom.window.document.querySelectorAll('div.owen-test');

expect(customElement.length).to.equal(1);
});

after(async () => {
setup.teardownTestBed();
});

});

});

after(function() {
setup.teardownTestBed();
});
});
21 changes: 11 additions & 10 deletions test/cli/cases/build.default/build.default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
const runSmokeTest = require('../../smoke-test');
const TestBed = require('../../test-bed');

describe('Build Greenwood With: ', () => {
describe('Build Greenwood With: ', function() {
const LABEL = 'Default Greenwood Configuration and Workspace';
let setup;
let context;

before(() => {
before(function() {
setup = new TestBed();
context = setup.setupTestBed(__dirname);
this.context = setup.setupTestBed(__dirname);
});

describe('Default Greenwood Configuration and Workspace', () => {
before(async () => {
await setup.runGreenwoodCommand('build');
});
describe(LABEL, function() {

it('should pass all smoke tests', async () => {
await runSmokeTest(context, setup, 'Default Greenwood Configuration and Workspace');
before(async function() {
await setup.runGreenwoodCommand('build');
});
runSmokeTest(['public', 'index', 'not-found', 'hello'], LABEL);
});

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

0 comments on commit aef54d7

Please sign in to comment.