Skip to content

Commit

Permalink
Merge a342846 into bac08a4
Browse files Browse the repository at this point in the history
  • Loading branch information
trentmwillis committed Aug 5, 2017
2 parents bac08a4 + a342846 commit 5388313
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
17 changes: 10 additions & 7 deletions Gruntfile.js
Expand Up @@ -10,8 +10,9 @@ var reportDir = "build/report";
var HAS_ASYNC_FUNCTIONS = semver.satisfies( process.version, ">= 7.10" );

module.exports = function( grunt ) {
var livereloadPort = grunt.option( "livereload-port" ) || 35729;

// Load grunt tasks from NPM packages
// Load grunt tasks from NPM packages
require( "load-grunt-tasks" )( grunt );

function preprocess( code ) {
Expand All @@ -31,7 +32,7 @@ module.exports = function( grunt ) {
options: {
port: 8000,
base: ".",
livereload: true
livereload: livereloadPort
}
}
},
Expand Down Expand Up @@ -191,8 +192,7 @@ module.exports = function( grunt ) {
options: {
atBegin: true,
spawn: false,
interrupt: true,
livereload: true
interrupt: true
},
files: [
".eslintrc.json",
Expand All @@ -203,10 +203,13 @@ module.exports = function( grunt ) {
"test/*.{html,js}",
"test/**/*.html"
],
tasks: [ "build", "livereload", "test-in-watch" ]
},

// TODO insert a new task to prompt reloads between "build" and "test-in-watch"
// https://github.com/gruntjs/grunt-contrib-watch/issues/186#issuecomment-72180420
tasks: [ "build", "test-in-watch" ]
livereload: {
options: {
port: livereloadPort
}
},

instrument: {
Expand Down
17 changes: 17 additions & 0 deletions build/tasks/livereload.js
@@ -0,0 +1,17 @@
/* eslint-env node */
var livereload = require( "tiny-lr" );
var server;

module.exports = function( grunt ) {
grunt.registerTask( "livereload", function() {
if ( !server ) {
var port = this.options().port;
server = livereload();
server.listen( port, function() {
console.log( "Livereload server listening on port " + port );
} );
}

server.changed( { body: { files: [ "file-path-does-not-matter.js" ] } } );
} );
};
14 changes: 8 additions & 6 deletions build/tasks/test-on-node.js
Expand Up @@ -2,7 +2,6 @@
"use strict";

var async = require( "async" );
var path = require( "path" );

module.exports = function( grunt ) {
grunt.registerMultiTask( "test-on-node", function() {
Expand Down Expand Up @@ -64,21 +63,24 @@ module.exports = function( grunt ) {
].join( "" );
}

function requireFresh( path ) {
var resolvedPath = require.resolve( path );
delete require.cache[ resolvedPath ];
return require( path );
}

function runQUnit( file, runEnd ) {

// Resolve current QUnit path and remove it from the require cache
// to avoid stacking the QUnit logs.
var QUnitFile = path.resolve( __dirname, "../../dist/qunit.js" );
delete require.cache[ QUnitFile ];

var QUnit = require( QUnitFile );
var QUnit = requireFresh( "../../dist/qunit" );

// Expose QUnit to the global scope to be seen on the other tests.
global.QUnit = QUnit;

QUnit.config.autostart = false;

require( "../../" + file );
requireFresh( "../../" + file );

registerEvents( QUnit, file, runEnd );

Expand Down

0 comments on commit 5388313

Please sign in to comment.