Skip to content

Commit

Permalink
✅ Test: add before and after test
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Mar 18, 2017
1 parent c2de1b6 commit fa7fb37
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/prompConfig.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import fs from 'fs-extra';
import test from 'ava';
import path from 'path';
import chalk from 'chalk';
import json from 'json-extra';
import os from 'os';
import getConfig from '../lib/getConfig';
import { choices, questions } from '../lib/promptConfig';

const cwd = process.cwd();
const homedir = os.homedir();
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);

let globalExist = false;


// rename global .sgcrc
test.before(() => {
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
globalExist = true;
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}.back`));
}
});

test.after(() => {
if (globalExist) {
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}.back`), path.join(homedir, '.sgcrc'));
}
});

test('get configuration file equals .sgcrc_default', (t) => {
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));
Expand Down

0 comments on commit fa7fb37

Please sign in to comment.