From 01b5291cdb6fd0051184f3b26e2875fd2668b525 Mon Sep 17 00:00:00 2001 From: Aleksandar Benic Date: Sat, 8 Oct 2016 04:16:21 +0200 Subject: [PATCH 1/2] Convert engine_twig_tests.js to use tape --- test/engine_twig_tests.js | 267 +++++++++++++++++++------------------- 1 file changed, 137 insertions(+), 130 deletions(-) diff --git a/test/engine_twig_tests.js b/test/engine_twig_tests.js index c5f9773b4..62b0d76e3 100644 --- a/test/engine_twig_tests.js +++ b/test/engine_twig_tests.js @@ -1,11 +1,21 @@ "use strict"; /*eslint-disable dot-notation*/ +/*eslint-disable no-shadow*/ +var test = require('tape'); var path = require('path'); var pa = require('../core/lib/pattern_assembler'); var Pattern = require('../core/lib/object_factory').Pattern; var eol = require('os').EOL; +// don't run these tests unless twig is installed +var engineLoader = require('../core/lib/pattern_engines'); +if (!engineLoader.twig) { + test.only('Twig engine not installed, skipping tests.', function (test) { + test.end(); + }); +} + // fake pattern lab constructor: // sets up a fake patternlab object, which is needed by the pattern processing // apparatus. @@ -34,7 +44,7 @@ function fakePatternLab() { // function for testing sets of partials function testFindPartials(test, partialTests) { - test.expect(partialTests.length + 1); + test.plan(partialTests.length + 1); // setup current pattern from what we would have during execution // docs on partial syntax are here: @@ -56,136 +66,133 @@ function testFindPartials(test, partialTests) { test.equals(results[index], testString); }); - test.done(); + test.end(); } -exports['engine_twig'] = { - 'button twig pattern renders': function (test) { - test.expect(1); - - var patternPath = path.join('00-atoms', '00-general', '08-button.twig'); - var expectedValue = '' + eol + eol + 'Button' + eol; - - // do all the normal processing of the pattern - var patternlab = new fakePatternLab(); - var assembler = new pa(); - var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab); - assembler.process_pattern_recursive(patternPath, patternlab); - - test.equals(helloWorldPattern.render(), expectedValue); - test.done(); - }, - 'media object twig pattern can see the atoms-button and atoms-image partials and renders them': function (test) { - test.expect(1); - - // pattern paths - var buttonPatternPath = path.join('00-atoms', '00-general', '08-button.twig'); - var imagePatternPath = path.join('00-atoms', '00-general', '09-image.twig'); - var mediaObjectPatternPath = path.join('00-molecules', '00-general', '00-media-object.twig'); - - var expectedValue = '\n\n\n\n\n
\n \n\n \n\nButton\n\n\n
\n\n \n \n\n

Oh, hello world!

\n
\n
\n'; - - // set up environment - var patternlab = new fakePatternLab(); // environment - var assembler = new pa(); - - // do all the normal processing of the pattern - assembler.process_pattern_iterative(buttonPatternPath, patternlab); - assembler.process_pattern_iterative(imagePatternPath, patternlab); - var mediaObjectPattern = assembler.process_pattern_iterative(mediaObjectPatternPath, patternlab); - assembler.process_pattern_recursive(buttonPatternPath, patternlab); - assembler.process_pattern_recursive(imagePatternPath, patternlab); - assembler.process_pattern_recursive(mediaObjectPatternPath, patternlab); - - // test - // this pattern is too long - so just remove line endings on both sides and compare output - test.equals(mediaObjectPattern.render().replace(/\r?\n|\r/gm, ""), expectedValue.replace(/\r?\n|\r/gm, "")); - test.done(); - }, - // 'twig partials can render JSON values': function (test) { - // test.expect(1); - - // // pattern paths - // var pattern1Path = path.resolve( - // testPatternsPath, - // '00-atoms', - // '00-global', - // '00-helloworld-withdata.hbs' - // ); - - // // set up environment - // var patternlab = new fakePatternLab(); // environment - // var assembler = new pa(); - - // // do all the normal processing of the pattern - // var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab); - // assembler.process_pattern_recursive(pattern1Path, patternlab); - - // // test - // test.equals(helloWorldWithData.render(), 'Hello world!\nYeah, we got the subtitle from the JSON.\n'); - // test.done(); - // }, - // 'twig partials use the JSON environment from the calling pattern and can accept passed parameters': function (test) { - // test.expect(1); - - // // pattern paths - // var atomPath = path.resolve( - // testPatternsPath, - // '00-atoms', - // '00-global', - // '00-helloworld-withdata.hbs' - // ); - // var molPath = path.resolve( - // testPatternsPath, - // '00-molecules', - // '00-global', - // '00-call-atom-with-molecule-data.hbs' - // ); - - // // set up environment - // var patternlab = new fakePatternLab(); // environment - // var assembler = new pa(); - - // // do all the normal processing of the pattern - // var atom = assembler.process_pattern_iterative(atomPath, patternlab); - // var mol = assembler.process_pattern_iterative(molPath, patternlab); - // assembler.process_pattern_recursive(atomPath, patternlab); - // assembler.process_pattern_recursive(molPath, patternlab); - - // // test - // test.equals(mol.render(), '

Call with default JSON environment:

\nThis is Hello world!\nfrom the default JSON.\n\n\n

Call with passed parameter:

\nHowever, this is Hello world!\nfrom a totally different blob.\n\n'); - // test.done(); - // }, - 'find_pattern_partials finds partials': function (test) { - testFindPartials(test, [ - '{% include "atoms-image" %}', - "{% include 'atoms-image' %}", - "{%include 'atoms-image'%}", - "{% include 'molecules-template' only %}", - "{% include 'organisms-sidebar' ignore missing %}", - "{% include 'organisms-sidebar' ignore missing only %}" - ]); - }, - 'find_pattern_partials finds verbose partials': function (test) { - testFindPartials(test, [ - "{% include '01-molecules/06-components/03-comment-header.twig' %}", - "{% include '00-atoms/00-global/06-test' %}" - ]); - }, - 'find_pattern_partials finds partials with twig parameters': function (test) { - testFindPartials(test, [ - "{% include 'molecules-template' with {'foo': 'bar'} %}", - "{% include 'molecules-template' with vars %}", - "{% include 'molecules-template.twig' with {'foo': 'bar'} only %}", - "{% include 'organisms-sidebar' ignore missing with {'foo': 'bar'} %}" - ]); - } -}; +test('button twig pattern renders', function (test) { + test.plan(1); + + var patternPath = path.join('00-atoms', '00-general', '08-button.twig'); + var expectedValue = '' + eol + eol + 'Button' + eol; + + // do all the normal processing of the pattern + var patternlab = new fakePatternLab(); + var assembler = new pa(); + var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab); + assembler.process_pattern_recursive(patternPath, patternlab); + + test.equals(helloWorldPattern.render(), expectedValue); + test.end(); +}); + +test('media object twig pattern can see the atoms-button and atoms-image partials and renders them', function (test) { + test.plan(1); + + // pattern paths + var buttonPatternPath = path.join('00-atoms', '00-general', '08-button.twig'); + var imagePatternPath = path.join('00-atoms', '00-general', '09-image.twig'); + var mediaObjectPatternPath = path.join('00-molecules', '00-general', '00-media-object.twig'); + + var expectedValue = '\n\n\n\n\n
\n \n\n \n\nButton\n\n\n
\n\n \n \n\n

Oh, hello world!

\n
\n
\n'; + + // set up environment + var patternlab = new fakePatternLab(); // environment + var assembler = new pa(); + + // do all the normal processing of the pattern + assembler.process_pattern_iterative(buttonPatternPath, patternlab); + assembler.process_pattern_iterative(imagePatternPath, patternlab); + var mediaObjectPattern = assembler.process_pattern_iterative(mediaObjectPatternPath, patternlab); + assembler.process_pattern_recursive(buttonPatternPath, patternlab); + assembler.process_pattern_recursive(imagePatternPath, patternlab); + assembler.process_pattern_recursive(mediaObjectPatternPath, patternlab); + + // test + // this pattern is too long - so just remove line endings on both sides and compare output + test.equals(mediaObjectPattern.render().replace(/\r?\n|\r/gm, ""), expectedValue.replace(/\r?\n|\r/gm, "")); + test.end(); +}); + +test.skip('twig partials can render JSON values', function (test) { + test.plan(1); + + // pattern paths + var pattern1Path = path.resolve( + testPatternsPath, + '00-atoms', + '00-global', + '00-helloworld-withdata.hbs' + ); + // set up environment + var patternlab = new fakePatternLab(); // environment + var assembler = new pa(); + + // do all the normal processing of the pattern + var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab); + assembler.process_pattern_recursive(pattern1Path, patternlab); + + // test + test.equals(helloWorldWithData.render(), 'Hello world!\nYeah, we got the subtitle from the JSON.\n'); + test.end(); +}); + +test.skip('twig partials use the JSON environment from the calling pattern and can accept passed parameters', function (test) { + test.plan(1); + + // pattern paths + var atomPath = path.resolve( + testPatternsPath, + '00-atoms', + '00-global', + '00-helloworld-withdata.hbs' + ); + var molPath = path.resolve( + testPatternsPath, + '00-molecules', + '00-global', + '00-call-atom-with-molecule-data.hbs' + ); + + // set up environment + var patternlab = new fakePatternLab(); // environment + var assembler = new pa(); + + // do all the normal processing of the pattern + var atom = assembler.process_pattern_iterative(atomPath, patternlab); + var mol = assembler.process_pattern_iterative(molPath, patternlab); + assembler.process_pattern_recursive(atomPath, patternlab); + assembler.process_pattern_recursive(molPath, patternlab); + + // test + test.equals(mol.render(), '

Call with default JSON environment:

\nThis is Hello world!\nfrom the default JSON.\n\n\n

Call with passed parameter:

\nHowever, this is Hello world!\nfrom a totally different blob.\n\n'); + test.end(); +}); + +test('find_pattern_partials finds partials', function (test) { + testFindPartials(test, [ + '{% include "atoms-image" %}', + "{% include 'atoms-image' %}", + "{%include 'atoms-image'%}", + "{% include 'molecules-template' only %}", + "{% include 'organisms-sidebar' ignore missing %}", + "{% include 'organisms-sidebar' ignore missing only %}" + ]); +}); + +test('find_pattern_partials finds verbose partials', function (test) { + testFindPartials(test, [ + "{% include '01-molecules/06-components/03-comment-header.twig' %}", + "{% include '00-atoms/00-global/06-test' %}" + ]); +}); + +test('find_pattern_partials finds partials with twig parameters', function (test) { + testFindPartials(test, [ + "{% include 'molecules-template' with {'foo': 'bar'} %}", + "{% include 'molecules-template' with vars %}", + "{% include 'molecules-template.twig' with {'foo': 'bar'} only %}", + "{% include 'organisms-sidebar' ignore missing with {'foo': 'bar'} %}" + ]); +}); -// don't run these tests unless twig is installed -var engineLoader = require('../core/lib/pattern_engines'); -if (!engineLoader.twig) { - console.log("Twig engine not installed, skipping tests."); - delete exports.engine_twig; -} From 24901ec1263e15e90bac4f07d39ae711602ee667 Mon Sep 17 00:00:00 2001 From: Aleksandar Benic Date: Mon, 10 Oct 2016 19:43:17 +0200 Subject: [PATCH 2/2] Use tap instead of tape --- test/engine_twig_tests.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/engine_twig_tests.js b/test/engine_twig_tests.js index 62b0d76e3..5a8351f7a 100644 --- a/test/engine_twig_tests.js +++ b/test/engine_twig_tests.js @@ -2,7 +2,7 @@ /*eslint-disable dot-notation*/ /*eslint-disable no-shadow*/ -var test = require('tape'); +var tap = require('tap'); var path = require('path'); var pa = require('../core/lib/pattern_assembler'); var Pattern = require('../core/lib/object_factory').Pattern; @@ -11,9 +11,10 @@ var eol = require('os').EOL; // don't run these tests unless twig is installed var engineLoader = require('../core/lib/pattern_engines'); if (!engineLoader.twig) { - test.only('Twig engine not installed, skipping tests.', function (test) { + tap.test('Twig engine not installed, skipping tests.', function (test) { test.end(); }); + return; } // fake pattern lab constructor: @@ -69,7 +70,7 @@ function testFindPartials(test, partialTests) { test.end(); } -test('button twig pattern renders', function (test) { +tap.test('button twig pattern renders', function (test) { test.plan(1); var patternPath = path.join('00-atoms', '00-general', '08-button.twig'); @@ -85,7 +86,7 @@ test('button twig pattern renders', function (test) { test.end(); }); -test('media object twig pattern can see the atoms-button and atoms-image partials and renders them', function (test) { +tap.test('media object twig pattern can see the atoms-button and atoms-image partials and renders them', function (test) { test.plan(1); // pattern paths @@ -113,7 +114,7 @@ test('media object twig pattern can see the atoms-button and atoms-image partial test.end(); }); -test.skip('twig partials can render JSON values', function (test) { +tap.test('twig partials can render JSON values', {skip: true}, function (test) { test.plan(1); // pattern paths @@ -137,7 +138,7 @@ test.skip('twig partials can render JSON values', function (test) { test.end(); }); -test.skip('twig partials use the JSON environment from the calling pattern and can accept passed parameters', function (test) { +tap.test('twig partials use the JSON environment from the calling pattern and can accept passed parameters', {skip: true}, function (test) { test.plan(1); // pattern paths @@ -169,7 +170,7 @@ test.skip('twig partials use the JSON environment from the calling pattern and c test.end(); }); -test('find_pattern_partials finds partials', function (test) { +tap.test('find_pattern_partials finds partials', function (test) { testFindPartials(test, [ '{% include "atoms-image" %}', "{% include 'atoms-image' %}", @@ -180,14 +181,14 @@ test('find_pattern_partials finds partials', function (test) { ]); }); -test('find_pattern_partials finds verbose partials', function (test) { +tap.test('find_pattern_partials finds verbose partials', function (test) { testFindPartials(test, [ "{% include '01-molecules/06-components/03-comment-header.twig' %}", "{% include '00-atoms/00-global/06-test' %}" ]); }); -test('find_pattern_partials finds partials with twig parameters', function (test) { +tap.test('find_pattern_partials finds partials with twig parameters', function (test) { testFindPartials(test, [ "{% include 'molecules-template' with {'foo': 'bar'} %}", "{% include 'molecules-template' with vars %}",