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/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/browserFunctional.js b/tests/browserFunctional.js index f9b10fb8..53478fbc 100644 --- a/tests/browserFunctional.js +++ b/tests/browserFunctional.js @@ -1,42 +1,42 @@ +// 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 +// +// 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: +// 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/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 diff --git a/tests/nodeUnit.js b/tests/nodeUnit.js index 0c61ca37..24d33e94 100644 --- a/tests/nodeUnit.js +++ b/tests/nodeUnit.js @@ -1,34 +1,28 @@ +// 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 +// +// 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/ +// +// 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,13 +136,50 @@ 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); }); }); + + bdd.describe('normalizeStatus', function() { + bdd.it('should convert empty strings', function() { + var indexJS = require('intern/dojo/node!../../../../engine/index').test; + assert.equal(indexJS.normalizeStatus(''), 'unknown'); + }); + + bdd.it('should leave known strings untouched', function() { + 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() { + 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)); + }); + }); }); }); });