Skip to content
This repository was archived by the owner on Feb 28, 2022. It is now read-only.

Commit 89ea8f5

Browse files
committed
fix(pipeline): Fix off-by-one error in pipeline extensibility
Added a more detailed test for extending the HTML pipeline, as suggested by @koraa and discovered (and fixed) an off-by-one error in pipeline extensibility, causing the `after` extension points to act like `before` extension points
1 parent 244454d commit 89ea8f5

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/pipeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Pipeline {
154154
* @param {String} name - name of the extension point (typically the function name).
155155
* @param {pipelineFunction} f - a new pipeline step that will be injected relative to `name`.
156156
*/
157-
this.attach.after = (name, f) => this.attach.generic(name, f, 1);
157+
this.attach.after = (name, f) => this.attach.generic(name, f, 2);
158158
}
159159

160160
/**

test/testHTML.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ describe('Testing HTML Pipeline', () => {
157157
});
158158

159159
it('html.pipe can be extended', async () => {
160-
const myfunc = ({ content }) => ({ response: { body: `${content.document.body.innerHTML}<esi:include src="foo.html">` } });
160+
const myfunc = ({ content }) => ({
161+
response: {
162+
body: `<h1>${content.title}</h1>
163+
${content.document.body.innerHTML}`,
164+
},
165+
});
161166

162167
let calledfoo = false;
163168
let calledbar = false;
@@ -173,15 +178,26 @@ describe('Testing HTML Pipeline', () => {
173178
calledbar = true;
174179
}
175180

181+
function shouttitle(p) {
182+
return {
183+
content: {
184+
title: `${p.content.title.toUpperCase()}!!!`,
185+
},
186+
};
187+
}
188+
176189
myfunc.before = {
177190
fetch: foo,
178191
};
179192

180193
myfunc.after = {
181194
flag: bar,
195+
// after the metadata has been retrived, make sure that
196+
// the title is being shouted
197+
getmetadata: shouttitle,
182198
};
183199

184-
await pipe(
200+
const res = await pipe(
185201
myfunc,
186202
{
187203
content: {
@@ -197,6 +213,8 @@ describe('Testing HTML Pipeline', () => {
197213

198214
assert.equal(calledfoo, true, 'foo has been called');
199215
assert.equal(calledbar, true, 'bar has been called');
216+
217+
assert.ok(res.response.body.match(/HELLO WORLD/));
200218
});
201219

202220
it('html.pipe renders index.md from helix-cli correctly', async () => {

0 commit comments

Comments
 (0)