* Test fixes
This commit is contained in:
Anna Kocheshkova 2018-05-15 16:25:33 +03:00 коммит произвёл GitHub
Родитель cc4ea60a9e
Коммит ab2ac551af
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 58 добавлений и 39 удалений

Просмотреть файл

@ -1,3 +1,8 @@
import mock = require('mock-fs');
import fs = require('fs');
import jsxml = require('node-jsxml');
import plist = require('plist');
import should = require('should');
import sinon = require('sinon');
import { Utils } from '../src/helpers/utils/utils';
@ -7,11 +12,7 @@ import { ConsoleLogger } from '../src/extension/log/consoleLogger';
describe('AppCenterConfig', function () {
let appCenterConfig: AppCenterConfig;
let path;
let jsxml;
let fs;
let sandbox;
const root = "./test/mock";
const appName: string = "appName";
let androidStringsPath: string;
let pathToAppCenterConfigPlist: string;
@ -19,28 +20,33 @@ describe('AppCenterConfig', function () {
let pathToAndroidConfig: string;
before(() => {
path = require("path");
jsxml = require("node-jsxml");
fs = require("fs");
androidStringsPath = path.join(root, "android", "app", "src", "main", "res", "values", "strings.xml");
pathToAppCenterConfigPlist = path.join(root, "ios", appName, "AppCenter-Config.plist");
pathToMainPlist = path.join(root, "ios", appName, "Info.plist");
pathToAndroidConfig = path.join(root, "android", "app", "src", "main", "assets", "appcenter-config.json");
// Cleanup the files.
fs.writeFileSync(pathToAppCenterConfigPlist, "");
fs.writeFileSync(pathToMainPlist, "");
fs.writeFileSync(pathToAndroidConfig, "");
fs.writeFileSync(androidStringsPath, fs.readFileSync(path.resolve(root, "exampleStringsXml.xml")));
mock({
"android/app/src/main/res/values": {
'strings.xml': '<?xml version="1.0" encoding="utf-8"?><resources><string name="name"></string></resources>'
},
"android/app/src/assets": {
'appcenter-config.json' : ""
},
"ios/appName/" : {
"AppCenter-Config.plist" : '<?xml version="1.0" encoding="UTF-8"?>',
"Info.plist" : '<?xml version="1.0" encoding="UTF-8"?>'
}
});
androidStringsPath = "android/app/src/main/res/values/strings.xml";
pathToAppCenterConfigPlist = `ios/${appName}/AppCenter-Config.plist`;
pathToMainPlist = `ios/${appName}/Info.plist`;
pathToAndroidConfig = "android/app/src/main/assets/appcenter-config.json";
sandbox = sinon.sandbox.create();
const loggerStub: ILogger = sandbox.stub(ConsoleLogger.prototype);
appCenterConfig = Utils.createAppCenterConfigFrom(appName, path.resolve(root), loggerStub);
appCenterConfig = Utils.createAppCenterConfigFrom(appName, '', loggerStub);
});
after(() => { sandbox.restore(); });
after(() => {
sandbox.restore();
mock.restore();
});
describe('#setAndroidStringResourcesDeploymentKey', () => {
it('should set the deployment key', async () => {
const depKey = "key";
appCenterConfig.setAndroidStringResourcesDeploymentKey(depKey);
@ -52,7 +58,6 @@ describe('AppCenterConfig', function () {
});
describe('#configPlistValue', () => {
it('should set and get config plist value', async () => {
const key = "key";
const value = "value";
@ -60,6 +65,10 @@ describe('AppCenterConfig', function () {
appCenterConfig.saveConfigPlist();
const newValue = appCenterConfig.getConfigPlistValueByKey(key);
newValue.should.equal(value);
const data = fs.readFileSync(pathToAppCenterConfigPlist, { encoding: "utf8" });
const parsedInfoConfigPlist = plist.parse(data);
parsedInfoConfigPlist.hasOwnProperty(key).should.be.true();
parsedInfoConfigPlist.key.should.equal(value);
});
it('should delete config plist value', async () => {
@ -68,13 +77,16 @@ describe('AppCenterConfig', function () {
appCenterConfig.setConfigPlistValueByKey(key, value);
appCenterConfig.saveConfigPlist();
appCenterConfig.deleteConfigPlistValueByKey(key);
appCenterConfig.saveConfigPlist();
const newValue = appCenterConfig.getConfigPlistValueByKey(key);
should.equal(newValue, undefined);
const data = fs.readFileSync(pathToAppCenterConfigPlist, { encoding: "utf8" });
const parsedInfoConfigPlist = plist.parse(data);
parsedInfoConfigPlist.hasOwnProperty(key).should.be.false();
});
});
describe('#androidconfigValue', () => {
it('should set and get android config value', async () => {
const key = "key";
const value = "value";
@ -82,6 +94,10 @@ describe('AppCenterConfig', function () {
appCenterConfig.saveAndroidAppCenterConfig();
const newValue = appCenterConfig.getAndroidAppCenterConfigValueByKey(key);
newValue.should.equal(value);
const data = fs.readFileSync(pathToAndroidConfig, { encoding: "utf8" });
const parsedAndroidConfig = JSON.parse(data);
parsedAndroidConfig.hasOwnProperty(key).should.be.true();
parsedAndroidConfig.key.should.equal(value);
});
it('should delete android config value', async () => {
@ -90,13 +106,16 @@ describe('AppCenterConfig', function () {
appCenterConfig.setAndroidAppCenterConfigValueByKey(key, value);
appCenterConfig.saveAndroidAppCenterConfig();
appCenterConfig.deleteAndroidAppCenterConfigValueByKey(key);
appCenterConfig.saveAndroidAppCenterConfig();
const newValue = appCenterConfig.getAndroidAppCenterConfigValueByKey(key);
should.equal(newValue, undefined);
const data = fs.readFileSync(pathToAndroidConfig, { encoding: "utf8" });
const parsedAndroidConfig = JSON.parse(data);
parsedAndroidConfig.hasOwnProperty(key).should.be.false();
});
});
describe('#mainPlistValue', () => {
it('should set and get main plist value', async () => {
const key = "key";
const value = "value";
@ -104,6 +123,10 @@ describe('AppCenterConfig', function () {
appCenterConfig.saveMainPlist();
const newValue = appCenterConfig.getMainPlistValueByKey(key);
newValue.should.equal(value);
const data = fs.readFileSync(pathToMainPlist, { encoding: "utf8" });
const parsedMainPlist = plist.parse(data);
parsedMainPlist.hasOwnProperty(key).should.be.true();
parsedMainPlist.key.should.equal(value);
});
});
});

Просмотреть файл

@ -71,7 +71,7 @@ describe('Auth', function () {
sandbox.restore();
});
it('should login', async () => {
it('should save profile and token for profile userId', async () => {
const profile = await vstsAuth.doLogin(vstsLoginInfo);
profile.should.deepEqual(mockProfile);
removeTokenStub.withArgs(mockId).calledOnce.should.be.true();
@ -117,7 +117,7 @@ describe('Auth', function () {
sandbox.restore();
});
it('should logout', async () => {
it('should remove profile and token for profile userId', async () => {
await vstsAuth.doLogout(mockId);
removeTokenStub.withArgs(mockId).calledOnce.should.be.true();
deleteStub.withArgs(mockId).calledOnce.should.be.true();

Просмотреть файл

@ -36,7 +36,7 @@ describe('FsProfileStorage', function () {
after(() => {
// Delete the file created during testing.
const absolutePath = path.resolve("test/" + fakeFilePath);
fs.unlink(absolutePath);
fs.unlinkSync(absolutePath);
});
it('should create empty storage', async () => {

Просмотреть файл

@ -30,17 +30,17 @@ describe('FsUtils', function () {
describe('#IsEmptyDirectoryToStartNewProject', () => {
it('should recognize an empty directory to start new project', async () => {
it('should return true if directory is empty', async () => {
const isEmpty = FSUtils.IsEmptyDirectoryToStartNewProject(pathToCreateEmptyFolder);
isEmpty.should.be.true();
});
it('should recognize a non-empty directory', async () => {
it('should return false if directory is not empty', async () => {
const isEmpty = FSUtils.IsEmptyDirectoryToStartNewProject(pathToNonEmptyDir);
isEmpty.should.be.false();
});
it('should ignore .vscode and .git', async () => {
it('should return true if directory is empty but has .vscode and .git folders', async () => {
const isEmpty = FSUtils.IsEmptyDirectoryToStartNewProject(dirWithIgnoredFilesPath);
isEmpty.should.be.true();
});
@ -48,17 +48,17 @@ describe('FsUtils', function () {
describe('#IsEmptyDirectory', () => {
it('should recognize an empty directory', async () => {
it('should return true if directory is empty', async () => {
const isEmpty = FSUtils.IsEmptyDirectory(pathToCreateEmptyFolder);
isEmpty.should.be.true();
});
it('should recognize a non-empty directory', async () => {
it('should return false if directory is not empty', async () => {
const isEmpty = FSUtils.IsEmptyDirectory(pathToNonEmptyDir);
isEmpty.should.be.false();
});
it('should ignore .vscode', async () => {
it('should return true if directory is empty but has .vscode folder', async () => {
const isEmpty = FSUtils.IsEmptyDirectory(dirWithIgnoredVscodePath);
isEmpty.should.be.true();
});

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="name"></string>
</resources>

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -15,7 +15,7 @@ describe('Utils', function () {
describe('#Format', () => {
it('should format the message properly', async () => {
it('should remove the newlines from the message', async () => {
const messageBeforeFormatting = `Test message!
New line here.`;
const messageAfterFormatting = "Test message! New line here.";
@ -54,7 +54,7 @@ New line here.`;
path = require("path");
});
it('should read json file properly', async () => {
it('should read and convert json file properly', async () => {
const file = Utils.parseJsonFile(path.resolve("test/" + jsonFilePath));
file.should.not.be.null;
file.property.should.equal("value");
@ -81,7 +81,7 @@ New line here.`;
path = require("path");
});
it('should read app name', async () => {
it('should read app name from package.json', async () => {
const file = Utils.getAppName(path.resolve(root));
file.should.equal("app_name");
});