Skip to content

Commit

Permalink
Merge 6b80337 into 8068777
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Mar 19, 2021
2 parents 8068777 + 6b80337 commit 780bf02
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ grunt/requirejs.js
!.nvmrc
!.prettierrc
!.gitmodules

test/test_manual.html
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"qunit": "~1.12.0",
"jasmine": "~1.3.1",
"mocha": "~2.1.0",
"sinon": "1.9.0",
"sprintf": "~1.0.2",
"requirejs-babel": "^0.0.9",
"d3-cloud": "^1.2.5"
Expand Down
7 changes: 7 additions & 0 deletions grunt/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ test:debug:
- puppet:debug
- clean:temp

generate-manual-testrunner:
- clean:temp
- babel:temp
- string-replace:temp
- generate-testrunner
- server

# Release
release:
description: Build the assets and prepare for a release
Expand Down
1 change: 1 addition & 0 deletions grunt/concurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
'curl:deep-object-diff',
'curl:xstate-react',
'curl:array-flat-polyfill',
'curl:sinon',
],
hash_require: ['hash_require:js', 'hash_require:css'],
};
4 changes: 4 additions & 0 deletions grunt/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ module.exports = {
'https://raw.githubusercontent.com/thostetler/array-flat-polyfill/master/index.js',
dest: 'src/libs/polyfills/array-flat-polyfill.js',
},
sinon: {
src: 'https://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.9.0/sinon.min.js',
dest: 'src/libs/sinon/index.js',
},
};
133 changes: 133 additions & 0 deletions grunt/generate-testrunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* eslint-disable global-require */
/**
* Options for the `test-manual` grunt task
*
* @module grunt/test-manual
*/

module.exports = function(grunt) {
grunt.registerTask('generate-testrunner', function() {
const done = this.async();
const path = require('path');
const RUNNER_FILE_PATH = 'test/test_manual.html';

// grab all test files
const specs = grunt.file
.expand(
{
cwd: path.resolve('test/mocha/js/'),
},
[
'**/*.spec.js',
'!widgets/base_tree_view.spec.js',
'!widgets/facet_zoomable_graph_view.spec.js',
'!widgets/list_of_things_expanding.spec.js',
'!widgets/multi_callback_widget.spec.js',
'!widgets/similar_widget.spec.js',
'!widgets/green_button_widget.spec.js',
'!widgets/facet_graph_widget.spec.js',
'!js/apps/bumblebox/**/*.js',
]
)
.map((p) => p.replace(/^/, 'test/mocha/js/').replace(/.js$/, ''));

// generate path mappings for transpiled modules
const mappings = grunt.file
.expand(
{
cwd: path.resolve('_tmp/js'),
},
['**/*.js']
)
.reduce((acc, m) => {
m = m.replace(/^/, 'js/').replace(/.js$/, '');
acc[m] = m.replace(/^js\//, '_tmp/js/');
return acc;
}, {});

const config = {
baseUrl: '../',
paths: mappings,
};

const testRunnerHTML = `<html>
<head>
<meta charset="utf-8" />
<title>Bumblebee Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../libs/mocha/mocha.css" />
<link rel="stylesheet" href="../styles/css/styles.css" />
</head>
<body>
<div id="mocha"></div>
<script>
// this forces the require config to not start the bumblebee application
window.skipMain = true;
</script>
<script
src="../libs/requirejs/require.js"
></script>
<script>
require({
baseUrl: '../',
deps: ['config/discovery.config'],
paths: {
'common.config': '../config/common.config',
mocha: 'libs/mocha/mocha',
chai: 'libs/chai/chai',
sinon: 'libs/sinon/index',
},
}, ['mocha', 'chai', 'sinon'], function(mocha, chai) {
// expose chai globals
window.expect = chai.expect;
window.assert = chai.assert;
window.should = chai.should;
window.normalizeSpace = (str) => str.replace(/\\s+/g, ' ').trim();
// set testing global
window.__BUMBLEBEE_TESTING_MODE__ = true;
// setup mocha
mocha.setup('bdd').reporter('html');
mocha.suite.afterEach(function() {
$('body>div:not(#mocha)').empty();
document.title = 'Bumblebee Tests';
location.hash = '';
window.localStorage.clear();
window.sessionStorage.clear();
});
// overwrite mocha's stdout to make sure it doesn't throw errors
Mocha.process.stdout.write = () => {};
});
require(
${JSON.stringify(config, null, 2)},
${JSON.stringify(specs, null, 2)},
function () {
const runner = mocha.run();
new Mocha.reporters.Spec(runner);
})
</script>
<!-- Test Fixtures. -->
<div id="fixtures" style="display: none; visibility: hidden;"></div>
<div id="test-area"></div>
<div id="test"></div>
<div id="scratch"></div>
</body>
</html>
`;
if (grunt.file.exists(RUNNER_FILE_PATH)) {
grunt.file.delete(RUNNER_FILE_PATH);
}
grunt.log.writeln('_tmp generated');
grunt.file.write(RUNNER_FILE_PATH, testRunnerHTML);
grunt.log.writeln(`Test runner generated at ${RUNNER_FILE_PATH}`);
grunt.log.writeln(
`open browser to http://localhost:8000/${RUNNER_FILE_PATH}`
);
done();
});
};
2 changes: 1 addition & 1 deletion src/config/discovery.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ require.config({
utils: 'js/utils',
mocha: 'libs/mocha/mocha',
chai: 'bower_components/chai/chai',
sinon: 'https://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.9.0/sinon.min',
sinon: 'libs/sinon/index',
suit: 'shared/dist/index.umd.development',
yup: 'libs/yup/index',
'react-hook-form': [
Expand Down

0 comments on commit 780bf02

Please sign in to comment.