From 94fc9366c136605a5a1922402b5e72d6d8bfb0c8 Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Fri, 8 Jan 2016 22:58:52 -0800 Subject: [PATCH 1/4] Add a couple simple unit tests for normalizeStatus --- engine/index.js | 5 +++++ tests/nodeUnit.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/engine/index.js b/engine/index.js index 06f5328b..f0fb8b1c 100644 --- a/engine/index.js +++ b/engine/index.js @@ -462,3 +462,8 @@ export default { buildStatus, buildIndex, }; + +const test = { + normalizeStatus, +}; +export { test }; diff --git a/tests/nodeUnit.js b/tests/nodeUnit.js index 0c61ca37..3d84ac1a 100644 --- a/tests/nodeUnit.js +++ b/tests/nodeUnit.js @@ -149,6 +149,51 @@ define(function(require) { assert(fp); }); }); + + bdd.describe('normalizeStatus', function() { + bdd.it('should convert empty strings', function() { + // The node module loader for some reason has wacky path resolution. + // I wish we didn't have to have all these '..' but, alas. + var indexJS = require('intern/dojo/node!../../../../engine/index').test; + assert.equal(indexJS.normalizeStatus(''), 'unknown'); + }); + + bdd.it('should leave known strings untouched', function() { + // The node module loader for some reason has wacky path resolution. + // I wish we didn't have to have all these '..' but, alas. + var indexJS = require('intern/dojo/node!../../../../engine/index').test; + + var strings = [ + 'unknown', + 'not-planned', + 'deprecated', + 'under-consideration', + 'in-development', + 'shipped', + ]; + + strings.forEach(function(val) { + assert.equal(indexJS.normalizeStatus(val), val); + }); + }); + + bdd.it('should throw Error objects for invalid strings', function() { + // The node module loader for some reason has wacky path resolution. + // I wish we didn't have to have all these '..' but, alas. + var indexJS = require('intern/dojo/node!../../../../engine/index').test; + assert.throws(indexJS.normalizeStatus.bind(null, 'asdf')); + assert.throws(indexJS.normalizeStatus.bind(null, 'a string')); + + assert.throws(indexJS.normalizeStatus.bind(null, '-8023')); + assert.throws(indexJS.normalizeStatus.bind(null, '91257')); + + assert.throws(indexJS.normalizeStatus.bind(null, 1234)); + assert.throws(indexJS.normalizeStatus.bind(null, -1234)); + + assert.throws(indexJS.normalizeStatus.bind(null, null)); + assert.throws(indexJS.normalizeStatus.bind(null)); + }); + }); }); }); }); From 440c1d23281c97c8bd773fb71e7bf362c78e44a9 Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Tue, 12 Jan 2016 12:57:05 -0800 Subject: [PATCH 2/4] Move Intern config Moving intern config files to a dedicated config folder. --- package.json | 2 +- tests/{ => config}/intern-browser.js | 0 tests/{ => config}/intern-node.js | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/{ => config}/intern-browser.js (100%) rename tests/{ => config}/intern-node.js (100%) diff --git a/package.json b/package.json index a939e3c8..f8137dc7 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "server": "node server.js", "lint": "gulp lint", "start": "gulp watch", - "test": "npm run lint && npm run build && intern-client config=tests/intern-node && intern-runner config=tests/intern-browser" + "test": "npm run lint && npm run build && intern-client config=tests/config/intern-node && intern-runner config=tests/config/intern-browser" }, "repository": { "type": "git", diff --git a/tests/intern-browser.js b/tests/config/intern-browser.js similarity index 100% rename from tests/intern-browser.js rename to tests/config/intern-browser.js diff --git a/tests/intern-node.js b/tests/config/intern-node.js similarity index 100% rename from tests/intern-node.js rename to tests/config/intern-node.js From 55528a6b65f7b680f54ebb8b5d614d4fda348d2c Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Tue, 12 Jan 2016 12:57:36 -0800 Subject: [PATCH 3/4] Clean up test documentation. Adding links to test documentation and cleaning up the file comments to hopefully make it easier to figure out how to write/extend tests. --- tests/browserFunctional.js | 63 ++++++++++++++++++-------------------- tests/nodeUnit.js | 51 ++++++++++-------------------- 2 files changed, 47 insertions(+), 67 deletions(-) diff --git a/tests/browserFunctional.js b/tests/browserFunctional.js index f9b10fb8..a0050779 100644 --- a/tests/browserFunctional.js +++ b/tests/browserFunctional.js @@ -1,42 +1,39 @@ +// This file is written as an AMD module that will be loaded by the Intern +// test-runner. The test runner is communicating with a Selenium server +// that is controlling a browser. These tests can remote-control the browser +// and probe the displayed pages to verify that pages are functioning and +// displaying as expected. +// +// The flow for each test is generally: +// 1. Create a page object, passing `this.remote` as an argument +// 2. Use the page object to interact with the page and use the assert +// library to verify expected results +// +// For each page that we want to test, we have written or should write an +// "Intern Page Object." Adding/extending tests will frequently mean +// adding/extending page objects as well: +// https://theintern.github.io/intern/#page-objects +// +// `this.remote` is a `Command` object. It is very useful when writing +// page objects to understand the `Command` object interface. Sometimes +// it is necessary to interact with a raw `Command` object in a test, so +// the documentation is linked here: +// https://theintern.github.io/leadfoot/Command.html +// +// We have chosen to use Intern's "BDD" interface (as opposed to the other +// options that Intern provides - "Object," "TDD," and "QUnit"): +// https://theintern.github.io/intern/#interface-tdd/ +// +// We have chosen to use Chai's "assert" library (as opposed to the other +// options that Chai provides - "expect" and "should"): +// http://chaijs.com/api/assert/ + define(function(require) { const bdd = require('intern!bdd'); const assert = require('intern/chai!assert'); - // This `Page` object gives us access to things on index.html const IndexPage = require('tests/support/pages/main'); - // Create a sub-suite with `bdd.describe`. Sub-suites can - // have their own sub-suites; just use `bdd.describe` - // within a suite. - // - // Use `bdd.before` to define a function that will - // run before the suite starts, `bdd.after` to define a - // function that will run after the suite ends, `bdd.beforeEach` - // to define a function that will run before each test or sub-suite, - // and `bdd.afterEach` to define a function that will run after each - // test or sub-suite. - // - // Use `bdd.it` to define actual test cases. - // - // Within a test, throwing an `Error` object will cause the test to fail. - // Returning a promise will make the test async; if the promise - // eventually resolves then the test will pass. If the promise - // eventually rejects then the test will fail. Reject with a descriptive - // `Error` object please. - // - // Within a test, `this` refers to a test suite object. You can use it - // to skip the test or do other test-specific things. - // - // `this.remote` is a `Command` object: - // https://theintern.github.io/leadfoot/Command.html - // - // `this.remote` is how we control the test browser for functional - // tests. Instead of using it directly, we pass it to the constructors - // for "page objects". We use those page objects to control the page - // and query information about its status. If you need to test a new - // page, write a new page object. If you need to extend the functionality - // of a page object, feel free to do so! - bdd.describe('Browser functional tests', function() { bdd.describe('main page', function() { bdd.it('should have correct title', function() { diff --git a/tests/nodeUnit.js b/tests/nodeUnit.js index 3d84ac1a..fb734232 100644 --- a/tests/nodeUnit.js +++ b/tests/nodeUnit.js @@ -1,34 +1,25 @@ +// This file is written as an AMD module that will be loaded by the Intern +// test client. The test client can load node modules directly to test +// that individual pieces are working as expected. +// +// The flow for each test is generally: +// 1. Load the module you wish to perform unit tests on +// 2. Call the functions of that module directly and use the assert +// library to verify expected results +// +// We have chosen to use Intern's "BDD" interface (as opposed to the other +// options that Intern provides - "Object," "TDD," and "QUnit"): +// https://theintern.github.io/intern/#interface-tdd/ +// +// We have chosen to use Chai's "assert" library (as opposed to the other +// options that Chai provides - "expect" and "should"): +// http://chaijs.com/api/assert/ + define(function(require) { const bdd = require('intern!bdd'); const assert = require('intern/chai!assert'); - - // This is how to load regular Node modules. const fs = require('intern/dojo/node!fs'); - // Create a sub-suite with `bdd.describe`. Sub-suites can - // have their own sub-suites; just use `bdd.describe` - // within a suite. - // - // Use `bdd.before` to define a function that will - // run before the suite starts, `bdd.after` to define a - // function that will run after the suite ends, `bdd.beforeEach` - // to define a function that will run before each test or sub-suite, - // and `bdd.afterEach` to define a function that will run after each - // test or sub-suite. - // - // Use `bdd.it` to define actual test cases. - // - // Within a test, throwing an `Error` object will cause the test to fail. - // Returning a promise will make the test async; if the promise - // eventually resolves then the test will pass. If the promise - // eventually rejects then the test will fail. Reject with a descriptive - // `Error` object please. - // - // Within a test, `this` refers to a test suite object. You can use it - // to skip the test or do other test-specific things. - // - // `this.remote` is null for unit tests. - const publicDir = 'dist/public'; bdd.describe('Node unit', function() { @@ -142,8 +133,6 @@ define(function(require) { bdd.describe('fixtureParser', function() { bdd.it('should something', function() { - // The node module loader for some reason has wacky path resolution. - // I wish we didn't have to have all these '..' but, alas. var FixtureParser = require('intern/dojo/node!../../../../engine/fixtureParser').default; var fp = new FixtureParser('asdf'); assert(fp); @@ -152,15 +141,11 @@ define(function(require) { bdd.describe('normalizeStatus', function() { bdd.it('should convert empty strings', function() { - // The node module loader for some reason has wacky path resolution. - // I wish we didn't have to have all these '..' but, alas. var indexJS = require('intern/dojo/node!../../../../engine/index').test; assert.equal(indexJS.normalizeStatus(''), 'unknown'); }); bdd.it('should leave known strings untouched', function() { - // The node module loader for some reason has wacky path resolution. - // I wish we didn't have to have all these '..' but, alas. var indexJS = require('intern/dojo/node!../../../../engine/index').test; var strings = [ @@ -178,8 +163,6 @@ define(function(require) { }); bdd.it('should throw Error objects for invalid strings', function() { - // The node module loader for some reason has wacky path resolution. - // I wish we didn't have to have all these '..' but, alas. var indexJS = require('intern/dojo/node!../../../../engine/index').test; assert.throws(indexJS.normalizeStatus.bind(null, 'asdf')); assert.throws(indexJS.normalizeStatus.bind(null, 'a string')); From 5e4caedf18ed3de35dfda1047cb422e9b784ab4a Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Tue, 12 Jan 2016 14:24:03 -0800 Subject: [PATCH 4/4] Add link to functional/unit test docs at Intern --- tests/browserFunctional.js | 3 +++ tests/nodeUnit.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/browserFunctional.js b/tests/browserFunctional.js index a0050779..53478fbc 100644 --- a/tests/browserFunctional.js +++ b/tests/browserFunctional.js @@ -9,6 +9,9 @@ // 2. Use the page object to interact with the page and use the assert // library to verify expected results // +// More info on writing functional tests with Intern: +// https://theintern.github.io/intern/#writing-functional-test +// // For each page that we want to test, we have written or should write an // "Intern Page Object." Adding/extending tests will frequently mean // adding/extending page objects as well: diff --git a/tests/nodeUnit.js b/tests/nodeUnit.js index fb734232..24d33e94 100644 --- a/tests/nodeUnit.js +++ b/tests/nodeUnit.js @@ -7,6 +7,9 @@ // 2. Call the functions of that module directly and use the assert // library to verify expected results // +// More info on writing Unit tests with Intern: +// https://theintern.github.io/intern/#writing-unit-test +// // We have chosen to use Intern's "BDD" interface (as opposed to the other // options that Intern provides - "Object," "TDD," and "QUnit"): // https://theintern.github.io/intern/#interface-tdd/