From 304bd7464a484252fe55d3b01dff3096e870de0f Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Thu, 7 Dec 2017 10:49:28 -0800 Subject: [PATCH] test: filename passed to hooks --- test/preprocess/index.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/preprocess/index.js b/test/preprocess/index.js index 29eaff67f1..6ed452f672 100644 --- a/test/preprocess/index.js +++ b/test/preprocess/index.js @@ -126,6 +126,41 @@ describe('preprocess', () => { }); }); + it('provides filename to processing hooks', () => { + const source = ` +

Hello __MARKUP_FILENAME__!

+ + + `; + + const expected = ` +

Hello file.html!

+ + + `; + + return svelte.preprocess(source, { + filename: 'file.html', + markup: ({ content, filename }) => { + return { + code: content.replace('__MARKUP_FILENAME__', filename) + }; + }, + style: ({ content, filename }) => { + return { + code: content.replace('__STYLE_FILENAME__', filename) + }; + }, + script: ({ content, filename }) => { + return { + code: content.replace('__SCRIPT_FILENAME__', filename) + }; + } + }).then(processed => { + assert.equal(processed.toString(), expected); + }); + }); + it('ignores null/undefined returned from preprocessor', () => { const source = `