Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #264 from mozilla/moretests
Browse files Browse the repository at this point in the history
Clean up test documentation and add tests
  • Loading branch information
marco-c committed Jan 14, 2016
2 parents cdf53ca + 5e4caed commit 1f3ca70
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 62 deletions.
5 changes: 5 additions & 0 deletions engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,8 @@ export default {
buildStatus,
buildIndex,
};

const test = {
normalizeStatus,
};
export { test };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
66 changes: 33 additions & 33 deletions tests/browserFunctional.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
File renamed without changes.
File renamed without changes.
87 changes: 59 additions & 28 deletions tests/nodeUnit.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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));
});
});
});
});
});

0 comments on commit 1f3ca70

Please sign in to comment.