Skip to content

Commit

Permalink
test(ConfigFile): minor improvements (#134)
Browse files Browse the repository at this point in the history
* test(ConfigFile): Fix module name
* test(ConfigFile): get fresh module for each test
  • Loading branch information
raphinesse committed Mar 15, 2020
1 parent fe6a73f commit fed6d05
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions spec/ConfigChanges/ConfigFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
*/

var rewire = require('rewire');
var configFile = rewire('../../src/ConfigChanges/ConfigFile');
var fs = require('fs-extra');
var path = require('path');
const readChunk = require('read-chunk');

describe('ConfigFile tests', function () {
let ConfigFile;
beforeEach(() => {
ConfigFile = rewire('../../src/ConfigChanges/ConfigFile');
});

describe('instance methods', () => {
describe('save', () => {
it('calls fs.writeFileSync', function () {
spyOn(fs, 'writeFileSync');
configFile.prototype.save();
ConfigFile.prototype.save();
expect(fs.writeFileSync).toHaveBeenCalled();
});
});
Expand All @@ -36,18 +40,18 @@ describe('ConfigFile tests', function () {
describe('isBinaryPlist', () => {
it('should return false if not binary', function () {
spyOn(readChunk, 'sync').and.returnValue('not bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(false);
expect(ConfigFile.isBinaryPlist('someFile')).toBe(false);
});

it('should return true if binary', function () {
spyOn(readChunk, 'sync').and.returnValue('bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(true);
expect(ConfigFile.isBinaryPlist('someFile')).toBe(true);
});
});

describe('getIOSProjectname', () => {
it('should throw error', function () {
expect(function () { configFile.getIOSProjectname('some/project/name'); }).toThrow();
expect(function () { ConfigFile.getIOSProjectname('some/project/name'); }).toThrow();
});
});

Expand All @@ -56,46 +60,46 @@ describe('ConfigFile tests', function () {

it('should return file path', function () {
var filePath = path.join('project_dir', 'file');
expect(configFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
});

it('should return AndroidManifest.xml file path', function () {
var androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
});

it('should return android config.xml file path', function () {
var configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
});

it('should return android strings.xml file path', function () {
var stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
});

it('should return ios config.xml file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('iospath');
spyOn(ConfigFile, 'getIOSProjectname').and.returnValue('iospath');
var configPath = path.join('project_dir', 'iospath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
});

it('should return osx config.xml file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('osxpath');
spyOn(ConfigFile, 'getIOSProjectname').and.returnValue('osxpath');
var configPath = path.join('project_dir', 'osxpath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'osx', 'config.xml')).toBe(configPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'osx', 'config.xml')).toBe(configPath);
});

it('should return android resource file path when path is normalized', function () {
var file = path.join('res', 'xml');
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});

it('should return android resource file path when path is not normalized', function () {
var file = 'res/xml';
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});
});
});
Expand Down

0 comments on commit fed6d05

Please sign in to comment.