mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 21:40:39 -07:00
fix: default length for truncate and truncatewords
This commit is contained in:
+16
-10
@@ -4,7 +4,6 @@ import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
const resolve = fs.resolve
|
||||
|
||||
describe('fs/browser', function () {
|
||||
describe('#resolve()', function () {
|
||||
@@ -25,31 +24,38 @@ describe('fs/browser', function () {
|
||||
delete (global as any).document
|
||||
})
|
||||
it('should support relative root', function () {
|
||||
expect(resolve('./views/', 'foo', '')).to.equal('https://example.com/foo/bar/views/foo')
|
||||
expect(fs.resolve('./views/', 'foo', '')).to.equal('https://example.com/foo/bar/views/foo')
|
||||
})
|
||||
it('should treat root as directory', function () {
|
||||
expect(resolve('./views', 'foo', '')).to.equal('https://example.com/foo/bar/views/foo')
|
||||
expect(fs.resolve('./views', 'foo', '')).to.equal('https://example.com/foo/bar/views/foo')
|
||||
})
|
||||
it('should support absolute root', function () {
|
||||
expect(resolve('/views', 'foo', '')).to.equal('https://example.com/views/foo')
|
||||
expect(fs.resolve('/views', 'foo', '')).to.equal('https://example.com/views/foo')
|
||||
})
|
||||
it('should support empty root', function () {
|
||||
expect(resolve('', 'page.html', '')).to.equal('https://example.com/foo/bar/page.html')
|
||||
expect(fs.resolve('', 'page.html', '')).to.equal('https://example.com/foo/bar/page.html')
|
||||
})
|
||||
it('should support full url as root', function () {
|
||||
expect(resolve('https://example.com/views/', 'page.html', '')).to.equal('https://example.com/views/page.html')
|
||||
expect(fs.resolve('https://example.com/views/', 'page.html', '')).to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should add extname when absent', function () {
|
||||
expect(resolve('https://example.com/views/', 'page', '.html')).to.equal('https://example.com/views/page.html')
|
||||
expect(fs.resolve('https://example.com/views/', 'page', '.html')).to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should add extname for urls have searchParams', function () {
|
||||
expect(resolve('https://example.com/views/', 'page?foo=bar', '.html')).to.equal('https://example.com/views/page.html?foo=bar')
|
||||
expect(fs.resolve('https://example.com/views/', 'page?foo=bar', '.html')).to.equal('https://example.com/views/page.html?foo=bar')
|
||||
})
|
||||
it('should not add extname when full url is given', function () {
|
||||
expect(resolve('https://example.com/views/', 'https://google.com/page.php', '.html')).to.equal('https://google.com/page.php')
|
||||
expect(fs.resolve('https://example.com/views/', 'https://google.com/page.php', '.html')).to.equal('https://google.com/page.php')
|
||||
})
|
||||
it('should not add extname when already have one', function () {
|
||||
expect(resolve('https://example.com/views/', 'page.php', '.html')).to.equal('https://example.com/views/page.php')
|
||||
expect(fs.resolve('https://example.com/views/', 'page.php', '.html')).to.equal('https://example.com/views/page.php')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#exists()', () => {
|
||||
it('should always return true', async function () {
|
||||
const val = await fs.exists('/foo/bar')
|
||||
expect(val).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+6
-13
@@ -2,17 +2,10 @@ import fs from 'src/fs/node'
|
||||
import * as path from 'path'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { mock, restore } from 'test/stub/mockfs'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('fs', function () {
|
||||
before(() => mock({
|
||||
'/foo/bar.html': 'bar',
|
||||
'/un-readable.html': { mode: '0000', content: '' }
|
||||
}))
|
||||
after(restore)
|
||||
|
||||
describe('#resolve()', function () {
|
||||
it('should resolve based on root', async function () {
|
||||
const filepath = fs.resolve('/foo', 'bar.html', '.liquid')
|
||||
@@ -27,21 +20,21 @@ describe('fs', function () {
|
||||
})
|
||||
describe('#exists', () => {
|
||||
it('should resolve as false if not exists', async () => {
|
||||
const result = await fs.exists('/foo/foo.html')
|
||||
const result = await fs.exists('/foo/bar')
|
||||
return expect(result).to.be.false
|
||||
})
|
||||
it('should resolve as true if exists', async () => {
|
||||
const result = await fs.exists('/foo/bar.html')
|
||||
const result = await fs.exists(__filename)
|
||||
return expect(result).to.be.true
|
||||
})
|
||||
})
|
||||
describe('#readFile', function () {
|
||||
it('should throw when not exist', function () {
|
||||
return expect(fs.readFile('/foo/foo.html')).to.rejectedWith('ENOENT')
|
||||
return expect(fs.readFile('/foo/bar')).to.rejectedWith('ENOENT')
|
||||
})
|
||||
it('should throw when file not readable', function () {
|
||||
return expect(fs.readFile('/un-readable.html')).to
|
||||
.be.rejectedWith(/EACCES/)
|
||||
it('should read content if exists', async function () {
|
||||
const content = await fs.readFile(__filename)
|
||||
return expect(content).to.contain('should read content if exists')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user