Migrate to using Mocha directly with ES6 and React JSX.

This commit is contained in:
Dorian 2016-08-05 23:59:07 -04:00
parent bd4bc3effd
commit 1476e9292c
6 changed files with 2913 additions and 1211 deletions

4
.babelrc Normal file
View File

@ -0,0 +1,4 @@
{
"presets": ["es2015", "react"],
"plugins": ["babel-plugin-rewire"]
}

3903
client/dist/rookeries.js vendored

File diff suppressed because one or more lines are too long

View File

@ -19,24 +19,26 @@
"superagent": "1.2.0"
},
"devDependencies": {
"babel-core": "^6.13.2",
"babel-eslint": "^6.1.2",
"babel-plugin-rewire": "^1.0.0-rc-5",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.11.6",
"babel-template": "^6.9.0",
"babel-traverse": "^6.13.0",
"babel-types": "^6.13.0",
"babelify": "^7.3.0",
"browserify": "^13.1.0",
"chai": "1.9.2",
"eslint": "^3.2.2",
"eslint-plugin-import": "^1.12.0",
"eslint-plugin-react": "^6.0.0",
"karma": "0.12.24",
"karma-browserify": "^5.0.5",
"karma-chai": "0.1.0",
"karma-coverage": "0.2.6",
"karma-mocha": "^1.0.1",
"karma-phantomjs-launcher": "^1.0.0",
"jsdom": "^9.4.1",
"less": "^2.7.1",
"mocha": "^2.4.5",
"react-addons-test-utils": "^15.3.0",
"rewireify": "0.2.1",
"sinon-chai": "2.7.0",
"watchify": "3.2.2"
@ -59,7 +61,7 @@
},
"browser": "./client/app.cjsx",
"scripts": {
"test": "karma start tests/client/karma.conf.coffee",
"test": "npm run build && mocha --compilers js:babel-register tests/client",
"build": "browserify client/app.js -o client/dist/rookeries.js -t [ babelify --presets [ es2015 react ] ]",
"watch": "watchify client/app.js -o client/dist/rookeries.js -t [ babelify --presets [ es2015 react ] ] --debug --verbose"
}

View File

@ -1,66 +0,0 @@
# Karma configuration
# Generated on Thu Oct 23 2014 17:35:10 GMT-0400 (EDT)
module.exports = (config) ->
config.set
# base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../../'
# frameworks to use
# available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['browserify', 'mocha', 'chai']
# list of files / patterns to load in the browser
files: [
'node_modules/react-tools/src/test/phantomjs-shims.js',
'tests/client/**/*.coffee',
'tests/client/**/*.cjsx'
]
# list of files to exclude
exclude: []
# preprocess matching files before serving them to the browser
# available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/**/*.coffee': ['browserify'],
'tests/**/*.cjsx': ['browserify']
}
browserify: {
debug: true,
transform: ['coffee-reactify', 'rewireify'],
extensions: ['.js', '.jsx', '.coffee', '.cjsx']
}
# test results reporter to use
# possible values: 'dots', 'progress'
# available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage']
# web server port
port: 9876
# enable / disable colors in the output (reporters and logs)
colors: true
# level of logging
# possible values:
# - config.LOG_DISABLE
# - config.LOG_ERROR
# - config.LOG_WARN
# - config.LOG_INFO
# - config.LOG_DEBUG
logLevel: config.LOG_DEBUG
# enable / disable watching file and executing tests whenever any file changes
autoWatch: false
# start these browsers
# available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS']
# Continuous Integration mode
# if true, Karma captures browsers, runs the tests and exits
singleRun: true

View File

@ -1,67 +0,0 @@
"use strict"
React = require "react"
TestUtils = require "react/lib/ReactTestUtils"
sinon = require "sinon"
Actions = require "../../client/actions.coffee"
JournalEntryStore = require "../../client/stores/journal_entry_store.coffee"
JournalMarkdownViewer = require "../../client/views/journal_markdown_viewer.cjsx"
Router = require "react-router"
describe 'JournalMarkdownViewer', () ->
RealActions = null
RealJournalEntryStore = null
RealStateMixin = null
StubStateMixin = sinon.stub(Router.State)
describe "simple test", () ->
it "prove that test infrastructure works", () ->
assert.ok true
describe.skip "Skip for now until component refactored", () ->
beforeEach () ->
console.log('Before')
RealActions = JournalMarkdownViewer.__get__ "Actions"
RealJournalEntryStore = JournalMarkdownViewer.__get__ "JournalEntryStore"
RealStateMixin = JournalMarkdownViewer.__get__ "Router.State"
JournalMarkdownViewer.__set__ "Actions", sinon.stub(Actions)
JournalMarkdownViewer.__set__ "JournalEntryStore", sinon.stub(JournalEntryStore)
JournalMarkdownViewer.__set__ "Router.State", StubStateMixin
afterEach () ->
console.log('After')
JournalMarkdownViewer.__set__ "Actions", RealActions
JournalMarkdownViewer.__set__ "JournalEntryStore", RealJournalEntryStore
JournalMarkdownViewer.__set__ "Router.State", RealStateMixin
it 'The view should default to a loading text when initializing and then calling for data', () ->
@skip "Implement me later"
# TODO Attempt to wrap the rendering of the route... using sinon stubs and knowledge of React's Router.
# StubStateMixin.getParams.id = undefined
mockStateCurrentParams = {getCurrentParams: () -> {id: undefined}}
mockStateMixinContext = {context: {router: sinon.stub(mockStateCurrentParams, "getCurrentParams")}}
StubStateMixin = sinon.stub(mockStateMixinContext)
journalMarkdownView = TestUtils.renderIntoDocument(<JournalMarkdownViewer />)
assert.ok journalMarkdownView
journalTitle = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'h1')
assert.ok journalTitle
assert.equal journalTitle.getDOMNode().textContent, 'Loading...'
journalContent = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'span')
assert.ok journalContent
assert.include journalContent.getDOMNode().textContent, 'Please wait while we load'
# TODO Add timer test
# TODO Add mock call for data.
it 'The view should update its state given newer data', () ->
@skip('Implement me.')

View File

@ -0,0 +1,66 @@
require("babel-register");
import React from "react";
import TestUtils from "react-addons-test-utils";
import sinon from "sinon";
import { assert } from "chai";
import { Actions } from "../../client/actions.js";
import { JournalEntryStore } from "../../client/stores/journal_entry_store.js";
import { JournalMarkdownView, __RewireAPI__ as JournalRewireAPI } from "../../client/views/journal_markdown_viewer.js";
import { Router, State } from "react-router";
// From https://github.com/jesstelford/react-testing-mocha-jsdom
import jsdom from 'jsdom';
// A super simple DOM ready for React to render into
// Store this DOM and the window in global scope ready for React to access
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = document.parentWindow;
describe('JournalMarkdownViewer', function() {
describe("simple test", function () {
it("prove that test infrastructure works", function () {
assert.ok(true);
});
});
describe.skip("Fetching of Articles by view linked to store", function () {
beforeEach(function () {
JournalRewireAPI.__Rewire__("Actions", sinon.stub(Actions));
JournalRewireAPI.__Rewire__("JournalEntryStore", sinon.stub(JournalEntryStore));
JournalRewireAPI.__Rewire__("State", sinon.stub(State));
});
afterEach(function () {
console.log('After');
JournalRewireAPI.__ResetDependency__("Actions");
JournalRewireAPI.__ResetDependency__("JournalEntryStore");
JournalRewireAPI.__ResetDependency__("State");
});
it('The view should default to a loading text when initializing and then calling for data', function () {
this.skip('Fix up later');
let journalMarkdownView = TestUtils.renderIntoDocument(<JournalMarkdownView />);
assert.ok(journalMarkdownView);
let journalTitle = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'h1');
assert.ok(journalTitle);
assert.equal(journalTitle.getDOMNode().textContent, 'Loading...');
let journalContent = TestUtils.findRenderedDOMComponentWithTag(journalMarkdownView, 'span');
assert.ok(journalContent);
assert.include(journalContent.getDOMNode().textContent, 'Please wait while we load');
});
// TODO Add timer test
// TODO Add mock call for data.
it('The view should update its state given newer data', function () {
this.skip('Implement me.');
});
});
});