UNPKG

1.89 kBJavaScriptView Raw
1"use strict";
2
3var TestDiscovery = require("./helper/test-discovery");
4var path = require("path");
5var argv = require("yargs").argv;
6var child_process = require("child_process");
7
8var testSuite;
9if (argv.language) {
10 testSuite = TestDiscovery.loadSomeTests(__dirname + "/languages", argv.language);
11} else {
12 // load complete test suite
13 testSuite = TestDiscovery.loadAllTests(__dirname + "/languages");
14}
15
16// define tests for all tests in all languages in the test suite
17for (var language in testSuite) {
18 if (!testSuite.hasOwnProperty(language)) {
19 continue;
20 }
21
22 (function (language, testFiles) {
23 describe("Testing language '" + language + "'", function () {
24 this.timeout(10000);
25
26 // Each set of tests runs in its own child process
27 var child;
28 before(function () {
29 child = child_process.fork(__dirname + "/run-child.js", ['--language=' + language], {
30 stdio: 'inherit'
31 });
32 });
33
34 after(function () {
35 child.kill();
36 });
37
38 testFiles.forEach(
39 function (filePath) {
40 var fileName = path.basename(filePath, path.extname(filePath));
41
42 it("– should pass test case '" + fileName + "'",
43 function (done) {
44
45 child.removeAllListeners('message');
46 child.on('message', function (o) {
47 // We have to delay the call,
48 // otherwise the first message is received
49 // over and over again.
50 setTimeout(function() {
51 if (o.error) {
52 throw JSON.parse(o.error);
53 } else if (o.success) {
54 done();
55 }
56 }, 1);
57 });
58 child.send({
59 filePath: filePath
60 });
61 }
62 );
63 }
64 );
65 });
66 })(language, testSuite[language]);
67}
\No newline at end of file