Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Headless Chrome over PhantomJS for (QUnit) tests #89

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
4 changes: 2 additions & 2 deletions docs/Coding_Guidelines.md
Expand Up @@ -93,12 +93,12 @@ It is highly recommended to integrate ESLint with your IDE. Instructions can be

```js
// Scroll
$(document).on(estatico.events.scroll, function(event, originalEvent) {
$(document).on(estatico.events.throttledscroll, function(event, originalEvent) {
console.log(originalEvent);
}.bind(this));

// Resize
$(document).on(estatico.events.resize, function(event, originalEvent) {
$(document).on(estatico.events.debouncedresize, function(event, originalEvent) {
console.log(originalEvent);
}.bind(this));
```
Expand Down
6 changes: 3 additions & 3 deletions docs/Tasks.md
Expand Up @@ -17,7 +17,7 @@ Create static webserver with livereload functionality, serve build directory on
### `gulp build`
Create build by running every HTML, CSS, JavaScript and media task.

* Prompts whether the `js:qunit` task should run in the end (default: yes).
* Prompts whether the `js:test` task should run in the end (default: yes).
* For non-interactive mode: `gulp --interactive=false --skipTests`

### `gulp clean`
Expand Down Expand Up @@ -75,8 +75,8 @@ Create static JSON data mocks
### `gulp js:modernizr`
Generate customized Modernizr build (using `Customizr`, crawling through files and gathering up references to Modernizr tests).

### `gulp js:qunit`
Run QUnit tests (using PhantomJS).
### `gulp js:test`
Open built HTML files in headless Chrome, report console errors and run QUnit tests.

### `gulp media:copy`
Copy specific media files to build directory.
Expand Down
6 changes: 3 additions & 3 deletions gulp/build.js
Expand Up @@ -4,7 +4,7 @@
* @function `gulp build`
* @desc Create build by running every HTML, CSS, JavaScript and media task.
*
* * Prompts whether the `js:qunit` task should run in the end (default: yes).
* * Prompts whether the `js:test` task should run in the end (default: yes).
* * For non-interactive mode: `gulp --interactive=false --skipTests`
*/

Expand Down Expand Up @@ -43,7 +43,7 @@ gulp.task(taskName, function(cb) {
'media:copy',
'media:imageversions'
],
'js:qunit',
'js:test',
function(err) {
if (err) {
helpers.errors(err);
Expand All @@ -54,7 +54,7 @@ gulp.task(taskName, function(cb) {
];

if (skipTests) {
runTasks = _.without(runTasks, 'js:qunit');
runTasks = _.without(runTasks, 'js:test');
}

runSequence.apply(this, runTasks);
Expand Down
43 changes: 40 additions & 3 deletions gulp/js/default.js
Expand Up @@ -12,12 +12,16 @@ var taskName = 'js',
taskConfig = {
src: [
'./source/assets/js/main.js',
'./source/assets/js/head.js'
'./source/assets/js/head.js',
'./source/preview/assets/js/test.js',
'./source/demo/modules/**/*.test.js'
],
devSrc: [
'./source/assets/js/dev.js'
],
srcBase: './source/assets/js/',
testSrcRoot: './source/',
testSrcBase: './source/preview/assets/js/',
dest: './build/assets/js/',
destBase: './build/',
destAsyncSuffix: 'async/',
Expand All @@ -42,10 +46,17 @@ var taskName = 'js',
var helpers = require('require-dir')('../../helpers'),
_ = require('lodash'),
path = require('path'),
glob = require('glob'),
webpack = require('webpack'),
livereload = require('gulp-livereload');

var src = config.src,
var src = taskConfig.src.reduce(function(paths, pathGlob) {
var resolvedGlob = glob.sync(pathGlob).map(function(file) {
return path.resolve(file);
});

return paths.concat(resolvedGlob);
}, []),
compiler;

// Optionally build dev scripts
Expand All @@ -55,7 +66,14 @@ var taskName = 'js',

compiler = webpack({
// Create a map of entries, i.e. {'assets/js/main': './source/assets/js/main.js'}
entry: helpers.webpack.getEntries(src, config.srcBase),
entry: helpers.webpack.getEntries(src, config.srcBase, function(key, srcBase, file) {
// Move test files into 'preview/assets/js'
if (path.extname(key) === '.test') {
key = path.join(path.relative(config.srcBase, config.testSrcBase), path.relative(config.testSrcRoot, file)).replace(path.extname(file), '');
}

return key;
}),
module: {
loaders: [
{
Expand Down Expand Up @@ -85,9 +103,28 @@ var taskName = 'js',
}]
]
}
},
{
test: /qunit\.js$/,
loader: 'expose?QUnit'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
]
},
externals: function(context, request, callback) {
// Do not include jQuery in test-related files
if (request === 'jquery' && /(\/preview\/assets\/js|\/modules\/)/.test(context)) {
return callback(null, 'jQuery');
// Do not include QUnit in every single test file
} else if (request === 'qunitjs' && /\/modules\//.test(context)) {
return callback(null, 'QUnit');
}

callback();
},

// Minifiy in prod mode
plugins: [
Expand Down
188 changes: 0 additions & 188 deletions gulp/js/qunit.js

This file was deleted.