From 99f8ae6b3383547d408f5e2aa282ab58f930a92a Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 4 Feb 2021 11:59:05 +0000 Subject: [PATCH] test: Add JSON array input test cases --- test/fixtures/2.json | 4 ++++ test/options.test.js | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/fixtures/2.json diff --git a/test/fixtures/2.json b/test/fixtures/2.json new file mode 100644 index 00000000..71bc6f2f --- /dev/null +++ b/test/fixtures/2.json @@ -0,0 +1,4 @@ +[ + "asdf", + "test" +] diff --git a/test/options.test.js b/test/options.test.js index 4dab44c1..f4e25838 100644 --- a/test/options.test.js +++ b/test/options.test.js @@ -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') @@ -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 = { @@ -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 => { @@ -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 => { @@ -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', () => { @@ -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) + }) + }) }) })