From 0b195b21ebfac5223335a4d40dfc57764d019505 Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Fri, 25 Oct 2024 21:47:06 +0800 Subject: [PATCH] test: case for "." path handling --- test/e2e/express.spec.ts | 4 ++-- test/e2e/render-file.spec.ts | 10 ++++++++++ test/integration/liquid/root.spec.ts | 2 +- test/stub/views/bar.html | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/e2e/express.spec.ts b/test/e2e/express.spec.ts index fba8a76e7..db63f48f5 100644 --- a/test/e2e/express.spec.ts +++ b/test/e2e/express.spec.ts @@ -35,7 +35,7 @@ describe('express()', function () { it('should respect express views(string)', function (done) { app.set('views', views) request(app).get('/include/bar') - .expect('bar') + .expect('BAR') .expect(200, done) }) it('should pass error when file not found', function (done) { @@ -63,7 +63,7 @@ describe('express()', function () { it('should respect express views (Array) when lookup', function (done) { app.set('views', [views, partials]) request(app).get('/include/bar') - .expect('bar') + .expect('BAR') .expect(200, done) }) }) diff --git a/test/e2e/render-file.spec.ts b/test/e2e/render-file.spec.ts index bfdc8e73d..3bc1f5a55 100644 --- a/test/e2e/render-file.spec.ts +++ b/test/e2e/render-file.spec.ts @@ -52,4 +52,14 @@ describe('#renderFile()', function () { }) return expect(engine.renderFile('/not/exist.html')).rejects.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/) }) + it('should handle "." as cwd', async () => { + engine = new Liquid({ + root: ['.'], + extname: '.html' + }) + process.chdir(resolve(__dirname, '../stub/views')) + await expect(engine.renderFile('bar')).resolves.toEqual('BAR') + process.chdir(resolve(__dirname, '../stub/partials')) + await expect(engine.renderFile('bar')).resolves.toEqual('bar') + }) }) diff --git a/test/integration/liquid/root.spec.ts b/test/integration/liquid/root.spec.ts index c09c1c879..0730a72c3 100644 --- a/test/integration/liquid/root.spec.ts +++ b/test/integration/liquid/root.spec.ts @@ -1,7 +1,7 @@ import { normalize } from '../../../src/liquid-options' describe('LiquidOptions#root', function () { - describe('#normalize ()', function () { + describe('#normalize()', function () { it('should normalize string typed root array', function () { const options = normalize({ root: 'foo' }) expect(options.root).toEqual(['foo']) diff --git a/test/stub/views/bar.html b/test/stub/views/bar.html index ba0e162e1..add837310 100644 --- a/test/stub/views/bar.html +++ b/test/stub/views/bar.html @@ -1 +1 @@ -bar \ No newline at end of file +BAR \ No newline at end of file