Skip to content

Commit

Permalink
test: add tests for readOrCreateFileSync and readFileSync in ConfigFile
Browse files Browse the repository at this point in the history
  • Loading branch information
TBubba committed Apr 29, 2020
1 parent c025d30 commit 18a942c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/src/back/ConfigFile.test.ts
Expand Up @@ -21,6 +21,12 @@ describe('Config File', () => {
expect(await ConfigFile.readFile(filePath)).toEqual(staticConfig);
});

test('Read Config File Synchronously', () => {
// staticConfig should be identical to the one in ./tests/static/back/config.json
const filePath = path.join(STATIC_PATH, BASE_PATH, 'config.json');
expect(ConfigFile.readFileSync(filePath)).toEqual(staticConfig);
});

test('Generate Config File', async () => {
// Create file
const filePath = path.join(RESULT_PATH, BASE_PATH, 'config_generated.json');
Expand All @@ -32,6 +38,17 @@ describe('Config File', () => {
expect(fileData).toEqual(defaultData);
});

test('Generate Config File Synchronously', async () => {
// Create file
const filePath = path.join(RESULT_PATH, BASE_PATH, 'config_generated_sync.json');
ConfigFile.readOrCreateFileSync(filePath);
// Get expected defaults
const rawData = await fs.readFile(filePath, 'utf8');
const fileData = JSON.parse(rawData);
const defaultData = getDefaultConfigData(process.platform);
expect(fileData).toEqual(defaultData);
});

test('Save Config File', async () => {
const filePath = path.join(RESULT_PATH, BASE_PATH, 'config_saved.json');
await ConfigFile.saveFile(filePath, staticConfig);
Expand Down

0 comments on commit 18a942c

Please sign in to comment.