diff --git a/.gitignore b/.gitignore index 2d2b47d..e17d846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -node_modules \ No newline at end of file +node_modules +test/pages \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 3fd8d64..20eda8e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,12 @@ -var spawn = require('child_process').spawn, - gulp = require('gulp'), - gutil = require('gulp-util'); +var spawn = require('child_process').spawn; +var gulp = require('gulp'); +var gutil = require('gulp-util'); +var nunjucksRender = require('gulp-nunjucks-render'); -gulp.task('test', function () { - var tests = ['test/']; + +gulp.task('test', ['nunjucks'], function () { + + var tests = ['test/casper/tests/']; var casperChild = spawn('casperjs', ['test'].concat(tests)); casperChild.stdout.on('data', function (data) { @@ -18,4 +21,16 @@ gulp.task('test', function () { process.exit(1); } }); + +}); + +gulp.task('nunjucks', function() { + + // Gets .html and .nunjucks files in pages + return gulp.src('test/nunjucks/*.nunjucks') + .pipe(nunjucksRender({ + path: ['test/nunjucks/partials/', 'test/nunjucks/layouts/'] + })) + .pipe(gulp.dest('test/pages/')) + }); \ No newline at end of file diff --git a/package.json b/package.json index e1b96a7..f25015e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "devDependencies": { "casperjs": "^1.1.0-beta5", "gulp": "^3.9.1", + "gulp-nunjucks-render": "^2.0.0", "gulp-util": "^3.0.7" } } diff --git a/test/casper/include/test.js b/test/casper/include/test.js new file mode 100644 index 0000000..fce7b6b --- /dev/null +++ b/test/casper/include/test.js @@ -0,0 +1,9 @@ +module.exports = { + sayHi: function() { + console.log('Hello from module.exports'); + } +}; + +casper.sayHiAgain = function() { + this.echo('Hello from casper function'); +}; \ No newline at end of file diff --git a/test/test1.js b/test/casper/tests/test1.js similarity index 68% rename from test/test1.js rename to test/casper/tests/test1.js index 14c803f..41fdb3b 100644 --- a/test/test1.js +++ b/test/casper/tests/test1.js @@ -1,6 +1,8 @@ +var includeTest = require('../include/test'); + casper.test.begin('testing.html contains stuff', 3, function (test) { - casper.start('./test/test1.html', function () { + casper.start('./test/pages/test1.html', function () { test.assertTitle('Test Page'); test.assertSelectorHasText('h1', 'Test!'); }); @@ -8,6 +10,9 @@ casper.test.begin('testing.html contains stuff', 3, function (test) { casper.then(function () { this.click('button'); test.assertSelectorHasText('h1', 'New title'); + + includeTest.sayHi(); + casper.sayHiAgain(); }); casper.run(function() { diff --git a/test/nunjucks/layouts/master.html b/test/nunjucks/layouts/master.html new file mode 100644 index 0000000..9b07d71 --- /dev/null +++ b/test/nunjucks/layouts/master.html @@ -0,0 +1,18 @@ + + + + Test Page + + {% block styles %}{% endblock %} + + + +{% block content %}{% endblock %} + +{% block includes %}{% endblock %} + + + + \ No newline at end of file diff --git a/test/nunjucks/partials/accordion.default.nunjucks b/test/nunjucks/partials/accordion.default.nunjucks new file mode 100644 index 0000000..a1f71ca --- /dev/null +++ b/test/nunjucks/partials/accordion.default.nunjucks @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/nunjucks/test1.nunjucks b/test/nunjucks/test1.nunjucks new file mode 100644 index 0000000..80b3506 --- /dev/null +++ b/test/nunjucks/test1.nunjucks @@ -0,0 +1,17 @@ +{% extends "master.html" %} + +{% block content %} + +

Test!

+ {% include "accordion.default.nunjucks" %} + +{% endblock %} + + +{% block scripts %} + + document.querySelector('button').addEventListener('click', function () { + document.querySelector('h1').innerHTML = 'New title'; + }); + +{% endblock %} \ No newline at end of file diff --git a/test/test1.html b/test/test1.html deleted file mode 100644 index 96aa405..0000000 --- a/test/test1.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - Test Page - - - -

Test!

- - - - - - \ No newline at end of file