Skip to content

Commit

Permalink
Use snapshot to test output of build script (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
colebemis authored Mar 12, 2020
1 parent f148a7e commit 3776160
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 73 deletions.
52 changes: 0 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"js-yaml": "^3.13.1",
"lodash.keyby": "^4.6.0",
"trim-newlines": "^3.0.0",
"yargs": "^15.1.0",
"yup": "^0.28.1"
"yargs": "^15.1.0"
}
}
22 changes: 3 additions & 19 deletions tests/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@
const path = require('path')
const test = require('ava')
const execa = require('execa')
const yup = require('yup')

test('builds a JSON object with a valid schema', t => {
const schema = yup.array(
yup.object({
name: yup.string().required(),
// `array().required()` doesn't work for `keywords` because
// `array().required()` treats `[]` as a missing value.
// `mixed().required()` ensures that the property is defined,
// but doesn't ensure that it's an array.
keywords: yup.array().ensure(),
width: yup.number().required(),
height: yup.number().required(),
path: yup.string().required()
})
)

return execa(path.resolve(__dirname, '../script/build.js'), ['--input=../icons/**/*.svg'], {
test('builds an object with the correct shape', t => {
return execa(path.resolve(__dirname, '../script/build.js'), ['--input', 'icon-a.svg', 'icon-b.svg'], {
cwd: __dirname
}).then(({stdout}) => {
const icons = JSON.parse(stdout)

t.true(schema.isValidSync(Object.values(icons)))
t.snapshot(icons)
})
})

Expand Down
2 changes: 2 additions & 0 deletions tests/icon-a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/icon-b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions tests/snapshots/build.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Snapshot report for `tests/build.js`

The actual snapshot is saved in `build.js.snap`.

Generated by [AVA](https://ava.li).

## builds an object with the correct shape

> Snapshot 1
{
'icon-a': {
height: 16,
keywords: [],
name: 'icon-a',
path: '<path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 000 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 00.01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path>',
width: 16,
},
'icon-b': {
height: 16,
keywords: [],
name: 'icon-b',
path: '<path fill-rule="evenodd" d="M13 2H1v2h12V2zM0 4a1 1 0 001 1v9a1 1 0 001 1h10a1 1 0 001-1V5a1 1 0 001-1V2a1 1 0 00-1-1H1a1 1 0 00-1 1v2zm2 1h10v9H2V5zm2 3h6V7H4v1z"></path>',
width: 14,
},
}
Binary file added tests/snapshots/build.js.snap
Binary file not shown.

1 comment on commit 3776160

@vercel
Copy link

@vercel vercel bot commented on 3776160 Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.