Browse Source

tests: Merge test-runner.js into test-cases.js

Removed the second <script> tag and the need to require() something on NodeJS
pull/233/head
Tobias Bieniek 10 years ago
parent
commit
678ac76479
  1. 88
      tests/test-cases.js
  2. 101
      tests/test-runner.js
  3. 1
      tests/tests.html

88
tests/test-cases.js

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
var assert = chai.assert;
var RECORD_SEP = String.fromCharCode(30);
var UNIT_SEP = String.fromCharCode(31);
var FILES_ENABLED = false;
@ -434,6 +436,21 @@ var CORE_PARSER_TESTS = [ @@ -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 = [
@ -824,9 +841,19 @@ var PARSE_TESTS = [ @@ -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]);
}
});
@ -893,10 +920,29 @@ var PARSE_ASYNC_TESTS = [ @@ -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]);
}
});
@ -1046,6 +1092,29 @@ var UNPARSE_TESTS = [ @@ -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 = [
@ -1379,3 +1448,18 @@ var CUSTOM_TESTS = [ @@ -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
tests/test-runner.js

@ -1,101 +0,0 @@ @@ -1,101 +0,0 @@
var assert = chai.assert;
// Generates all tests from CORE_PARSER_TESTS in test-cases.js
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]);
}
});
// Generates all tests from PARSE_TESTS in test-cases.js
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]);
}
});
// Generates all tests from PARSE_ASYNC_TESTS in test-cases.js
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]);
}
});
// Generates all tests from UNPARSE_TESTS in test-cases.js
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]);
}
});
// Generates all tests from CUSTOM_TESTS in test-cases.js
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]);
}
});

1
tests/tests.html

@ -11,7 +11,6 @@ @@ -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>

Loading…
Cancel
Save