Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
test:
name: Node.js ${{ matrix.node-version }} - Express ${{ matrix.express-version }}
permissions:
checks: write # for coverallsapp/github-action to create new checks
contents: read # for actions/checkout to fetch code
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- "18.0.0"
- "18"
- "19"
- "20"
Expand Down Expand Up @@ -53,28 +53,8 @@ jobs:
npm -s ls ||:

- name: Run tests
run: ${{ matrix.node-version == '18' && 'npm test' || 'npm run test-ci' }}
run: npm test

- name: Lint code
if: matrix.node-version >= '22'
run: npm run lint

- name: Collect code coverage
if: matrix.node-version != '18'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-node${{ matrix.node-version }}-express${{ matrix.express-version }}
parallel: true

coverage:
permissions:
checks: write # for coverallsapp/github-action to create new checks
needs: test
runs-on: ubuntu-latest
steps:
- name: Upload code coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Linux Build][github-actions-ci-image]][github-actions-ci-url]
[![Windows Build][appveyor-image]][appveyor-url]
[![Test Coverage][coveralls-image]][coveralls-url]

[Express.js](https://expressjs.com/) view engine for
[handlebars.js](https://handlebarsjs.com/)
Expand Down Expand Up @@ -150,8 +149,6 @@ See examples/extend for a working example. Note how the index.hbs file defines e

[appveyor-image]: https://badgen.net/appveyor/ci/dougwilson/nodejs-hbs/master?label=windows
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/nodejs-hbs
[coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/hbs/master
[coveralls-url]: https://coveralls.io/r/pillarjs/hbs?branch=master
[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/hbs/master?label=linux
[github-actions-ci-url]: https://github.com/pillarjs/hbs/actions?query=workflow%3Aci
[node-image]: https://badgen.net/npm/node/hbs
Expand Down
9 changes: 3 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ export default [
languageOptions: {
globals: {
describe: 'readonly',
test: 'readonly',
it: 'readonly',
expect: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
before: 'readonly',
after: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
vi: 'readonly'
afterEach: 'readonly'
}
}
},
Expand Down
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
},
"devDependencies": {
"@eslint/markdown": "^6.0.0",
"@vitest/coverage-v8": "^4.0.18",
"eslint": "^9.0.0",
"express": "^5.2.1",
"express": "5",
"mocha": "^10.8.2",
"neostandard": "^0.13.0",
"supertest": "6.1.6",
"vitest": "^4.0.18"
"supertest": "6.1.6"
},
"files": [
"lib/",
Expand All @@ -31,13 +30,8 @@
"engines": {
"node": ">= 18"
},
"overrides": {
"vite": "^6.0.0"
},
"scripts": {
"lint": "eslint .",
"test": "vitest run",
"test-ci": "vitest run --coverage --coverage.reporter=lcov --coverage.reporter=text",
"test-cov": "vitest run --coverage --coverage.reporter=html --coverage.reporter=text"
"test": "mocha \"test/*.test.js\""
}
}
2 changes: 0 additions & 2 deletions test/.eslintrc.yml

This file was deleted.

37 changes: 19 additions & 18 deletions test/app.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('node:path')
const fs = require('node:fs')
const assert = require('node:assert')
const request = require('supertest')
const express = require('express')
const hbs = require('../').create()
Expand Down Expand Up @@ -32,7 +33,7 @@ hbs.registerPartials(path.join(__dirname, 'views', 'partials'))

function shouldHaveFirstLineEqual (str) {
return function (res) {
expect(res.text.split(/\r?\n/)[0]).toBe(str)
assert.strictEqual(res.text.split(/\r?\n/)[0], str)
}
}

Expand All @@ -52,7 +53,7 @@ Person.prototype.name = function name () {
describe('express 4.x', () => {
let app

beforeAll(() => {
before(() => {
app = express()

// manually set render engine, under normal circumstances this
Expand Down Expand Up @@ -219,15 +220,15 @@ describe('express 4.x', () => {
})
})

test('index', async () => {
it('index', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index.html'),
'utf8'
)
await request(app).get('/').expect(expected)
})

test('helper error', async () => {
it('helper error', async () => {
await request(app)
.get('/helper-error')
.expect(500)
Expand All @@ -240,7 +241,7 @@ describe('express 4.x', () => {
)
})

test('partials', async () => {
it('partials', async () => {
await request(app)
.get('/partials')
.expect(
Expand All @@ -250,15 +251,15 @@ describe('express 4.x', () => {
)
})

test('html extension', async () => {
it('html extension', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index.html'),
'utf8'
)
await request(app).get('/html').expect(expected)
})

test('syntax error', async () => {
it('syntax error', async () => {
await request(app)
.get('/syntax-error')
.expect(500)
Expand All @@ -271,7 +272,7 @@ describe('express 4.x', () => {
)
})

test('syntax error cached', async () => {
it('syntax error cached', async () => {
await request(app)
.get('/syntax-error')
.expect(500)
Expand All @@ -284,7 +285,7 @@ describe('express 4.x', () => {
)
})

test('syntax error layout', async () => {
it('syntax error layout', async () => {
await request(app)
.get('/syntax-error-layout')
.expect(500)
Expand All @@ -297,23 +298,23 @@ describe('express 4.x', () => {
)
})

test('escape for frontend', async () => {
it('escape for frontend', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'escape.html'),
'utf8'
)
await request(app).get('/escape').expect(expected)
})

test('response locals', async () => {
it('response locals', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'locals.html'),
'utf8'
)
await request(app).get('/locals').expect(expected)
})

test('response locals cached', async () => {
it('response locals cached', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'locals.html'),
'utf8'
Expand All @@ -322,44 +323,44 @@ describe('express 4.x', () => {
await request(app).get('/locals-cached').expect(expected)
})

test('response locals model', async () => {
it('response locals model', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'locals.html'),
'utf8'
)
await request(app).get('/locals-model').expect(expected)
})

test('response globals', async () => {
it('response globals', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'globals.html'),
'utf8'
)
await request(app).get('/globals').expect(expected)
})

test('multiple views directories', async () => {
it('multiple views directories', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index_no_layout.html'),
'utf8'
)
await request(app).get('/secondary').expect(expected)
})

test('layout does not exist', async () => {
it('layout does not exist', async () => {
await request(app)
.get('/layout-no-exist')
.expect(500)
.expect(/Error: ENOENT.*noexist_layout\.hbs/)
})

test('app.render', async () => {
it('app.render', async () => {
const str = await new Promise((resolve, reject) => {
app.render('blank', (err, str) => {
if (err) return reject(err)
resolve(str)
})
})
expect(str).toMatch(/ {2}index body :\)/)
assert.match(str, / {2}index body :\)/)
})
})
18 changes: 9 additions & 9 deletions test/async_helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FIXTURES_DIR = path.join(__dirname, 'fixtures')
describe('express 4.x async helpers', () => {
let app

beforeAll(() => {
before(() => {
const hbs = hbsFactory.create()

app = express()
Expand Down Expand Up @@ -115,47 +115,47 @@ describe('express 4.x async helpers', () => {
})
})

test('index', async () => {
it('index', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'async.html'),
'utf8'
)
await request(app).get('/').expect(expected)
})

test('async', async () => {
it('async', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'fake-async.html'),
'utf8'
)
await request(app).get('/fake-async').expect(expected)
})

test('cached', async () => {
it('cached', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'async.html'),
'utf8'
)
await request(app).get('/').expect(expected)
})

test('async-with-params', async () => {
it('async-with-params', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'async-with-params.html'),
'utf8'
)
await request(app).get('/async-with-params').expect(expected)
})

test('async-with-layout', async () => {
it('async-with-layout', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'async-with-layout.html'),
'utf8'
)
await request(app).get('/async-with-layout').expect(expected)
})

test('layout-with-async', async () => {
it('layout-with-async', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'layout-with-async.html'),
'utf8'
Expand All @@ -164,13 +164,13 @@ describe('express 4.x async helpers', () => {
})

// @see https://github.com/pillarjs/hbs/security/advisories/GHSA-rg36-rxv9-2m9q
test('async helper output is HTML-escaped', async () => {
it('async helper output is HTML-escaped', async () => {
await request(app)
.get('/async-escape')
.expect('<script>alert(document.cookie)</script>')
})

test('async helper non-string values keep their text output', async () => {
it('async helper non-string values keep their text output', async () => {
await request(app)
.get('/async-non-string')
.expect('[null][undefined][false][0]')
Expand Down
8 changes: 4 additions & 4 deletions test/no_layout_app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FIXTURES_DIR = path.join(__dirname, 'fixtures')
describe('express 4.x no layout', () => {
let app

beforeAll(() => {
before(() => {
app = express()

// manually set render engine, under normal circumstances this
Expand Down Expand Up @@ -62,23 +62,23 @@ describe('express 4.x no layout', () => {
})
})

test('index', async () => {
it('index', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index_no_layout.html'),
'utf8'
)
await request(app).get('/').expect(expected)
})

test('index w/layout', async () => {
it('index w/layout', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index_no_layout.html'),
'utf8'
)
await request(app).get('/with_layout').expect(expected)
})

test('index layout cache', async () => {
it('index layout cache', async () => {
const expected = fs.readFileSync(
path.join(FIXTURES_DIR, 'index_no_layout.html'),
'utf8'
Expand Down
Loading
Loading