Skip to content

Commit

Permalink
test: inline all tostring tests
Browse files Browse the repository at this point in the history
remove file stubs and reading from disk
  • Loading branch information
cossssmin committed Oct 2, 2022
1 parent f7608d7 commit 4f5efbf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
9 changes: 0 additions & 9 deletions test/expected/useConfig.html

This file was deleted.

9 changes: 0 additions & 9 deletions test/fixtures/useConfig.html

This file was deleted.

28 changes: 7 additions & 21 deletions test/test-tostring.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
const test = require('ava')
const Maizzle = require('../src')

const path = require('path')
const fs = require('fs')

const readFile = (dir, filename) => fs.promises
.readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
.then(html => html.trim())

const fixture = file => readFile('fixtures', file)
const expected = file => readFile('expected', file)

const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)

test('compiles HTML string if no options are passed', async t => {
const source = await fixture('basic')

const html = await renderString(source)

t.is(html, source)
})

test('uses environment config file(s) if available', async t => {
const source = await fixture('useConfig')
const source = `<div>{{ page.mail }}</div>`

const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
const html = await renderString(source, {
maizzle: {
mail: 'puzzle'
}
})

t.is(html, await expected('useConfig'))
t.is(html, '<div>puzzle</div>')
})

test('throws if first argument is not an HTML string', async t => {
Expand Down

0 comments on commit 4f5efbf

Please sign in to comment.