Skip to content

Commit

Permalink
Merge pull request #977 from kingFighter/test-frame
Browse files Browse the repository at this point in the history
Add an option of test framework to list all tests
  • Loading branch information
rogerwang committed Aug 12, 2013
2 parents 2f8e33c + 9cbd052 commit 08f1aaf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/automatic_tests/console/mocha_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ describe('console.log', function() {
it('should display null correctly', function() {
assert.equal(results[7], expected[7]);
});
});//describe('output data types', function()
});


describe('concatenate expressions', function() {
it('should display string correctly', function() {
assert.equal(results[8], expected[8]);
});
});//describe('concatenate expressions', function())
});

describe('format output', function() {
it('should display correctly with %s', function() {
Expand Down Expand Up @@ -111,5 +111,5 @@ describe('console.log', function() {
it('should display correcty with all formats', function() {
assert.equal(results[17], expected[17]);
});
})//describe('format output', function())
})
});
41 changes: 40 additions & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
var program = require('commander');
global.local_server = require('./server/server');
var local_server = global.local_server;

var list = new Array();
//socket server
var net = require('net');
global.server = net.createServer();
Expand Down Expand Up @@ -63,6 +63,7 @@
.option('-A, --async-only', "force all tests to take a callback (async)")
.option('-p, --port <port>', "set the port used by socket")
.option('-v, --verbose', "show the test case which is running.")
.option('-l, --list', "list all test cases")
.parse([ 'node-webkit', 'nw-test' ].concat(gui.App.argv));

// --silent
Expand Down Expand Up @@ -108,6 +109,32 @@

if (fs.existsSync(test_file_path)){
var content = fs.readFileSync(test_file_path);
// Get all the test cases
var content_tmp = content + "", content_bet, n, n1 = 0, obj, obj1;
obj1 = new Object();
obj1.depth = 1;

while (program.list && content_tmp.length != 0) {
n = content_tmp.search('describe');
if (n == -1)
break;
n1 = content_tmp.search('{');
content_bet = (content_tmp + "").slice(n1, n);
var c = content_bet.split('{').length - content_bet.split('}').length;

content_tmp = content_tmp.slice(n);
n1 = content_tmp.search('{');
n1 = content_tmp.lastIndexOf(',' ,n1);
obj = new Object();
obj.test_name = content_tmp.slice(10, n1 - 1);
content_tmp = content_tmp.slice(n1);
obj.depth = obj1.depth + c;

list.push(obj);
obj1 = obj;
}


// Simple wrapped 'eval' to setup tests, so:
// 1) working directory is the directory of 'index.html'.
// 2) tests run in window context.
Expand All @@ -121,6 +148,18 @@
}
}

if (program.list) {
for (var i = 0; i < list.length; i++) {
var split = '-';
process.stdout.write(new Array(list[i].depth).join(split) + list[i].test_name + '\n');
}
process.stdout.write("Report total: " + list.length + '\n');
server.close = function(){}
server.listen = function() {}
process.exit();
}



server.on('listening', function(){
// Run!
Expand Down

0 comments on commit 08f1aaf

Please sign in to comment.