mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
Changes including: - will not call fs.resolve when normalizing `fs` - removed hardcoded `/` - mandatory `fs.dirname` for relative reference - mandatory `fs.sep`, defaults to '/'
This commit is contained in:
+23
-16
@@ -6,23 +6,23 @@ import * as chaiAsPromised from 'chai-as-promised'
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('fs/browser', function () {
|
||||
if (+(process.version.match(/^v(\d+)/) as RegExpMatchArray)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping template-browser...')
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
beforeEach(function () {
|
||||
const dom = new JSDOM(``, {
|
||||
url: 'https://example.com/foo/bar/',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
});
|
||||
(global as any).document = dom.window.document
|
||||
})
|
||||
afterEach(function () {
|
||||
delete (global as any).document
|
||||
})
|
||||
describe('#resolve()', function () {
|
||||
if (+(process.version.match(/^v(\d+)/) as RegExpMatchArray)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping template-browser...')
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
beforeEach(function () {
|
||||
const dom = new JSDOM(``, {
|
||||
url: 'https://example.com/foo/bar/',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
});
|
||||
(global as any).document = dom.window.document
|
||||
})
|
||||
afterEach(function () {
|
||||
delete (global as any).document
|
||||
})
|
||||
it('should support relative root', function () {
|
||||
expect(fs.resolve('./views/', 'foo', '')).to.equal('https://example.com/foo/bar/views/foo')
|
||||
})
|
||||
@@ -52,6 +52,13 @@ describe('fs/browser', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#dirname()', () => {
|
||||
it('should return dirname of file', async function () {
|
||||
const val = fs.dirname('https://example.com/views/foo/bar')
|
||||
expect(val).to.equal('https://example.com/views/foo/')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#exists()', () => {
|
||||
it('should always return true', async function () {
|
||||
const val = await fs.exists('/foo/bar')
|
||||
|
||||
@@ -12,5 +12,15 @@ describe('fs/loader', function () {
|
||||
const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current', true)]
|
||||
expect(candidates).to.contain('/root/foo/bar')
|
||||
})
|
||||
it('should not include out of root candidates', async function () {
|
||||
const loader = new Loader({ relativeReference: true, fs, extname: '' } as any)
|
||||
const candidates = [...loader.candidates('../foo/bar', ['/root'], '/root/current', true)]
|
||||
expect(candidates).to.have.lengthOf(0)
|
||||
})
|
||||
it('should treat root as a terminated path', async function () {
|
||||
const loader = new Loader({ relativeReference: true, fs, extname: '' } as any)
|
||||
const candidates = [...loader.candidates('../root-dir/bar', ['/root'], '/root/current', true)]
|
||||
expect(candidates).to.have.lengthOf(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user