Skip to content

Commit

Permalink
Merge pull request #106 from google/add/qunit-tests
Browse files Browse the repository at this point in the history
Improve Qunit tests
  • Loading branch information
felixarntz authored Jul 3, 2019
2 parents f7da393 + 18c0024 commit 3290fe2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ script:
fi
- |
if [[ "$JS" == "1" ]]; then
travis_retry npm run travis:test || exit 1
npm run build || exit 1 # Build for tests.
npx gulp qunit || exit 1 # QUnit tests
npm run test || exit 1 # Bundle size test
travis_retry npm run travis:visualtest || exit 1 # Visual regression tests
else
gulp phpunit || exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/

import gulp from 'gulp';
import qunit from 'node-qunit-phantomjs';
import requireDir from 'require-dir';
import runSequence from 'run-sequence';
import livereload from 'gulp-livereload';
import { execSync } from 'child_process';
var phpunit = require( 'gulp-phpunit' );

requireDir( './gulp-tasks' );
Expand Down Expand Up @@ -89,7 +89,7 @@ gulp.task( 'default', () => {
} );

gulp.task( 'qunit', function() {
qunit( './tests/qunit/index.html' );
execSync( 'node-qunit-phantomjs ./tests/qunit/index.html', { stdio: [ 0, 1, 2 ] } );
} );

gulp.task( 'phpunit', function() {
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"test:visualtest": "npm run build && start-server-and-test storybook http-get://localhost:9001 backstopjs",
"test:visualapprove": "backstop approve --config=backstop.js",
"test:analyze": "webpack -p --mode=production --env.analyze=true --json --progress --profile > /tmp/stats.json && cp ./dist/assets/js/*.js /tmp && webpack-bundle-analyzer /tmp/stats.json",
"travis:test": "npm run build && npm run travis:qunit && npm run travis:phpunit && npm run travis:visualtest",
"travis:qunit": "gulp qunit",
"travis:phpunit": "gulp phpunit",
"travis:visualtest": "start-server-and-test storybook http-get://localhost:9001 travis:backstopjs",
"storybook": "start-storybook -s ./dist -p 9001 -c .storybook",
"backstopjs": "backstop test --config=backstop.js --docker",
Expand Down
4 changes: 2 additions & 2 deletions tests/qunit/utils.js → tests/qunit/assets/js/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ googlesitekit.modules = {
/**
* Test showErrorNotification.
*/
QUnit.test( 'showErrorNotification', function ( assert ) {
QUnit.test( 'showErrorNotification!', function ( assert ) {
testFunctions.showErrorNotification();
var value = wp.hooks.applyFilters( 'googlesitekit.ErrorNotification', [] );
assert.equal( value.toString().replace( /(\r\n|\n|\r)/gm, '' ), 'function (r) {return React.createElement(e,a()({},r,t,{OriginalComponent:n}));}' );
Expand Down Expand Up @@ -261,7 +261,7 @@ var gtag = function( type, name, sendto, category, label, value ) {
};
};

var sendAnalyticsTrackingEventExpected = '{"type":"event","name":"name","sendto":{"event_category":"category","event_label":"label","event_value":"value"}}';
var sendAnalyticsTrackingEventExpected = '{"type":"event","name":"name","sendto":{"event_category":"category","event_label":"label","event_value":"value","dimension1":"","dimension2":"true"}}';
QUnit.test( 'sendAnalyticsTrackingEvent', function ( assert ) {
window.googlesitekit.admin.trackingOptin = true;
const value = JSON.stringify( testFunctions.sendAnalyticsTrackingEvent( 'category', 'name', 'label', 'value' ) );
Expand Down
15 changes: 12 additions & 3 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
<script src='https://unpkg.com/[email protected]/lodash'></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en,Intl.~locale.de"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.4/polyfill.js"></script>
<script src='../../dist/assets/vendor/lodash.js'></script>
<script>
window.wp = {};
wp.hooks = {};
window.lodash = _;
window.googlesitekit = {
initialized: true,
setup: {
isFirstAdmin: true
}
};
var lodash = _.noConflict();
</script>
<script src='../../dist/assets/vendor/react.development.js'></script>
<script src='../../dist/assets/vendor/react-dom.development.js'></script>
<script src='../../dist/assets/js/externals/element.js'></script>
<script src='../../dist/assets/js/externals/i18n.js'></script>
<script src='../../dist/assets/js/externals/url.js'></script>
<script src='../../dist/assets/js/externals/hooks.js'></script>
Expand All @@ -25,10 +36,8 @@
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.7.0.js"></script>



<!-- Include the test scripts -->
<script src='utils.js'></script>
<script src='assets/js/util/index.js'></script>
</body>

</html>

0 comments on commit 3290fe2

Please sign in to comment.