import fse from 'fs-extra';
import { expect } from 'chai';
import { saveJson } from '../../mat/util/file-save';

describe('util/file-save.js saveJson()', () => {
    before((done) => {
        // 删除临时文件目录
        fse.removeSync('./test/tmp/util-file-save');

        saveJson(require('../data/fixtures/util-file-save/file.js'), './test/tmp/util-file-save/file.json')
            .then(() => {
                done();
            })
            .catch((err) => {
                // console.error('err', err);
                done();
            });
    });

    after(() => {
        fse.removeSync('./test/tmp/util-file-save');
    });

    it('Save json object to .json file success!', (done) => {
        // 保存的文件内容
        const newSavedFile = fse.readFileSync('./test/tmp/util-file-save/file.json', 'utf8');

        // 预期的文件内容
        const expectedFile = fse.readFileSync('./test/data/expected/util-file-save/file.json', 'utf8');

        expect(newSavedFile).to.equal(expectedFile);

        done();
    });
});

@@ -1,12 +1,37 @@
+import path from 'path';%0A
 import fse f
@@ -135,56 +135,519 @@
 ';%0A%0A
-describe('util/file-save.js saveJson()', () =%3E %7B
+const BASE_PATH_TMP = './test/tmp';%0Aconst BASE_PATH_EXPECTED = './test/data/expected';%0Aconst BASE_PATH_SRC = '../data/fixtures';%0Aconst FOLDER_NAME = 'util-file-save';%0A%0Adescribe('util/file-save.js saveJson()', () =%3E %7B%0A    const TMP_SAVE_FOLDER = path.join(BASE_PATH_TMP, FOLDER_NAME);%0A    const TMP_SAVE_FILE = path.join(TMP_SAVE_FOLDER, 'file.json');%0A%0A    const EXPECTED_SAVE_FILE = path.join(BASE_PATH_EXPECTED, FOLDER_NAME, 'file.json');%0A    const SRC_FILE = path.join(BASE_PATH_SRC, FOLDER_NAME, 'file.js');%0A
 %0A   
@@ -713,35 +713,23 @@
 ync(
-'./test/tmp/util-file-save'
+TMP_SAVE_FOLDER
 );%0A%0A
@@ -757,89 +757,32 @@
 ire(
-'../data/fixtures/util-file-save/file.js'), './test/tmp/util-file-save/file.json'
+SRC_FILE), TMP_SAVE_FILE
 )%0A  
@@ -1014,35 +1014,23 @@
 ync(
-'./test/tmp/util-file-save'
+TMP_SAVE_FOLDER
 );%0A 
@@ -1168,45 +1168,21 @@
 ync(
-'./test/tmp/util-file-save/file.json'
+TMP_SAVE_FILE
 , 'u
@@ -1258,55 +1258,26 @@
 ync(
-'./test/data/expected/util-file-save/file.json'
+EXPECTED_SAVE_FILE
 , 'u

重构了测试用例的写法，将变量提出来