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

Clean up test documentation and add tests #264

Merged
merged 4 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could try using rewire to avoid exporting internal functions.

https://github.com/jhnns/rewire

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewire looks super cool! I'll update this to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that rewire doesn't work with babel: jhnns/rewire#62

However there is a babel plugin that might work for this use case: https://github.com/speedskater/babel-plugin-rewire

I'm giving it a shot now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The babel plugin doesn't work with babel 6+:
speedskater/babel-plugin-rewire#71

At this point I'm thinking that exporting the items we want to test via a non-default export makes the most sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's file a follow-up to use rewire or babel-plugin-rewire once it's feasible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've filed #272.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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));
});
});
});
});
});