Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Sep 3, 2022
1 parent 24f313e commit f0d9669
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function collectKeys (key, arrayOfResults) {

for (const result of arrayOfResults) {
const value = result[key]
collection.push(value)
if (value) collection.push(value)
delete result[key]
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
},
"standard": {
"ignore": [
"test-cases/build-errors/src/**/*.js"
"test-cases/build-errors/src/**/*.js",
"test-cases/page-build-errors/src/**/*.js"
]
},
"files": [
Expand Down
5 changes: 1 addition & 4 deletions test-cases/build-errors/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ tap.test('build-errors', async (t) => {
const results = await siteUp.build()
t.notOk(results, 'Build should fail, and not generate results')
} catch (err) {
t.match(err.message, /Build finished but there were errors/, 'Should have an error message about a filed build.')
t.match(err.message, /Prebuild finished but there were errors/, 'Should have an error message about a filed build.')
t.ok(Array.isArray(err.errors), 'Should have an array of errors')

const pageError = err.errors.find(err => err.message.includes('Error building page'))
const cssError = err.errors.find(err => err.message.includes('Error building css'))
const jsError = err.errors.find(err => err.message.includes('Error building JS clients'))

t.ok(pageError, 'Should include a page build error')
t.ok(pageError.cause, 'Should include an error cause')
t.ok(cssError, 'Should include a css build error')
t.ok(cssError.cause, 'Should include an error cause')
t.ok(jsError, 'Should include a js client build error')
Expand Down
31 changes: 31 additions & 0 deletions test-cases/page-build-errors/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tap from 'tap'
import desm from 'desm'
import { Siteup } from '../../index.js'
import * as path from 'path'
import rimraf from 'rimraf'
import { promisify } from 'util'

const __dirname = desm(import.meta.url)
const rimrafP = promisify(rimraf)

tap.test('build-errors', async (t) => {
const src = path.join(__dirname, './src')
const dest = path.join(__dirname, './public')
const cwd = __dirname
const siteUp = new Siteup(src, dest, cwd)

await rimrafP(dest)

try {
const results = await siteUp.build()
t.notOk(results, 'Build should fail, and not generate results')
} catch (err) {
t.match(err.message, /Build finished but there were errors/, 'Should have an error message about a filed build.')
t.ok(Array.isArray(err.errors), 'Should have an array of errors')

const pageError = err.errors.find(err => err.message.includes('Error building page'))

t.ok(pageError, 'Should include a page build error')
t.ok(pageError.cause, 'Should include an error cause')
}
})
1 change: 1 addition & 0 deletions test-cases/page-build-errors/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.md
3 changes: 3 additions & 0 deletions test-cases/page-build-errors/src/a-working-page/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A working page

Just some working markdown
File renamed without changes.
1 change: 1 addition & 0 deletions test-cases/page-build-errors/src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hi')
7 changes: 7 additions & 0 deletions test-cases/page-build-errors/src/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default () => /* html */`
<div>Hello this is a JS page</div>
`

// Some garbled JS syntax
// eslint-disable-next-line
fdsf dsf fdsaf;
3 changes: 3 additions & 0 deletions test-cases/page-build-errors/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.some-class {
background: blue;
}

0 comments on commit f0d9669

Please sign in to comment.