mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Add mocha tests + parsing to npm test
This commit is contained in:
@@ -8,6 +8,7 @@ gulpfile.js
|
||||
/tests/compile/*
|
||||
/tests/jsunit/*
|
||||
/tests/generators/*
|
||||
/tests/mocha/run_mocha_tests_in_browser.js
|
||||
/tests/test_runner.js
|
||||
/tests/workspace_svg/*
|
||||
/generators/*
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<body>
|
||||
|
||||
<div id="mocha"></div>
|
||||
<div id="failureCount" style="display:none"></div>
|
||||
<script src="https://unpkg.com/chai/chai.js"></script>
|
||||
<script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>
|
||||
<script src="https://unpkg.com/sinon/pkg/sinon.js"></script>
|
||||
@@ -34,7 +35,10 @@
|
||||
</xml>
|
||||
|
||||
<script>
|
||||
mocha.run();
|
||||
mocha.run(function(failures) {
|
||||
var failureDiv = document.getElementById('failureCount');
|
||||
failureDiv.setAttribute('tests_failed', failures);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
81
tests/mocha/run_mocha_tests_in_browser.js
Normal file
81
tests/mocha/run_mocha_tests_in_browser.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @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');
|
||||
|
||||
module.exports = runMochaTestsInBrowser;
|
||||
|
||||
/**
|
||||
* Runs the Mocha 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.
|
||||
* @return 0 on success, 1 on failure.
|
||||
*/
|
||||
async function runMochaTestsInBrowser() {
|
||||
var options = {
|
||||
capabilities: {
|
||||
browserName: 'chrome'
|
||||
}
|
||||
};
|
||||
|
||||
var url = 'file://' + __dirname + '/index.html';
|
||||
console.log('Starting webdriverio...');
|
||||
const browser = await webdriverio.remote(options);
|
||||
console.log('Initialized.\nLoading url: ' + url);
|
||||
await browser.url(url);
|
||||
|
||||
await browser.waitUntil(async () => {
|
||||
var elem = await browser.$('#failureCount');
|
||||
var text = await elem.getAttribute('tests_failed');
|
||||
return text != 'unset';
|
||||
})
|
||||
|
||||
const elem = await browser.$('#failureCount')
|
||||
const numOfFailure = await elem.getAttribute('tests_failed');
|
||||
|
||||
console.log('============Blockly Mocha Test Summary=================');
|
||||
console.log(numOfFailure);
|
||||
console.log(numOfFailure + ' tests failed');
|
||||
console.log('============Blockly Mocha Test Summary=================');
|
||||
if (parseInt(numOfFailure) !== 0) {
|
||||
await browser.deleteSession();
|
||||
return 1;
|
||||
}
|
||||
await browser.deleteSession();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
runMochaTestsInBrowser().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}).then(function(result) {
|
||||
if (result) {
|
||||
console.log('Mocha tests failed');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Mocha tests passed');
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -57,7 +57,9 @@ run_test_command "eslint" "eslint ."
|
||||
|
||||
# Run JSUnit tests inside a browser.
|
||||
run_test_command "jsunit" "node tests/jsunit/run_jsunit_tests_in_browser.js"
|
||||
# TODO: Make sure jsunit output is captured. Child process?
|
||||
|
||||
# Run Mocha tests inside a browser.
|
||||
run_test_command "mocha" "node tests/mocha/run_mocha_tests_in_browser.js"
|
||||
|
||||
# Run generator tests inside a browser and check the results.
|
||||
run_test_command "generators" "tests/scripts/run_generators.sh"
|
||||
|
||||
Reference in New Issue
Block a user