Skip to content
Permalink
Browse files
Create projects instead of asserting their properties in pkgJson.spec
  • Loading branch information
raphinesse committed Apr 13, 2019
1 parent 38f7c13 commit 22d8deef4d664031cf3c7cdeedcecf8b325cb2a1
Showing 1 changed file with 21 additions and 24 deletions.
@@ -32,7 +32,7 @@ describe('pkgJson', function () {
const fixturesPath = path.join(__dirname, '../spec/cordova/fixtures');
let tmpDir, project, pkgJsonPath;
const {
getPkgJsonPath, setupBaseProject, getCfg, getPkgJson
getPkgJsonPath, setupBaseProject, getCfg, getPkgJson, setPkgJson
} = projectTestHelpers(() => project);

beforeEach(() => {
@@ -47,11 +47,6 @@ describe('pkgJson', function () {
fs.removeSync(tmpDir);
});

function useProject (name) {
fs.copySync(path.join(fixturesPath, name), project);
process.chdir(project);
}

// Copies a fixture to temp dir to avoid modifiying it as they get installed as symlinks
function copyFixture (fixtureRelativePath) {
const fixturePath = path.join(fixturesPath, fixtureRelativePath);
@@ -383,9 +378,9 @@ describe('pkgJson', function () {
});
});

// Test #020 : use basePkgJson15 as pkg.json contains platform/spec and plugin/spec and config.xml does not.
// Test #020 : pkg.json contains platform/spec and plugin/spec and config.xml does not
describe('During add, if pkg.json has a platform/plugin spec, use that one.', function () {
beforeEach(() => useProject('basePkgJson15'));
beforeEach(() => setupBaseProject());

/** Test#020 will check that pkg.json, config.xml, platforms.json, and cordova platform ls
* are updated with the correct (platform and plugin) specs from pkg.json.
@@ -394,9 +389,8 @@ describe('pkgJson', function () {
const PLATFORM = 'ios';
const PLUGIN = 'cordova-plugin-splashscreen';

// Pkg.json has ios and spec '^4.2.1' and splashscreen '^3.2.2'.
expect(getPkgJson('cordova.platforms')).toEqual([ PLATFORM ]);
expect(getPkgJson('dependencies')).toEqual({
setPkgJson('cordova.platforms', [ PLATFORM ]);
setPkgJson('dependencies', {
[PLUGIN]: '^3.2.2',
[`cordova-${PLATFORM}`]: '^4.5.4'
});
@@ -424,9 +418,9 @@ describe('pkgJson', function () {
}, TIMEOUT * 2);
});

// Test #021 : use basePkgJson16 as config.xml contains platform/spec and plugin/spec pkg.json does not.
// Test #021 : config.xml contains platform/spec and plugin/spec pkg.json does not
describe('During add, if config.xml has a platform/plugin spec and pkg.json does not, use config.', function () {
beforeEach(() => useProject('basePkgJson16'));
beforeEach(() => setupBaseProject());

/** Test#021 during add, this test will check that pkg.json, config.xml, platforms.json,
* and cordova platform ls are updated with the correct platform/plugin spec from config.xml.
@@ -435,7 +429,11 @@ describe('pkgJson', function () {
const PLATFORM = 'ios';
const PLUGIN = 'cordova-plugin-splashscreen';

// Pkg.json does not have platform or spec yet. Config.xml has ios and spec '~4.2.1'.
getCfg()
.addEngine(PLATFORM, '~4.2.1')
.addPlugin({ name: PLUGIN, spec: '~3.2.2' })
.write();

expect(installedPlatforms()).toEqual([]);

// Remove for testing purposes so platform is not pre-installed.
@@ -456,9 +454,9 @@ describe('pkgJson', function () {
});
});

// Test #022 : use basePkgJson17 (config.xml and pkg.json each have ios platform with different specs).
// Test #022 : config.xml and pkg.json each have ios platform with different specs
describe('During add, if add specifies a platform spec, use that one regardless of what is in pkg.json or config.xml', function () {
beforeEach(() => useProject('basePkgJson17'));
beforeEach(() => setupBaseProject());

/** Test#022 : when adding with a specific platform version, always use that one
* regardless of what is in package.json or config.xml.
@@ -467,16 +465,15 @@ describe('pkgJson', function () {
const PLATFORM = 'ios';
const PLUGIN = 'cordova-plugin-splashscreen';

// Pkg.json has ios and spec '^4.2.1'.
expect(getPkgJson('cordova.platforms')).toEqual([ PLATFORM ]);
expect(getPkgJson('dependencies')).toEqual({
setPkgJson('cordova.platforms', [ PLATFORM ]);
setPkgJson('dependencies', {
[`cordova-${PLATFORM}`]: '^4.2.1',
[PLUGIN]: '~3.2.2'
[PLUGIN]: '^3.2.2'
});
// Config.xml has ios and spec ~4.2.1.
expect(getCfg().getEngines()).toEqual([
{ name: PLATFORM, spec: '~4.2.1' }
]);
getCfg()
.addEngine(PLATFORM, '~4.2.1')
.addPlugin({ name: PLUGIN, spec: '~3.2.1' })
.write();

expect(installedPlatforms()).toEqual([]);

0 comments on commit 22d8dee

Please sign in to comment.