-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
664 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cache | ||
build | ||
**/node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"globals": {}, | ||
"extends": ["eslint:recommended", "plugin:prettier/recommended"], | ||
"parserOptions": { | ||
"ecmaVersion": 12 | ||
}, | ||
"plugins": ["prettier"], | ||
"rules": { | ||
"no-unused-vars": ["error", { "varsIgnorePattern": "^omit.*$" }], | ||
"array-callback-return": "off", | ||
"arrow-parens": ["error", "as-needed"], | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"quoteProps": "consistent", | ||
"semi": false, | ||
"arrowParens": "avoid", | ||
"singleQuote": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,124 @@ | ||
const combineJson = require('../src/combine-json'); | ||
const fs = require('fs'); | ||
const rimraf = require('rimraf'); | ||
const combineJson = require('../src/combine-json') | ||
const fs = require('fs') | ||
const rimraf = require('rimraf') | ||
|
||
const OUTPUT_DIR = 'test-output'; | ||
const OUTPUT_DIR = 'test-output' | ||
|
||
beforeAll(() => { | ||
if (!fs.existsSync(OUTPUT_DIR)) { | ||
fs.mkdirSync(OUTPUT_DIR); | ||
fs.mkdirSync(OUTPUT_DIR) | ||
} | ||
}); | ||
}) | ||
|
||
test('Tests on 1 empty file', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/one_empty', | ||
outputFile: 'test-output/combine_empty.json', | ||
}); | ||
}) | ||
|
||
const data = JSON.parse( | ||
fs.readFileSync(`${process.cwd()}/test-output/combine_empty.json`, 'utf-8') | ||
); | ||
const expected = []; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests on multiple empty files', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/multiple_empty', | ||
outputFile: 'test-output/combine_multiple_empty.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync( | ||
`${process.cwd()}/test-output/combine_multiple_empty.json`, | ||
'utf-8' | ||
) | ||
); | ||
const expected = []; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests on some invalid files and some valid', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/multiple_empty', | ||
outputFile: 'test-output/combine_multiple_empty.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync( | ||
`${process.cwd()}/test-output/combine_multiple_empty.json`, | ||
'utf-8' | ||
) | ||
); | ||
const expected = []; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests if on 1 file containing one primitive', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/one_primitive', | ||
outputFile: 'test-output/combine_a_single_primitive.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync( | ||
`${process.cwd()}/test-output/combine_a_single_primitive.json`, | ||
'utf-8' | ||
) | ||
); | ||
const expected = [1]; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [1] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests if on 1 files', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/one_file', | ||
outputFile: 'test-output/combine_one.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync(`${process.cwd()}/test-output/combine_one.json`, 'utf-8') | ||
); | ||
const expected = [{ name: 'Hello' }, { name: 'Hello' }, { name: 'Hello' }]; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [{ name: 'Hello' }, { name: 'Hello' }, { name: 'Hello' }] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests on 3 array', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc/array_test', | ||
outputFile: 'test-output/combine_array.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync(`${process.cwd()}/test-output/combine_array.json`, 'utf-8') | ||
); | ||
const expected = [{ name: 'far away' }, { name: 'far away and behind' }, 1, 2, 3]; | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = [ | ||
{ name: 'far away' }, | ||
{ name: 'far away and behind' }, | ||
1, | ||
2, | ||
3, | ||
] | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
test('Tests if on all files', async () => { | ||
const res = await combineJson({ | ||
inputDir: 'misc', | ||
outputFile: 'test-output/combine_all.json', | ||
}); | ||
}) | ||
const data = JSON.parse( | ||
fs.readFileSync(`${process.cwd()}/test-output/combine_all.json`, 'utf-8') | ||
); | ||
const expected = require('./assets/combine_all.json'); | ||
expect(res).toBe(1); | ||
expect(data).toEqual(expected); | ||
}); | ||
) | ||
const expected = require('./assets/combine_all.json') | ||
expect(res).toBe(1) | ||
expect(data).toEqual(expected) | ||
}) | ||
|
||
afterAll(() => { | ||
if (fs.existsSync(OUTPUT_DIR)) { | ||
// rimraf.sync(OUTPUT_DIR); | ||
rimraf.sync(OUTPUT_DIR) | ||
} | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.