Skip to content

Commit

Permalink
Migrate to node's version of mocha + should/loca
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Jun 27, 2014
1 parent 9c40a58 commit cd44fc2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 94 deletions.
34 changes: 19 additions & 15 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

// mocha setup
var should = chai.should();
mocha.suite._timeout = 1000 * 60 * 60;
mocha.setup({
ui: 'bdd',
bail: true,
globals: ['']
});
// show the dev tools by default
require('nw.gui').Window.get().showDevTools().resizeTo(800, 1000);

var Mocha = require('mocha');
var mocha = new Mocha;
mocha.reporter('loca');
mocha.bail(true);
mocha.timeout(1000*60*60);
// pass the browser context
mocha.suite.emit('pre-require', window, null, mocha);

// iframe onload callback
var page = {
onload: null,
Expand Down Expand Up @@ -116,15 +119,16 @@ jQuery(function () {

switch (true) {
case (/relationships/.test(db)):
tests.relationships.otm1();
tests.relationships.otm2();
var file = '<script src="test/relationships/name.js"></script>';
jQuery('head').append(file.replace('name', 'otm1'));
jQuery('head').append(file.replace('name', 'otm2'));

tests.relationships.mtm1();
tests.relationships.mtm2();
jQuery('head').append(file.replace('name', 'mtm1'));
jQuery('head').append(file.replace('name', 'mtm2'));

tests.relationships.tbl();
tests.relationships.filter();
tests.relationships.edit();
jQuery('head').append(file.replace('name', 'tbl'));
jQuery('head').append(file.replace('name', 'filter'));
jQuery('head').append(file.replace('name', 'edit'));
break;
case (/data-types/.test(db) && /pg/.test(engine)):
// sql.pg.truncate is broken!
Expand Down
54 changes: 5 additions & 49 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,18 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Express Admin Tests</title>

<!-- style -->
<link href="node_modules/mocha/mocha.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
#iframe { width: 100%; height: 500px; }
html, body, #iframe { width: 100%; height: 100%; border: 0; padding: 0; margin: 0; }
</style>

<!-- Mocha -->
<script type="text/javascript" charset="utf-8">
// Remove symbols of node-webkit to avoid conficts with mocha in browser.
var nodeRequire = require;
var nodeGlobal = global;
var nodeProcess = process;
require = undefined;
global = undefined;
process = undefined;
</script>
<!--
Use the browser version of mocha, the node version of mocha will
run tests in node contex, which make it imposssible to test nw.gui.
Mocha needs to be v1.11.0 - https://github.com/visionmedia/mocha/issues/960
-->
<script src="node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="node_modules/chai/chai.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Restore default node-webkit environment.
require = nodeRequire;
global = nodeGlobal;
process = nodeProcess;
</script>

<!-- should -->
<script src="node_modules/should/should.js" type="text/javascript" charset="utf-8"></script>

<!-- jquery -->
<script src="node_modules/jquery/dist/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<!-- globals -->
<script type="text/javascript" charset="utf-8">
// show the dev tools by default
require('nw.gui').Window.get().showDevTools().resizeTo(800, 1000);

var tests = {relationships:{}, types:{}};
</script>
<!-- test suite -->
<script src="test/relationships/otm1.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/otm2.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/mtm1.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/mtm2.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/tbl.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/filter.js" type="text/javascript" charset="utf-8"></script>
<script src="test/relationships/edit.js" type="text/javascript" charset="utf-8"></script>

<script src="test/data-types/otm.js" type="text/javascript" charset="utf-8"></script>
<script src="test/data-types/mtm.js" type="text/javascript" charset="utf-8"></script>

<!-- test config -->
<script src="config.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="mocha"></div>
</body>
<body></body>
</html>
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"url" : "git://github.com/simov/express-admin-tests.git"
},
"dependencies": {
"mocha" : "1.11.0",
"chai" : "1.9.1",
"mocha" : "1.20.1",
"loca" : "1.0.1",
"should" : "4.0.4",
"jquery" : "2.1.1",
"async" : "0.9.0",
"mysql" : "2.2.0",
Expand Down
4 changes: 0 additions & 4 deletions test/relationships/edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.edit = function () {

describe('edit', function () {
before(function (done) {
$('a[href="/tbl"]')[0].click();
Expand Down Expand Up @@ -286,5 +284,3 @@ describe('edit', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.filter = function () {

describe('filter', function () {
before(function (done) {
$('a[href="/tbl"]')[0].click();
Expand Down Expand Up @@ -138,5 +136,3 @@ describe('filter', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/mtm1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.mtm1 = function () {

describe('mtm1', function () {
before(function (done) {
client.query(sql.truncate('mtm1'), done);
Expand Down Expand Up @@ -51,5 +49,3 @@ describe('mtm1', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/mtm2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.mtm2 = function () {

describe('mtm2', function () {
before(function (done) {
client.query(sql.truncate('mtm2'), done);
Expand Down Expand Up @@ -56,5 +54,3 @@ describe('mtm2', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/otm1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.otm1 = function () {

describe('otm1', function () {
before(function (done) {
client.query(sql.truncate('otm1'), done);
Expand Down Expand Up @@ -51,5 +49,3 @@ describe('otm1', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/otm2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.otm2 = function () {

describe('otm2', function () {
before(function (done) {
client.query(sql.truncate('otm2'), done);
Expand Down Expand Up @@ -56,5 +54,3 @@ describe('otm2', function () {
page.load(done);
});
});

}
4 changes: 0 additions & 4 deletions test/relationships/tbl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

tests.relationships.tbl = function () {

describe('tbl', function () {
before(function (done) {
async.eachSeries(['tbl','mto1','mto2',
Expand Down Expand Up @@ -499,5 +497,3 @@ describe('tbl', function () {
page.load(done);
});
});

}

0 comments on commit cd44fc2

Please sign in to comment.