Changing root script for tests under Node. (#1837)

* Changing root script for tests under Node.

Was: tests/jsunit/test_runner.js
Now: tests/test_runner.js

The webdriver & jsunit calls formerly in tests/jsunit/test_runner.js
are now in function runJsUnitTestsInBrowser, in
run_jsunit_tests_in_browser.js, called from tests/test_runner.js.

This makes room for additional tests under Node, such as headless and generator tests.
This commit is contained in:
Andrew n marshall
2018-05-02 12:19:49 -07:00
committed by GitHub
parent 1687275cb2
commit 0ffd5dda18
5 changed files with 122 additions and 36 deletions

View File

@@ -6,6 +6,7 @@
/tests/compile/*
/tests/jsunit/*
/tests/generators/*
/tests/test_runner.js
/tests/workspace_svg/*
/generators/*
/demos/*

View File

@@ -19,7 +19,7 @@
"scripts": {
"lint": "eslint .",
"pretest": "tests/scripts/test_setup.sh",
"test": "node tests/jsunit/test_runner.js"
"test": "node tests/test_runner.js"
},
"license": "Apache-2.0",
"private": true,

View File

@@ -0,0 +1,76 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2018 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Node.js script to run JsUnit tests in Chrome, via webdriver.
*/
var webdriverio = require('webdriverio');
/**
* Runs the JsUnit tests in this directory in Chrome. It uses webdriverio to
* launch Chrome and load index.html. Outputs a summary of the test results
* to the console.
* @throws If any error occurs when attempting to run the tests.
*/
function runJsUnitTestsInBrowser() {
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
//TODO: change pause to waitunitl
var browser = webdriverio
.remote(options)
.init()
.url('file://' + __dirname + '/index.html').pause(5000);
browser
.getHTML('#closureTestRunnerLog')
.then(function(result) {
// call js to parse html
var regex = /[\d]+\spassed,\s([\d]+)\sfailed./i;
var numOfFailure = regex.exec(result)[1];
var regex2 = /Unit Tests for Blockly .*]/;
var testStatus = regex2.exec(result)[0];
console.log('============Blockly Unit Test Summary=================');
console.log(testStatus);
var regex3 = /\d+ passed,\s\d+ failed/;
var detail = regex3.exec(result)[0];
console.log(detail);
console.log('============Blockly Unit Test Summary=================');
if ( parseInt(numOfFailure) !== 0) {
console.log(result);
process.exit(1);
}
})
}
module.exports = runJsUnitTestsInBrowser;
if (require.main === module) {
try {
runJsUnitTestsInBrowser();
} catch(errorStr) {
console.error(errorStr);
process.exit(1);
}
}

View File

@@ -1,35 +0,0 @@
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
var path = process.cwd();
//TODO: change pause to waitunitl
var browser = webdriverio
.remote(options)
.init()
.url("file://" + path + "/tests/jsunit/index.html").pause(5000);
browser
.getHTML('#closureTestRunnerLog')
.then(function(result) {
// call js to parse html
var regex = /[\d]+\spassed,\s([\d]+)\sfailed./i;
var numOfFailure = regex.exec(result)[1];
var regex2 = /Unit Tests for Blockly .*]/;
var testStatus = regex2.exec(result)[0];
console.log("============Blockly Unit Test Summary=================");
console.log(testStatus);
var regex3 = /\d+ passed,\s\d+ failed/;
var detail = regex3.exec(result)[0];
console.log(detail);
console.log("============Blockly Unit Test Summary=================");
if ( parseInt(numOfFailure) !== 0) {
console.log(result);
process.exit(1);
}
})
.catch(function(err) { console.log(err); process.exit(1); });

44
tests/test_runner.js Normal file
View File

@@ -0,0 +1,44 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2018 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Node.js script to run all tests.
*/
if (require.main !== module) {
throw __filename + ' must be called directly.';
}
var testFns = [
require('./jsunit/run_jsunit_tests_in_browser')
];
var errored = false;
testFns.forEach((testFn) => {
try {
testFn();
} catch (errorStr) {
errored = true;
console.error(errorStr + '\n\n');
}
});
if (errored) {
process.exit(1);
}