Skip to content

Commit

Permalink
test: Add JSON array input test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
qistoph committed Feb 4, 2021
1 parent acec7e2 commit 99f8ae6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/fixtures/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"asdf",
"test"
]
49 changes: 49 additions & 0 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { INVALID_PATH_ERROR, INVALID_JSON_PATH_ERROR } from '../src/utils'

const PATH_FIXTURES = path.join('test', 'fixtures')
const PATH_JSON_FIXTURE = path.join(PATH_FIXTURES, '1.json')
const PATH_JSON_ARRAY_FIXTURE = path.join(PATH_FIXTURES, '2.json')
const PATH_SLURP_FIXTURE_1 = path.join(PATH_FIXTURES, 'slurp1.json')
const PATH_SLURP_FIXTURE_2 = path.join(PATH_FIXTURES, 'slurp2.json')
const PATH_SORT_FIXTURE = path.join(PATH_FIXTURES, 'sort.json')
Expand All @@ -16,6 +17,10 @@ const FIXTURE_JSON = require('./fixtures/1.json')
const FIXTURE_JSON_STRING = JSON.stringify(FIXTURE_JSON)
const FIXTURE_JSON_PRETTY = JSON.stringify(FIXTURE_JSON, null, 2)

const FIXTURE_JSON_ARRAY = require('./fixtures/2.json')
const FIXTURE_JSON_ARRAY_STRING = JSON.stringify(FIXTURE_JSON_ARRAY)
const FIXTURE_JSON_ARRAY_PRETTY = JSON.stringify(FIXTURE_JSON_ARRAY, null, 2)

const FILTER_VALID = '.repository.type'

const OPTION_DEFAULTS = {
Expand Down Expand Up @@ -122,6 +127,17 @@ describe('options', () => {
})
})

it('should accept an array object', done => {
run('.', FIXTURE_JSON_ARRAY, { input: 'json' })
.then(output => {
expect(output).to.not.equal(null)
done()
})
.catch(error => {
done(error)
})
})

it('should accept an empty string as json object', done => {
run('.', '', { input: 'json' })
.then(output => {
Expand Down Expand Up @@ -169,6 +185,17 @@ describe('options', () => {
})
})

it('should accept a json array as input', done => {
run('.', FIXTURE_JSON_ARRAY_STRING, { input: 'string' })
.then(output => {
expect(output).to.not.equal(null)
done()
})
.catch(error => {
done(error)
})
})

it('should fail on an empty string', done => {
run('.', '', { input: 'string' })
.catch(error => {
Expand Down Expand Up @@ -249,6 +276,17 @@ describe('options', () => {
done(error)
})
})

it('should return a minified json array string', done => {
run('.', PATH_JSON_ARRAY_FIXTURE, { output: 'string' })
.then(output => {
expect(output).to.equal(FIXTURE_JSON_ARRAY_STRING)
done()
})
.catch(error => {
done(error)
})
})
})

describe('compact', () => {
Expand All @@ -275,6 +313,17 @@ describe('options', () => {
done(error)
})
})

it('should return a prettified json array string', done => {
run('.', PATH_JSON_ARRAY_FIXTURE, { output: 'pretty' })
.then(output => {
expect(output).to.be.oneOf(multiEOL(FIXTURE_JSON_ARRAY_PRETTY))
done()
})
.catch(error => {
done(error)
})
})
})
})

Expand Down

0 comments on commit 99f8ae6

Please sign in to comment.