Skip to content

Commit

Permalink
tests: Merge test-runner.js into test-cases.js
Browse files Browse the repository at this point in the history
Removed the second <script> tag and the need to require() something on NodeJS
  • Loading branch information
Turbo87 committed Jul 15, 2015
1 parent 06a6284 commit 678ac76
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 104 deletions.
88 changes: 86 additions & 2 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var assert = chai.assert;

var RECORD_SEP = String.fromCharCode(30);
var UNIT_SEP = String.fromCharCode(31);
var FILES_ENABLED = false;
Expand Down Expand Up @@ -434,6 +436,21 @@ var CORE_PARSER_TESTS = [
}
];

describe('Core Parser Tests', function() {
function generateTest(test) {
(test.disabled ? it.skip : it)(test.description, function() {
var actual = new Papa.Parser(test.config).parse(test.input);
assert.deepEqual(JSON.stringify(actual.errors), JSON.stringify(test.expected.errors));
assert.deepEqual(actual.data, test.expected.data);
});
}

for (var i = 0; i < CORE_PARSER_TESTS.length; i++) {
generateTest(CORE_PARSER_TESTS[i]);
}
});



// Tests for Papa.parse() function -- high-level wrapped parser (CSV to JSON)
var PARSE_TESTS = [
Expand Down Expand Up @@ -824,9 +841,19 @@ var PARSE_TESTS = [
}
];

describe('Parse Tests', function() {
function generateTest(test) {
(test.disabled ? it.skip : it)(test.description, function() {
var actual = Papa.parse(test.input, test.config);
assert.deepEqual(JSON.stringify(actual.errors), JSON.stringify(test.expected.errors));
assert.deepEqual(actual.data, test.expected.data);
});
}



for (var i = 0; i < PARSE_TESTS.length; i++) {
generateTest(PARSE_TESTS[i]);
}
});



Expand Down Expand Up @@ -893,10 +920,29 @@ var PARSE_ASYNC_TESTS = [
}
];

describe('Parse Async Tests', function() {
function generateTest(test) {
(test.disabled ? it.skip : it)(test.description, function(done) {
var config = test.config;

config.complete = function(actual) {
assert.deepEqual(JSON.stringify(actual.errors), JSON.stringify(test.expected.errors));
assert.deepEqual(actual.data, test.expected.data);
done();
};

config.error = function(err) {
throw err;
};

Papa.parse(test.input, config);
});
}

for (var i = 0; i < PARSE_ASYNC_TESTS.length; i++) {
generateTest(PARSE_ASYNC_TESTS[i]);
}
});



Expand Down Expand Up @@ -1046,6 +1092,29 @@ var UNPARSE_TESTS = [
}
];

describe('Unparse Tests', function() {
function generateTest(test) {
(test.disabled ? it.skip : it)(test.description, function() {
var actual;

try {
actual = Papa.unparse(test.input, test.config);
} catch (e) {
if (e instanceof Error) {
throw e;
}
actual = e;
}

assert.strictEqual(actual, test.expected);
});
}

for (var i = 0; i < UNPARSE_TESTS.length; i++) {
generateTest(UNPARSE_TESTS[i]);
}
});



var CUSTOM_TESTS = [
Expand Down Expand Up @@ -1379,3 +1448,18 @@ var CUSTOM_TESTS = [
}

];

describe('Custom Tests', function() {
function generateTest(test) {
(test.disabled ? it.skip : it)(test.description, function(done) {
test.run(function (actual) {
assert.deepEqual(JSON.stringify(actual), JSON.stringify(test.expected));
done();
});
});
}

for (var i = 0; i < CUSTOM_TESTS.length; i++) {
generateTest(CUSTOM_TESTS[i]);
}
});
101 changes: 0 additions & 101 deletions tests/test-runner.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<script>mocha.setup('bdd')</script>
<script src="test-cases.js"></script>
<script src="test-runner.js"></script>
</head>
<body>
<div id="mocha"></div>
Expand Down

0 comments on commit 678ac76

Please sign in to comment.