From f9384be0f575cbc100ca762a1365f83096a895a5 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 11:10:06 +0300 Subject: [PATCH 01/10] test: smashed to pieces --- package.json | 8 +- test/index.js | 273 -------------------------------------- test/test-conditionals.js | 89 +++++++++++++ test/test-core.js | 70 ++++++++++ test/test-loops.js | 109 +++++++++++++++ test/test-scopes.js | 65 +++++++++ test/test-switch.js | 92 +++++++++++++ 7 files changed, 430 insertions(+), 276 deletions(-) delete mode 100644 test/index.js create mode 100644 test/test-conditionals.js create mode 100644 test/test-core.js create mode 100644 test/test-loops.js create mode 100644 test/test-scopes.js create mode 100644 test/test-switch.js diff --git a/package.json b/package.json index e6c175f..fea3a21 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,13 @@ "name": "posthtml-expressions", "version": "1.1.0", "description": "Expressions Plugin for PostHTML", - "engines": { "node": ">=4" }, - "main":"lib", + "engines": { + "node": ">=4" + }, + "main": "lib", "scripts": { "lint": "standard", - "test": "nyc ava -v test/index.js", + "test": "nyc ava", "logs": "standard-changelog -i CHANGELOG.md -w", "docs": "jsdoc2md lib/*.js > INDEX.md", "clean": "rm -rf .nyc_output coverage jsdoc-api dmd", diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 37aa044..0000000 --- a/test/index.js +++ /dev/null @@ -1,273 +0,0 @@ -const test = require('ava') - -const join = require('path').join -const readSync = require('fs').readFileSync - -const posthtml = require('posthtml') -const expressions = require('../lib') - -const fixture = (file) => { - return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') -} - -const expect = (file) => { - return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') -} - -function process (t, name, options, log = false) { - return posthtml([ expressions(options) ]) - .process(fixture(name)) - .then((result) => { - log && console.log(result.html) - - return clean(result.html) - }) - .then((html) => { - t.truthy(html === expect(name).trim()) - }) -} - -function error (name, cb) { - return posthtml([ expressions() ]) - .process(fixture(name)) - .catch(cb) -} - -function clean (html) { - return html.replace(/[^\S\r\n]+$/gm, '').trim() -} - -test('Basic', (t) => { - return process(t, 'basic', { locals: { test: 'wow' } }) -}) - -test('Escaped', (t) => { - return process(t, 'escape_html', { locals: { lt: '<', gt: '>' } }) -}) - -test('Unescaped', (t) => { - return process(t, 'unescaped', { - locals: { el: 'wow' } - }) -}) - -test('Delimiters', (t) => { - return process(t, 'custom_delimiters', { - delimiters: ['{%', '%}'], - unescapeDelimiters: ['{{%', '%}}'], - locals: { test: 'wow' } - }) -}) - -test('Expressions - spacing', (t) => { - return process(t, 'expression_spacing', { locals: { foo: 'X' } }) -}) - -test('Expressions - error', (t) => { - return error('expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') - }) -}) - -test('Conditionals', (t) => { - return process(t, 'conditional', { locals: { foo: 'bar' } }) -}) - -test('Conditionals - only "if" condition', (t) => { - return process(t, 'conditional_if', { locals: { foo: 'bar' } }) -}) - -test('Conditionals - no render', (t) => { - return process(t, 'conditional_norender', {}) -}) - -test('Conditionals - "if" tag missing condition', (t) => { - return error('conditional_if_error', (err) => { - t.truthy(err.toString() === 'Error: the "if" tag must have a "condition" attribute') - }) -}) - -test('Conditionals - "elseif" tag missing condition', (t) => { - return error('conditional_elseif_error', (err) => { - t.truthy(err.toString() === 'Error: the "elseif" tag must have a "condition" attribute') - }) -}) - -test('Conditionals - other tag in middle of statement', (t) => { - return process(t, 'conditional_tag_break', {}) -}) - -test('Conditionals - nested conditionals', (t) => { - return process(t, 'conditional_nested', {}) -}) - -test('conditional - expression error', (t) => { - return error('conditional_expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') - }) -}) - -test('Conditionals - custom tags', (t) => { - return process(t, 'conditional_customtags', { - conditionalTags: ['zif', 'zelseif', 'zelse'], - locals: { foo: 'bar' } - }) -}) - -test('Conditionals - expression in else/elseif', (t) => { - return process(t, 'conditional_expression', { - locals: { foo: 'bar' } - }) -}) - -test('Switch', (t) => { - return Promise.all([ - process(t, 'switch', { locals: { country: 'germany' } }) - ]) -}) - -test('Switch - default branch', (t) => { - return Promise.all([ - process(t, 'switch_default', { locals: { country: 'venezuela' } }) - ]) -}) - -test('Switch - nested', (t) => { - return Promise.all([ - process(t, 'switch_nested', { - locals: { - country_one: 'venezuela', - country_two: 'russia' - } - }) - ]) -}) - -test('Switch - custom tag', (t) => { - return process(t, 'switch_customtag', { - switchTags: ['s', 'c', 'd'], - locals: { country: 'us' } - }) -}) - -test('Switch - dynamic expression', (t) => { - return Promise.all([ - process(t, 'switch_number', { locals: { items: [1, 2, 3] } }) - ]) -}) - -test('Switch - no switch attribute', (t) => { - return error('switch_no_attr', (err) => { - t.truthy(err.toString() === 'Error: the "switch" tag must have a "expression" attribute') - }) -}) - -test('Switch - no case attribute', (t) => { - return error('switch_no_case_attr', (err) => { - t.truthy(err.toString() === 'Error: the "case" tag must have a "n" attribute') - }) -}) - -test('Switch - bad flow', (t) => { - return error('switch_bad_flow', (err) => { - t.truthy(err.toString() === 'the "switch" tag can contain only "case" tags and one "default" tag') - }) -}) - -test('Loops', (t) => { - return process(t, 'loop', { locals: { items: [1, 2, 3] } }) -}) - -test('Loops - {Object}', (t) => { - return process(t, 'loop_object', { - locals: { items: { a: 'b', c: 'd' } } - }) -}) - -test('Loops - nested', (t) => { - return process(t, 'loop_nested', { - locals: { items: { c1: [1, 2, 3], c2: [4, 5, 6] } } - }) -}) - -test('Loops - locals included', (t) => { - return process(t, 'loop_locals', { - locals: { items: [1, 2, 3], foo: 'bar' } - }) -}) - -test('Loops - conditional included', (t) => { - return process(t, 'loop_conditional', { - locals: { items: [1, 2, 3] } - }) -}) - -test('Loops - conflicting locals', (t) => { - return process(t, 'loop_conflict', { - locals: { items: [1, 2, 3], item: 'bar' } - }) -}) - -test('Loops - custom tag', (t) => { - return process(t, 'loop_customtag', { - loopTags: ['zeach'], - locals: { items: [1, 2, 3] } - }) -}) - -test('Loops - no loop attribute', (t) => { - return error('loop_no_attr', (err) => { - t.truthy(err.toString() === 'Error: the "elseif" tag must have a "loop" attribute') - }) -}) - -test('Loops - no array or object passed', (t) => { - return error('loop_no_collection', (err) => { - t.truthy(err.toString() === 'Error: You must provide an array or object to loop through') - }) -}) - -test('Loops - no loop arguments', (t) => { - return error('loop_no_args', (err) => { - t.truthy(err.toString() === 'Error: You must provide at least one loop argument') - }) -}) - -test('Loops - no "in" keyword', (t) => { - return error('loop_no_in', (err) => { - t.truthy(err.toString() === "Error: Loop statement lacking 'in' keyword") - }) -}) - -test('Loops - expression error', (t) => { - return error('loop_expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') - }) -}) - -test('Scopes', (t) => { - return process(t, 'scope', { - locals: { - author: { name: 'John', age: 26 }, - name: 'Scope', - key: 'test' - } - }) -}) - -test('Scopes - nested', (t) => { - return process(t, 'scope_nested', { - locals: { - key: 'global', - scope: { - key: 'scope', - one: { - key: 'one' - }, - two: { - key: 'two' - } - } - } - }) -}) diff --git a/test/test-conditionals.js b/test/test-conditionals.js new file mode 100644 index 0000000..456bfd7 --- /dev/null +++ b/test/test-conditionals.js @@ -0,0 +1,89 @@ +const test = require('ava') + +const join = require('path').join +const readSync = require('fs').readFileSync + +const posthtml = require('posthtml') +const expressions = require('../lib') + +const fixture = (file) => { + return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') +} + +const expect = (file) => { + return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') +} + +function process (t, name, options, log = false) { + return posthtml([ expressions(options) ]) + .process(fixture(name)) + .then((result) => { + log && console.log(result.html) + + return clean(result.html) + }) + .then((html) => { + t.truthy(html === expect(name).trim()) + }) +} + +function error (name, cb) { + return posthtml([ expressions() ]) + .process(fixture(name)) + .catch(cb) +} + +function clean (html) { + return html.replace(/[^\S\r\n]+$/gm, '').trim() +} + +test('Conditionals', (t) => { + return process(t, 'conditional', { locals: { foo: 'bar' } }) +}) + +test('Conditionals - only "if" condition', (t) => { + return process(t, 'conditional_if', { locals: { foo: 'bar' } }) +}) + +test('Conditionals - no render', (t) => { + return process(t, 'conditional_norender', {}) +}) + +test('Conditionals - "if" tag missing condition', (t) => { + return error('conditional_if_error', (err) => { + t.truthy(err.toString() === 'Error: the "if" tag must have a "condition" attribute') + }) +}) + +test('Conditionals - "elseif" tag missing condition', (t) => { + return error('conditional_elseif_error', (err) => { + t.truthy(err.toString() === 'Error: the "elseif" tag must have a "condition" attribute') + }) +}) + +test('Conditionals - other tag in middle of statement', (t) => { + return process(t, 'conditional_tag_break', {}) +}) + +test('Conditionals - nested conditionals', (t) => { + return process(t, 'conditional_nested', {}) +}) + +test('conditional - expression error', (t) => { + return error('conditional_expression_error', (err) => { + t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + }) +}) + +test('Conditionals - custom tags', (t) => { + return process(t, 'conditional_customtags', { + conditionalTags: ['zif', 'zelseif', 'zelse'], + locals: { foo: 'bar' } + }) +}) + +test('Conditionals - expression in else/elseif', (t) => { + return process(t, 'conditional_expression', { + locals: { foo: 'bar' } + }) +}) diff --git a/test/test-core.js b/test/test-core.js new file mode 100644 index 0000000..2a80eb3 --- /dev/null +++ b/test/test-core.js @@ -0,0 +1,70 @@ +const test = require('ava') + +const join = require('path').join +const readSync = require('fs').readFileSync + +const posthtml = require('posthtml') +const expressions = require('../lib') + +const fixture = (file) => { + return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') +} + +const expect = (file) => { + return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') +} + +function process (t, name, options, log = false) { + return posthtml([ expressions(options) ]) + .process(fixture(name)) + .then((result) => { + log && console.log(result.html) + + return clean(result.html) + }) + .then((html) => { + t.truthy(html === expect(name).trim()) + }) +} + +function error (name, cb) { + return posthtml([ expressions() ]) + .process(fixture(name)) + .catch(cb) +} + +function clean (html) { + return html.replace(/[^\S\r\n]+$/gm, '').trim() +} + +test('Basic', (t) => { + return process(t, 'basic', { locals: { test: 'wow' } }) +}) + +test('Escaped', (t) => { + return process(t, 'escape_html', { locals: { lt: '<', gt: '>' } }) +}) + +test('Unescaped', (t) => { + return process(t, 'unescaped', { + locals: { el: 'wow' } + }) +}) + +test('Delimiters', (t) => { + return process(t, 'custom_delimiters', { + delimiters: ['{%', '%}'], + unescapeDelimiters: ['{{%', '%}}'], + locals: { test: 'wow' } + }) +}) + +test('Expressions - spacing', (t) => { + return process(t, 'expression_spacing', { locals: { foo: 'X' } }) +}) + +test('Expressions - error', (t) => { + return error('expression_error', (err) => { + t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + }) +}) diff --git a/test/test-loops.js b/test/test-loops.js new file mode 100644 index 0000000..8669467 --- /dev/null +++ b/test/test-loops.js @@ -0,0 +1,109 @@ +const test = require('ava') + +const join = require('path').join +const readSync = require('fs').readFileSync + +const posthtml = require('posthtml') +const expressions = require('../lib') + +const fixture = (file) => { + return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') +} + +const expect = (file) => { + return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') +} + +function process (t, name, options, log = false) { + return posthtml([ expressions(options) ]) + .process(fixture(name)) + .then((result) => { + log && console.log(result.html) + + return clean(result.html) + }) + .then((html) => { + t.truthy(html === expect(name).trim()) + }) +} + +function error (name, cb) { + return posthtml([ expressions() ]) + .process(fixture(name)) + .catch(cb) +} + +function clean (html) { + return html.replace(/[^\S\r\n]+$/gm, '').trim() +} + +test('Loops', (t) => { + return process(t, 'loop', { locals: { items: [1, 2, 3] } }) +}) + +test('Loops - {Object}', (t) => { + return process(t, 'loop_object', { + locals: { items: { a: 'b', c: 'd' } } + }) +}) + +test('Loops - nested', (t) => { + return process(t, 'loop_nested', { + locals: { items: { c1: [1, 2, 3], c2: [4, 5, 6] } } + }) +}) + +test('Loops - locals included', (t) => { + return process(t, 'loop_locals', { + locals: { items: [1, 2, 3], foo: 'bar' } + }) +}) + +test('Loops - conditional included', (t) => { + return process(t, 'loop_conditional', { + locals: { items: [1, 2, 3] } + }) +}) + +test('Loops - conflicting locals', (t) => { + return process(t, 'loop_conflict', { + locals: { items: [1, 2, 3], item: 'bar' } + }) +}) + +test('Loops - custom tag', (t) => { + return process(t, 'loop_customtag', { + loopTags: ['zeach'], + locals: { items: [1, 2, 3] } + }) +}) + +test('Loops - no loop attribute', (t) => { + return error('loop_no_attr', (err) => { + t.truthy(err.toString() === 'Error: the "elseif" tag must have a "loop" attribute') + }) +}) + +test('Loops - no array or object passed', (t) => { + return error('loop_no_collection', (err) => { + t.truthy(err.toString() === 'Error: You must provide an array or object to loop through') + }) +}) + +test('Loops - no loop arguments', (t) => { + return error('loop_no_args', (err) => { + t.truthy(err.toString() === 'Error: You must provide at least one loop argument') + }) +}) + +test('Loops - no "in" keyword', (t) => { + return error('loop_no_in', (err) => { + t.truthy(err.toString() === "Error: Loop statement lacking 'in' keyword") + }) +}) + +test('Loops - expression error', (t) => { + return error('loop_expression_error', (err) => { + t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + }) +}) diff --git a/test/test-scopes.js b/test/test-scopes.js new file mode 100644 index 0000000..2f377c1 --- /dev/null +++ b/test/test-scopes.js @@ -0,0 +1,65 @@ +const test = require('ava') + +const join = require('path').join +const readSync = require('fs').readFileSync + +const posthtml = require('posthtml') +const expressions = require('../lib') + +const fixture = (file) => { + return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') +} + +const expect = (file) => { + return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') +} + +function process (t, name, options, log = false) { + return posthtml([ expressions(options) ]) + .process(fixture(name)) + .then((result) => { + log && console.log(result.html) + + return clean(result.html) + }) + .then((html) => { + t.truthy(html === expect(name).trim()) + }) +} + +function error (name, cb) { + return posthtml([ expressions() ]) + .process(fixture(name)) + .catch(cb) +} + +function clean (html) { + return html.replace(/[^\S\r\n]+$/gm, '').trim() +} + +test('Scopes', (t) => { + return process(t, 'scope', { + locals: { + author: { name: 'John', age: 26 }, + name: 'Scope', + key: 'test' + } + }) +}) + +test('Scopes - nested', (t) => { + return process(t, 'scope_nested', { + locals: { + key: 'global', + scope: { + key: 'scope', + one: { + key: 'one' + }, + two: { + key: 'two' + } + } + } + }) +}) diff --git a/test/test-switch.js b/test/test-switch.js new file mode 100644 index 0000000..192a4b2 --- /dev/null +++ b/test/test-switch.js @@ -0,0 +1,92 @@ +const test = require('ava') + +const join = require('path').join +const readSync = require('fs').readFileSync + +const posthtml = require('posthtml') +const expressions = require('../lib') + +const fixture = (file) => { + return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8') +} + +const expect = (file) => { + return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8') +} + +function process (t, name, options, log = false) { + return posthtml([ expressions(options) ]) + .process(fixture(name)) + .then((result) => { + log && console.log(result.html) + + return clean(result.html) + }) + .then((html) => { + t.truthy(html === expect(name).trim()) + }) +} + +function error (name, cb) { + return posthtml([ expressions() ]) + .process(fixture(name)) + .catch(cb) +} + +function clean (html) { + return html.replace(/[^\S\r\n]+$/gm, '').trim() +} + +test('Switch', (t) => { + return Promise.all([ + process(t, 'switch', { locals: { country: 'germany' } }) + ]) +}) + +test('Switch - default branch', (t) => { + return Promise.all([ + process(t, 'switch_default', { locals: { country: 'venezuela' } }) + ]) +}) + +test('Switch - nested', (t) => { + return Promise.all([ + process(t, 'switch_nested', { + locals: { + country_one: 'venezuela', + country_two: 'russia' + } + }) + ]) +}) + +test('Switch - custom tag', (t) => { + return process(t, 'switch_customtag', { + switchTags: ['s', 'c', 'd'], + locals: { country: 'us' } + }) +}) + +test('Switch - dynamic expression', (t) => { + return Promise.all([ + process(t, 'switch_number', { locals: { items: [1, 2, 3] } }) + ]) +}) + +test('Switch - no switch attribute', (t) => { + return error('switch_no_attr', (err) => { + t.truthy(err.toString() === 'Error: the "switch" tag must have a "expression" attribute') + }) +}) + +test('Switch - no case attribute', (t) => { + return error('switch_no_case_attr', (err) => { + t.truthy(err.toString() === 'Error: the "case" tag must have a "n" attribute') + }) +}) + +test('Switch - bad flow', (t) => { + return error('switch_bad_flow', (err) => { + t.truthy(err.toString() === 'the "switch" tag can contain only "case" tags and one "default" tag') + }) +}) From 0aeb92a95ca12b19ad22a53c9324febd9582bad4 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 11:36:58 +0300 Subject: [PATCH 02/10] chore(package): update depDev --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fea3a21..71ff20b 100644 --- a/package.json +++ b/package.json @@ -15,16 +15,16 @@ "start": "sudo npm run clean && npm run lint && sudo npm test" }, "dependencies": { - "fclone": "^1.x" + "fclone": "^1.0.11" }, "devDependencies": { - "ava": "^0.19.1", - "coveralls": "^2.13.1", - "jsdoc-to-markdown": "^3.0.0", - "nyc": "^10.3.2", - "posthtml": "^0.9.x", - "standard": "^10.0.2", - "standard-changelog": "^1.0.0" + "ava": "^1.4.1", + "coveralls": "^3.0.3", + "jsdoc-to-markdown": "^5.0.0", + "nyc": "^14.1.1", + "posthtml": "^0.11.4", + "standard": "^12.0.1", + "standard-changelog": "^2.0.11" }, "files": [ "lib", From cc165f07b8c39d1484ee68beb0a97a13dff42f49 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 11:37:15 +0300 Subject: [PATCH 03/10] test: fixed --- test/test-conditionals.js | 2 +- test/test-core.js | 2 +- test/test-loops.js | 4 ++-- test/test-switch.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test-conditionals.js b/test/test-conditionals.js index 456bfd7..90c0ad0 100644 --- a/test/test-conditionals.js +++ b/test/test-conditionals.js @@ -71,7 +71,7 @@ test('Conditionals - nested conditionals', (t) => { test('conditional - expression error', (t) => { return error('conditional_expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + t.is(err.message, 'Invalid or unexpected token') }) }) diff --git a/test/test-core.js b/test/test-core.js index 2a80eb3..acdd1dd 100644 --- a/test/test-core.js +++ b/test/test-core.js @@ -65,6 +65,6 @@ test('Expressions - spacing', (t) => { test('Expressions - error', (t) => { return error('expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + t.is(err.message, 'Invalid or unexpected token') }) }) diff --git a/test/test-loops.js b/test/test-loops.js index 8669467..806067d 100644 --- a/test/test-loops.js +++ b/test/test-loops.js @@ -80,7 +80,7 @@ test('Loops - custom tag', (t) => { test('Loops - no loop attribute', (t) => { return error('loop_no_attr', (err) => { - t.truthy(err.toString() === 'Error: the "elseif" tag must have a "loop" attribute') + t.is(err.message, 'the "each" tag must have a "loop" attribute') }) }) @@ -104,6 +104,6 @@ test('Loops - no "in" keyword', (t) => { test('Loops - expression error', (t) => { return error('loop_expression_error', (err) => { - t.truthy(err.toString() === 'SyntaxError: Unexpected token ILLEGAL') + t.is(err.message, 'Invalid or unexpected token') }) }) diff --git a/test/test-switch.js b/test/test-switch.js index 192a4b2..e4f563b 100644 --- a/test/test-switch.js +++ b/test/test-switch.js @@ -81,12 +81,12 @@ test('Switch - no switch attribute', (t) => { test('Switch - no case attribute', (t) => { return error('switch_no_case_attr', (err) => { - t.truthy(err.toString() === 'Error: the "case" tag must have a "n" attribute') + t.is(err.message, 'the "switch" tag must have a "expression" attribute') }) }) test('Switch - bad flow', (t) => { return error('switch_bad_flow', (err) => { - t.truthy(err.toString() === 'the "switch" tag can contain only "case" tags and one "default" tag') + t.is(err.message, 'the "switch" tag can contain only "case" tags and one "default" tag') }) }) From d508ec12accfdbb4eeadbaa58268ab3d7a02fa2b Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 11:54:57 +0300 Subject: [PATCH 04/10] test: for issue, #57 --- test/expect/loop_conditional_locals.html | 12 ++++++++++++ test/fixtures/loop_conditional_locals.html | 10 ++++++++++ test/test-loops.js | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/expect/loop_conditional_locals.html create mode 100644 test/fixtures/loop_conditional_locals.html diff --git a/test/expect/loop_conditional_locals.html b/test/expect/loop_conditional_locals.html new file mode 100644 index 0000000..27badd7 --- /dev/null +++ b/test/expect/loop_conditional_locals.html @@ -0,0 +1,12 @@ +

x

+ + + Page 1 + + + Page 2 + + + Page 3 + +

x

diff --git a/test/fixtures/loop_conditional_locals.html b/test/fixtures/loop_conditional_locals.html new file mode 100644 index 0000000..c136ee0 --- /dev/null +++ b/test/fixtures/loop_conditional_locals.html @@ -0,0 +1,10 @@ +

x

+ + + {{ page.title }} + + + {{ page.title }} + + +

x

diff --git a/test/test-loops.js b/test/test-loops.js index 806067d..d256991 100644 --- a/test/test-loops.js +++ b/test/test-loops.js @@ -23,7 +23,7 @@ function process (t, name, options, log = false) { return clean(result.html) }) .then((html) => { - t.truthy(html === expect(name).trim()) + t.is(html, expect(name).trim()) }) } @@ -65,6 +65,19 @@ test('Loops - conditional included', (t) => { }) }) +test('Loops - conditional and locals included', (t) => { + return process(t, 'loop_conditional_locals', { + locals: { + pages: [ + { path: "/page1", title: "Page 1" }, + { path: "/page2", title: "Page 2" }, + { path: "/page3", title: "Page 3" } + ], + current_path: '/page1' + } + }) +}) + test('Loops - conflicting locals', (t) => { return process(t, 'loop_conflict', { locals: { items: [1, 2, 3], item: 'bar' } From b978e76b46274a6f3416931cf24bbee22fed36e9 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:02:36 +0300 Subject: [PATCH 05/10] ci: drop support old node --- .travis.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e38bcc4..5fba99c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: node_js node_js: - - node + - "stable" + - "lts/*" - 6 - - 4 cache: directories: - node_modules diff --git a/package.json b/package.json index 71ff20b..21a3212 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.1.0", "description": "Expressions Plugin for PostHTML", "engines": { - "node": ">=4" + "node": ">=6" }, "main": "lib", "scripts": { From 0d65f6cdab00cf2ca8f0e19d012cf8fadc64e8bf Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:26:47 +0300 Subject: [PATCH 06/10] test: fix floating syntax error message --- test/test-core.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/test-core.js b/test/test-core.js index acdd1dd..edfe41a 100644 --- a/test/test-core.js +++ b/test/test-core.js @@ -64,7 +64,10 @@ test('Expressions - spacing', (t) => { }) test('Expressions - error', (t) => { - return error('expression_error', (err) => { - t.is(err.message, 'Invalid or unexpected token') - }) + return error('expression_error', (err) => { + t.is(err.name, 'SyntaxError'); + }) + // return error('expression_error', (err) => { + // t.is(err.message, 'Invalid or unexpected token') + // }) }) From 68264a057b77e6412aede0573575b1cbdef55c1d Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:27:53 +0300 Subject: [PATCH 07/10] style: remove comment --- test/test-core.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test-core.js b/test/test-core.js index edfe41a..59858f2 100644 --- a/test/test-core.js +++ b/test/test-core.js @@ -67,7 +67,4 @@ test('Expressions - error', (t) => { return error('expression_error', (err) => { t.is(err.name, 'SyntaxError'); }) - // return error('expression_error', (err) => { - // t.is(err.message, 'Invalid or unexpected token') - // }) }) From bd3c3177ecc013c8bf11c5348f3b0fb4531593bb Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:31:54 +0300 Subject: [PATCH 08/10] test: incorrect fix test --- test/test-conditionals.js | 2 +- test/test-core.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test-conditionals.js b/test/test-conditionals.js index 90c0ad0..f5b6428 100644 --- a/test/test-conditionals.js +++ b/test/test-conditionals.js @@ -71,7 +71,7 @@ test('Conditionals - nested conditionals', (t) => { test('conditional - expression error', (t) => { return error('conditional_expression_error', (err) => { - t.is(err.message, 'Invalid or unexpected token') + t.is(err.name, 'SyntaxError'); }) }) diff --git a/test/test-core.js b/test/test-core.js index 59858f2..acdd1dd 100644 --- a/test/test-core.js +++ b/test/test-core.js @@ -64,7 +64,7 @@ test('Expressions - spacing', (t) => { }) test('Expressions - error', (t) => { - return error('expression_error', (err) => { - t.is(err.name, 'SyntaxError'); - }) + return error('expression_error', (err) => { + t.is(err.message, 'Invalid or unexpected token') + }) }) From 4dc6b7d1cbed46e4ba74b8075ed76f5effe6ff66 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:36:43 +0300 Subject: [PATCH 09/10] style: by standard --- test/test-conditionals.js | 2 +- test/test-loops.js | 6 +++--- test/test-scopes.js | 6 ------ test/test-switch.js | 2 +- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/test/test-conditionals.js b/test/test-conditionals.js index f5b6428..f213801 100644 --- a/test/test-conditionals.js +++ b/test/test-conditionals.js @@ -71,7 +71,7 @@ test('Conditionals - nested conditionals', (t) => { test('conditional - expression error', (t) => { return error('conditional_expression_error', (err) => { - t.is(err.name, 'SyntaxError'); + t.is(err.name, 'SyntaxError') }) }) diff --git a/test/test-loops.js b/test/test-loops.js index d256991..22c8b19 100644 --- a/test/test-loops.js +++ b/test/test-loops.js @@ -69,9 +69,9 @@ test('Loops - conditional and locals included', (t) => { return process(t, 'loop_conditional_locals', { locals: { pages: [ - { path: "/page1", title: "Page 1" }, - { path: "/page2", title: "Page 2" }, - { path: "/page3", title: "Page 3" } + { path: '/page1', title: 'Page 1' }, + { path: '/page2', title: 'Page 2' }, + { path: '/page3', title: 'Page 3' } ], current_path: '/page1' } diff --git a/test/test-scopes.js b/test/test-scopes.js index 2f377c1..e863210 100644 --- a/test/test-scopes.js +++ b/test/test-scopes.js @@ -27,12 +27,6 @@ function process (t, name, options, log = false) { }) } -function error (name, cb) { - return posthtml([ expressions() ]) - .process(fixture(name)) - .catch(cb) -} - function clean (html) { return html.replace(/[^\S\r\n]+$/gm, '').trim() } diff --git a/test/test-switch.js b/test/test-switch.js index e4f563b..68aba85 100644 --- a/test/test-switch.js +++ b/test/test-switch.js @@ -81,7 +81,7 @@ test('Switch - no switch attribute', (t) => { test('Switch - no case attribute', (t) => { return error('switch_no_case_attr', (err) => { - t.is(err.message, 'the "switch" tag must have a "expression" attribute') + t.is(err.message, 'the "switch" tag must have a "expression" attribute') }) }) From a598579e60ecbf097bca1e0648623c016f70da83 Mon Sep 17 00:00:00 2001 From: Ivan Demidov Date: Wed, 15 May 2019 12:37:19 +0300 Subject: [PATCH 10/10] 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21a3212..4d9e7db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthtml-expressions", - "version": "1.1.0", + "version": "1.1.1", "description": "Expressions Plugin for PostHTML", "engines": { "node": ">=6"