From 4f458f92cbf163cfc5c868950b811a5e8ef14212 Mon Sep 17 00:00:00 2001 From: Richard Lea Date: Wed, 5 Sep 2018 02:16:38 +0900 Subject: [PATCH] Test: template render case to test basic import Signed-off-by: Richard Lea --- .../import-render-nigeru.html | 21 ++++++++++++++ .../import-render-case/layout/template.njk | 21 ++++++++++++++ .../import-render-case/source/style.css | 3 ++ test/nunjucks.test.ts | 29 ++++++++++++++++--- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/tpl-render-result/import-render-nigeru.html create mode 100644 test/fixtures/tpl-test/import-render-case/layout/template.njk create mode 100644 test/fixtures/tpl-test/import-render-case/source/style.css diff --git a/test/fixtures/tpl-render-result/import-render-nigeru.html b/test/fixtures/tpl-render-result/import-render-nigeru.html new file mode 100644 index 0000000..559fd11 --- /dev/null +++ b/test/fixtures/tpl-render-result/import-render-nigeru.html @@ -0,0 +1,21 @@ + + + + + + 逃げる + + + + +

逃げる

+ 逃げちゃだめだ。逃げちゃだめだ。逃げちゃだめだ。 + + + \ No newline at end of file diff --git a/test/fixtures/tpl-test/import-render-case/layout/template.njk b/test/fixtures/tpl-test/import-render-case/layout/template.njk new file mode 100644 index 0000000..9f769d6 --- /dev/null +++ b/test/fixtures/tpl-test/import-render-case/layout/template.njk @@ -0,0 +1,21 @@ + + + + + + {{ title }} + + + + +

逃げる

+ {{ body }} + + + \ No newline at end of file diff --git a/test/fixtures/tpl-test/import-render-case/source/style.css b/test/fixtures/tpl-test/import-render-case/source/style.css new file mode 100644 index 0000000..2435aff --- /dev/null +++ b/test/fixtures/tpl-test/import-render-case/source/style.css @@ -0,0 +1,3 @@ +#nigeru { + background-color: green; +} \ No newline at end of file diff --git a/test/nunjucks.test.ts b/test/nunjucks.test.ts index 3cf9c8e..21c7e41 100644 --- a/test/nunjucks.test.ts +++ b/test/nunjucks.test.ts @@ -4,11 +4,13 @@ import * as path from 'path'; import * as CONST from './constants'; const NjkLoaders = require('../tools/njk-loader'); +function getNJKEnv(tplDir: string | string[]) { + return new nunjucks.Environment( + new NjkLoaders.TemplateLoader(tplDir)); +} + test('TemplateLoader Basic Usage', done => { - const njk_env = new nunjucks.Environment( - new NjkLoaders.TemplateLoader(path.join(CONST.TEST_TEMPLATE_DIR, './basic-render-case')), - // new nunjucks.FileSystemLoader(path.join(CONST.TEST_TEMPLATE_DIR, './basic-render-case')), - ); + const njk_env = getNJKEnv(path.join(CONST.TEST_TEMPLATE_DIR, './basic-render-case')); njk_env.render('layout/template.njk', { title: '逃げる', body: '逃げちゃだめだ。逃げちゃだめだ。逃げちゃだめだ。', @@ -25,3 +27,22 @@ test('TemplateLoader Basic Usage', done => { return done(); }); }); + +test('Basic External Source Import Testing', done => { + const njk_env = getNJKEnv([ + path.join(CONST.TEST_TEMPLATE_DIR, './import-render-case'), + path.join(CONST.TEST_TEMPLATE_DIR, './import-render-case/source'), + ]); + njk_env.render('layout/template.njk', { + title: '逃げる', + body: '逃げちゃだめだ。逃げちゃだめだ。逃げちゃだめだ。', + }, (err, result) => { + expect(err).toBeNull(); + expect(result).toEqual( + fs.readFileSync( + path.resolve(CONST.RENDER_CASE_DIR, './import-render-nigeru.html') + , 'utf8')); + + return done(); + }); +});