From 3fffdc78b78fb57054853ac2040a7baf139bf7f7 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Wed, 25 Jan 2017 00:50:38 +0000 Subject: [PATCH 1/2] Add regression tests for #1261 --- .../__snapshots__/index.test.js.snap | 24 +++++++++++++++ .../pug/test/regression-1261/index.test.js | 29 +++++++++++++++++++ packages/pug/test/regression-1261/layout.pug | 3 ++ .../pug/test/regression-1261/page1-issue1.pug | 9 ++++++ .../pug/test/regression-1261/page1-issue2.pug | 9 ++++++ .../pug/test/regression-1261/page1-issue3.pug | 8 +++++ packages/pug/test/regression-1261/page2.pug | 5 ++++ 7 files changed, 87 insertions(+) create mode 100644 packages/pug/test/regression-1261/__snapshots__/index.test.js.snap create mode 100644 packages/pug/test/regression-1261/index.test.js create mode 100644 packages/pug/test/regression-1261/layout.pug create mode 100644 packages/pug/test/regression-1261/page1-issue1.pug create mode 100644 packages/pug/test/regression-1261/page1-issue2.pug create mode 100644 packages/pug/test/regression-1261/page1-issue3.pug create mode 100644 packages/pug/test/regression-1261/page2.pug diff --git a/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap b/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..54fee6754 --- /dev/null +++ b/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap @@ -0,0 +1,24 @@ +exports[`test #1261 - issue 1 - page with nested append 1`] = ` +" + + +

page 1

+" +`; + +exports[`test #1261 - issue 2 - append/prepend in include 1`] = ` +" + + +

page 1

+

page 2

" +`; + +exports[`test #1261 - issue 3 - append inside include inside append content 1`] = ` +" + + +

page 1

+ +

page 2

" +`; diff --git a/packages/pug/test/regression-1261/index.test.js b/packages/pug/test/regression-1261/index.test.js new file mode 100644 index 000000000..053878505 --- /dev/null +++ b/packages/pug/test/regression-1261/index.test.js @@ -0,0 +1,29 @@ +const pug = require('../../'); + +// Issue 1: block append in another block append duplicates the content of the inner block append, +// in different order furthermore. +test('#1261 - issue 1 - page with nested append', () => { + const output = pug.renderFile( + __dirname + '/page1-issue1.pug', + {pretty: true} + ); + expect(output).toMatchSnapshot(); +}); + +// Issue 2: append order is not the expected one: page 2 should be after page 1 in both script & content blocks. +test('#1261 - issue 2 - append/prepend in include', () => { + const output = pug.renderFile( + __dirname + '/page1-issue2.pug', + {pretty: true} + ); + expect(output).toMatchSnapshot(); +}); + +// Issue 3: block scripts is duplicated like in issue 1, but the order is the same in the two copies... +test('#1261 - issue 3 - append inside include inside append content', () => { + const output = pug.renderFile( + __dirname + '/page1-issue3.pug', + {pretty: true} + ); + expect(output).toMatchSnapshot(); +}); diff --git a/packages/pug/test/regression-1261/layout.pug b/packages/pug/test/regression-1261/layout.pug new file mode 100644 index 000000000..6c9d1c2c7 --- /dev/null +++ b/packages/pug/test/regression-1261/layout.pug @@ -0,0 +1,3 @@ +block scripts + +block content diff --git a/packages/pug/test/regression-1261/page1-issue1.pug b/packages/pug/test/regression-1261/page1-issue1.pug new file mode 100644 index 000000000..e6e1b9887 --- /dev/null +++ b/packages/pug/test/regression-1261/page1-issue1.pug @@ -0,0 +1,9 @@ +extends ./layout.pug + +append scripts + script console.log("page1"); + +append content + p page 1 + append scripts + script console.log("page1 in content"); diff --git a/packages/pug/test/regression-1261/page1-issue2.pug b/packages/pug/test/regression-1261/page1-issue2.pug new file mode 100644 index 000000000..e379d64f9 --- /dev/null +++ b/packages/pug/test/regression-1261/page1-issue2.pug @@ -0,0 +1,9 @@ +extends ./layout.pug + +append scripts + script console.log("page1"); + +append content + p page 1 + +include ./page2.pug diff --git a/packages/pug/test/regression-1261/page1-issue3.pug b/packages/pug/test/regression-1261/page1-issue3.pug new file mode 100644 index 000000000..85b1f4934 --- /dev/null +++ b/packages/pug/test/regression-1261/page1-issue3.pug @@ -0,0 +1,8 @@ +extends ./layout.pug + +append scripts + script console.log("page1"); + +append content + p page 1 + include ./page2.pug diff --git a/packages/pug/test/regression-1261/page2.pug b/packages/pug/test/regression-1261/page2.pug new file mode 100644 index 000000000..5b5ef1c5e --- /dev/null +++ b/packages/pug/test/regression-1261/page2.pug @@ -0,0 +1,5 @@ +append scripts + script console.log("page2"); + +append content + p page 2 From 78b65d37915bd28f27be62d31fcf9a7df53d1c33 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Wed, 25 Jan 2017 00:58:17 +0000 Subject: [PATCH 2/2] Update snapshot to match user's typical expectations. --- .../pug/test/regression-1261/__snapshots__/index.test.js.snap | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap b/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap index 54fee6754..1f2539d3a 100644 --- a/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap +++ b/packages/pug/test/regression-1261/__snapshots__/index.test.js.snap @@ -2,8 +2,7 @@ exports[`test #1261 - issue 1 - page with nested append 1`] = ` " -

page 1

-" +

page 1

" `; exports[`test #1261 - issue 2 - append/prepend in include 1`] = ` @@ -19,6 +18,5 @@ exports[`test #1261 - issue 3 - append inside include inside append content 1`]

page 1

-

page 2

" `;