mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
chore(TypeScript): fix unit tests and coverage
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ jobs:
|
||||
name: 'Linting'
|
||||
script: npm run lint
|
||||
- name: 'Coverage'
|
||||
script: npm run coverage && npm run coveralls
|
||||
script: npm run coverage-coveralls
|
||||
- stage: release
|
||||
if: branch = master
|
||||
script: skip
|
||||
|
||||
+8
-4
@@ -7,11 +7,11 @@
|
||||
"browser": "dist/liquid.js",
|
||||
"scripts": {
|
||||
"lint": "eslint . --ext .ts --ext .js",
|
||||
"unit": "mocha -r ts-node/register -r tsconfig-paths/register test/unit/**.ts",
|
||||
"e2e": "npm run build && mocha -r ts-node/register -r tsconfig-paths/register test/e2e/**/*.ts",
|
||||
"unit": "mocha test/unit/*.ts test/unit/**/*.ts",
|
||||
"e2e": "npm run build && mocha test/e2e/**/*.ts test/e2e/*.ts",
|
||||
"test": "npm run unit && npm run e2e",
|
||||
"coverage": "nyc --reporter=html npm run unit",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"coverage-html": "nyc npm run unit && nyc report --reporter=html",
|
||||
"coverage-coveralls": "nyc npm run unit && nyc report --reporter=text-lcov | coveralls",
|
||||
"build": "rollup -c && ls -lh dist",
|
||||
"version": "npm run build && git add -A dist"
|
||||
},
|
||||
@@ -68,6 +68,7 @@
|
||||
"semantic-release": "^15.13.3",
|
||||
"sinon": "^7.2.3",
|
||||
"sinon-chai": "^3.3.0",
|
||||
"source-map-support": "^0.5.10",
|
||||
"supertest": "^3.4.2",
|
||||
"ts-node": "^8.0.2",
|
||||
"tsconfig-paths": "^3.8.0",
|
||||
@@ -82,5 +83,8 @@
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/git"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [ ".ts" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import * as _ from '../util/underscore'
|
||||
import * as path from 'path'
|
||||
import { anySeries } from '../util/promise'
|
||||
import * as fs from 'fs'
|
||||
import { stat, readFile } from 'fs'
|
||||
|
||||
const statFileAsync = <(filepath: string) => Promise<object>>_.promisify(fs.stat)
|
||||
const readFileAsync = <(filepath: string, encoding: string) => Promise<string>>_.promisify(fs.readFile)
|
||||
export const fs = {
|
||||
stat: _.promisify(stat) as ((filepath: string) => Promise<object>),
|
||||
readFile: _.promisify(readFile) as ((filepath: string, encoding: string) => Promise<string>)
|
||||
}
|
||||
|
||||
export async function resolve (filepath, root, options) {
|
||||
if (!path.extname(filepath)) {
|
||||
@@ -15,7 +17,7 @@ export async function resolve (filepath, root, options) {
|
||||
const paths = root.map(root => path.resolve(root, filepath))
|
||||
return anySeries(paths, async path => {
|
||||
try {
|
||||
await statFileAsync(path)
|
||||
await fs.stat(path)
|
||||
return path
|
||||
} catch (e) {
|
||||
e.message = `${e.code}: Failed to lookup ${filepath} in: ${root}`
|
||||
@@ -25,5 +27,5 @@ export async function resolve (filepath, root, options) {
|
||||
}
|
||||
|
||||
export async function read (filepath): Promise<string> {
|
||||
return readFileAsync(filepath, 'utf8')
|
||||
return fs.readFile(filepath, 'utf8')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
--require ts-node/register
|
||||
--require tsconfig-paths/register
|
||||
@@ -12,7 +12,7 @@ describe('LiquidOptions#trimming', function () {
|
||||
})
|
||||
it('should respect trim_tag_right', async function () {
|
||||
const engine = new Liquid({ trim_tag_right: true })
|
||||
const html = engine.parseAndRender('\t{%if true%}foo{%endif%} \n')
|
||||
const html = await engine.parseAndRender('\t{%if true%}foo{%endif%} \n')
|
||||
return expect(html).to.equal('\tfoo')
|
||||
})
|
||||
it('should not trim value', async function () {
|
||||
|
||||
+20
-5
@@ -1,13 +1,28 @@
|
||||
import { resolve } from '../../src/parser/template'
|
||||
import * as mock from 'mock-fs'
|
||||
import { expect } from 'chai'
|
||||
import * as path from 'path'
|
||||
import { fs } from 'src/parser/template'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
describe('template', function () {
|
||||
let readFile, stat
|
||||
before(function () {
|
||||
mock({
|
||||
'/foo/bar.html': 'bar'
|
||||
})
|
||||
readFile = fs.readFile
|
||||
stat = fs.stat
|
||||
fs.readFile = async function (file) {
|
||||
if (file === '/foo/bar.html') return 'bar'
|
||||
throw new Error('NOENT')
|
||||
}
|
||||
fs.stat = async function (file) {
|
||||
if (file === '/foo/bar.html') return { type: 'file' }
|
||||
throw new Error('NOENT')
|
||||
}
|
||||
})
|
||||
after(function () {
|
||||
fs.readFile = readFile
|
||||
fs.stat = stat
|
||||
})
|
||||
describe('#resolve()', function () {
|
||||
it('should resolve based on root', async function () {
|
||||
|
||||
@@ -47,7 +47,8 @@ describe('error', function () {
|
||||
it('should contain stack in err.stack', async function () {
|
||||
const err = await expect(engine.parseAndRender('{% . a %}')).be.rejected
|
||||
expect(err.message).to.contain('illegal tag syntax')
|
||||
expect(err.stack).to.contain('at Object.parse')
|
||||
console.log(err.stack)
|
||||
expect(err.stack).to.contain('at Liquid.parse')
|
||||
})
|
||||
describe('captureStackTrace compatibility', function () {
|
||||
const captureStackTrace = Error.captureStackTrace
|
||||
|
||||
@@ -52,9 +52,9 @@ describe('util/promise', function () {
|
||||
.then(() => expect(spy).to.not.have.been.called)
|
||||
})
|
||||
})
|
||||
describe('.mapSeries()', function () {
|
||||
describe('.mapSeries()', async function () {
|
||||
it('should resolve when all resolved', async function () {
|
||||
const result = P.mapSeries(
|
||||
const result = await P.mapSeries(
|
||||
['first', 'second', 'third'],
|
||||
item => Promise.resolve(item)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user