Skip to content

Commit

Permalink
Use up-to-date fixtures in tests (#770)
Browse files Browse the repository at this point in the history
* Add helper to get up-to-date test fixtures

* Use up-to-date project fixture in E2E plugin dependency tests

* Use up-to-date platform fixture in plugman.install tests

* Use up-to-date platform in HooksRunner E2E tests

* Use up-to-date platform fixture in plugman.uninstall tests

* Use up-to-date project fixture in pkgJson plugin E2E tests

* Use up-to-date platform fixture in plugin.spec E2E tests

* Remove unused and outdated Android project fixture

* Remove unused project fixture "base"

* Use cordova-test-platform to test platform installation from local path

* Remove unused cordova-browser fixture

* Use cordova-test-platform to test getInstalledPlatformsWithVersions

* Remove unused cordova-android fixture

* Use testPlatformApp fixture to test cordova/util.getPlatformApiFunction

* Finally remove shelljs (again)

Had to be kept in devDeps before because of some outdated fixtures

* Make platformApi fixture project a minimal stub
  • Loading branch information
raphinesse committed Oct 10, 2019
1 parent 7f66885 commit 293b9c0
Show file tree
Hide file tree
Showing 1,362 changed files with 239 additions and 173,083 deletions.
16 changes: 7 additions & 9 deletions integration-tests/HooksRunner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ describe('HooksRunner', function () {
}).forEach(f => fs.chmodSync(f, 0o755));

// Add the testing platform and plugin to our project
fs.copySync(
path.join(__dirname, '../spec/plugman/projects', testPlatform),
path.join(preparedProject, 'platforms', testPlatform)
);
fs.copySync(
testPluginFixture,
path.join(preparedProject, 'plugins', testPlugin)
);
});
process.chdir(preparedProject);
return cordova.platform('add', testPlatform)
.then(() => fs.copy(
testPluginFixture,
path.join(preparedProject, 'plugins', testPlugin)
));
}, 60 * 1000);

beforeEach(function () {
// Reset our test project
Expand Down
9 changes: 3 additions & 6 deletions integration-tests/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ describe('end-to-end plugin dependency tests', function () {
helpers.setDefaultTimeout(TIMEOUT);

// This prepares a project that we will copy and use for all tests
const preparedProject = helpers.tmpDir('plugin_dependency_test_project');
let preparedProject;
beforeAll(function () {
return cordova.create(preparedProject)
.then(function () {
process.chdir(preparedProject);
return cordova.platform('add', 'android', { save: true });
});
preparedProject = helpers.tmpDir('plugin_dependency_test_project');
return helpers.getFixture('projectWithPlatform').copyTo(preparedProject);
});

afterAll(function () {
Expand Down
76 changes: 46 additions & 30 deletions integration-tests/pkgJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const path = require('path');
const fs = require('fs-extra');
const semver = require('semver');
const { listPlatforms, requireNoCache } = require('../src/cordova/util');
const { tmpDir: getTmpDir, testPlatform, setDefaultTimeout } = require('../spec/helpers');
const { tmpDir: getTmpDir, testPlatform, getFixture, setDefaultTimeout } = require('../spec/helpers');
const projectTestHelpers = require('../spec/project-test-helpers');
const cordova = require('../src/cordova/cordova');

Expand Down Expand Up @@ -112,18 +112,27 @@ describe('pkgJson', function () {
describe('plugin end-to-end', function () {
const pluginId = 'cordova-plugin-device';

// Prepare a project with platform that can be reused by below tests
let projectFixture;
beforeAll(() => {
projectFixture = getTmpDir('pkgJson-project-fixture');
return getFixture('projectWithPlatform').copyTo(projectFixture);
});

afterAll(() => {
process.chdir(__dirname); // Needed to rm the dir on Windows.
fs.removeSync(projectFixture);
});

beforeEach(function () {
setupBaseProject();
// Copy some platform to avoid working on a project with no platforms.
// FIXME Use a fixture that is properly promisified. This one
// causes spurious test failures when tests reuse the project path.
fs.copySync(path.join(__dirname, '../spec/plugman/projects', testPlatform), path.join(project, 'platforms', testPlatform));
fs.copySync(projectFixture, project);
process.chdir(project);
});

it('Test#001 : should successfully add and remove a plugin with save and correct spec', function () {
// No plugins in config or pkg.json yet.
expect(getCfg().getPluginIdList()).toEqual([]);
expect(getPkgJson('cordova')).toBeUndefined();
expect(getPkgJson('cordova.plugins')).toBeUndefined();

// Add the plugin with --save.
return cordova.plugin('add', `${pluginId}@1.1.2`, { save: true })
Expand Down Expand Up @@ -211,6 +220,7 @@ describe('pkgJson', function () {
[pluginId]: {}, [OTHER_PLUGIN]: {}
});
expect(getPkgJson('dependencies')).toEqual({
'cordova-android': jasmine.any(String),
[pluginId]: jasmine.any(String),
[OTHER_PLUGIN]: jasmine.any(String)
});
Expand All @@ -220,7 +230,9 @@ describe('pkgJson', function () {
}).then(function () {
// Checking that the plugin removed is in not in the platforms.
expect(getPkgJson('cordova.plugins')).toEqual({});
expect(getPkgJson('dependencies')).toEqual({});
expect(getPkgJson('dependencies')).toEqual({
'cordova-android': jasmine.any(String)
});
});
});

Expand All @@ -231,16 +243,16 @@ describe('pkgJson', function () {
const PLUGIN = 'cordova-plugin-geolocation';

// Pkg.json has no platform or plugin or specs.
expect(getPkgJson('cordova')).toBeUndefined();
expect(getPkgJson('dependencies')).toBeUndefined();
expect(getPkgJson('cordova.platforms')).not.toContain(PLATFORM);
expect(getPkgJson(`dependencies.${PLUGIN}`)).toBeUndefined();

// Config.xml has no platform or plugin or specs.
expect(getCfg().getEngines()).toEqual([]);
expect(getCfg().getEngines()).not.toContain(PLATFORM);
expect(getCfg().getPluginIdList()).toEqual([]);

return cordova.platform('add', PLATFORM, { save: true })
.then(function () {
expect(getPkgJson('cordova.platforms')).toEqual([PLATFORM]);
expect(getPkgJson('cordova.platforms')).toContain(PLATFORM);
}).then(function () {
return cordova.plugin('add', PLUGIN, { save: true });
}).then(function () {
Expand All @@ -254,27 +266,13 @@ describe('pkgJson', function () {
});

// Test#025: has a pkg.json. Checks if local path is added to pkg.json for platform and plugin add.
it('Test#025 : if you add a platform/plugin with local path, pkg.json gets updated', function () {
// TEMPORARY WORKAROUND due to failure on AppVeyor CI on Node.js 10
// as reported in:
// https://github.com/apache/cordova-lib/issues/787
if (process.platform === 'win32') pending('skip on Windows host');

const PLATFORM = 'browser';
it('Test#025 : if you add a plugin with local path, pkg.json gets updated', () => {
const PLUGIN = 'cordova-lib-test-plugin';

const platformPath = copyFixture(`platforms/cordova-${PLATFORM}`);
const pluginPath = copyFixture(path.join('plugins', PLUGIN));

return cordova.platform('add', platformPath, { save: true })
.then(function () {
// Pkg.json has platform
expect(getPkgJson('cordova.platforms')).toEqual([PLATFORM]);
expect(getPkgJson(`dependencies.cordova-${PLATFORM}`)).toBeDefined();
}).then(function () {
// Run cordova plugin add local path --save --fetch.
return cordova.plugin('add', pluginPath, { save: true });
}).then(function () {
// Run cordova plugin add local path --save
return cordova.plugin('add', pluginPath, { save: true })
.then(() => {
// Pkg.json has test plugin.
expect(getPkgJson(`cordova.plugins.${PLUGIN}`)).toBeDefined();
expect(getPkgJson(`dependencies.${PLUGIN}`)).toBeDefined();
Expand Down Expand Up @@ -381,6 +379,24 @@ describe('pkgJson', function () {
expect(installedPlatforms()).toEqual([]);
});
});

it('Test#012 : platform with local path is added correctly with --save', () => {
const PLATFORM = 'android';
const platformPath = path.join(tmpDir, PLATFORM);

expect(getPkgJson('cordova')).toBeUndefined();
expect(installedPlatforms()).toEqual([]);

return getFixture('androidPlatform').copyTo(platformPath)
.then(() => {
return cordova.platform('add', platformPath, { save: true });
})
.then(() => {
expect(installedPlatforms()).toEqual([PLATFORM]);
expect(getPkgJson('cordova.platforms')).toEqual([PLATFORM]);
expect(getPkgJson(`dependencies.cordova-${PLATFORM}`)).toBeDefined();
});
});
});

// Test #020 : pkg.json contains platform/spec and plugin/spec and config.xml does not
Expand Down
25 changes: 18 additions & 7 deletions integration-tests/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var plugin_util = require('../src/cordova/plugin/util');
var util = require('../src/cordova/util');

var tmpDir = helpers.tmpDir('plugin_test');
var preparedProject = path.join(tmpDir, 'prepared-project');
var project = path.join(tmpDir, 'project');
var fixturesDir = path.join(__dirname, '..', 'spec', 'cordova', 'fixtures');
var pluginsDir = path.join(fixturesDir, 'plugins');
Expand Down Expand Up @@ -102,13 +103,13 @@ function mockPluginFetch (id, dir) {
describe('plugin end-to-end', function () {
events.on('results', function (res) { results = res; });

beforeEach(function () {
fs.copySync(path.join(fixturesDir, 'base'), project);
beforeAll(() => {
return helpers.getFixture('projectWithPlatform').copyTo(preparedProject);
}, 20000);

// Copy some platform to avoid working on a project with no platforms.
fs.copySync(
path.join(__dirname, '../spec/plugman/projects', helpers.testPlatform),
path.join(project, 'platforms', helpers.testPlatform));
beforeEach(function () {
// Reset our test project and change into it
fs.copySync(preparedProject, project);
process.chdir(project);

// Reset origCwd before each spec to respect chdirs
Expand All @@ -122,7 +123,7 @@ describe('plugin end-to-end', function () {

afterEach(function () {
process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
fs.removeSync(tmpDir);
fs.removeSync(project);
expect(errorHandler.errorCallback).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -212,6 +213,16 @@ describe('plugin end-to-end', function () {
mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin));

spyOn(plugin_util, 'info').and.callThrough();

// Pretend to have cordova-android 5.2.2 installed to force the
// expected version outcome for the plugin below
fs.writeFileSync(
path.join(project, 'platforms/android/cordova/version'),
`#!/usr/bin/env node
exports.version = '5.2.2';
if (!module.parent) console.log(exports.version);`
);

return addPlugin(npmInfoTestPlugin, npmInfoTestPlugin)
.then(function () {
expect(plugin_util.info).toHaveBeenCalled();
Expand Down
22 changes: 10 additions & 12 deletions integration-tests/plugman_uninstall.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ const { PluginInfo, events } = require('cordova-common');
const common = require('../spec/common');
const install = require('../src/plugman/install');
const platforms = require('../src/platforms/platforms');
const { tmpDir: getTmpDir } = require('../spec/helpers.js');

const spec = path.join(__dirname, '..', 'spec', 'plugman');
const srcProject = path.join(spec, 'projects', 'android');
const { tmpDir: getTmpDir, getFixture } = require('../spec/helpers.js');

const tmpDir = getTmpDir('plugman_uninstall_test');
const projectsPath = path.join(tmpDir, 'projects');
const project = path.join(tmpDir, 'project');
const plugins_install_dir = path.join(project, 'cordova/plugins');

const plugins_dir = path.join(spec, 'plugins');
const plugins_dir = path.join(__dirname, '../spec/plugman/plugins');
const plugins = {
'org.test.plugins.dummyplugin': path.join(plugins_dir, 'org.test.plugins.dummyplugin'),
'A': path.join(plugins_dir, 'dependencies', 'A'),
Expand All @@ -55,12 +52,13 @@ describe('plugman/uninstall', () => {
const project2 = path.join(projectsPath, 'uninstall.test2');
const project3 = path.join(projectsPath, 'uninstall.test3');

for (const p of [project1, project2, project3]) {
fs.copySync(srcProject, p);
}

return install('android', project1, plugins['org.test.plugins.dummyplugin'])
.then(function (result) {
return Promise.resolve()
.then(_ => getFixture('androidApp').copyTo(project1))
.then(_ => getFixture('androidApp').copyTo(project2))
.then(_ => getFixture('androidApp').copyTo(project3))
.then(function () {
return install('android', project1, plugins['org.test.plugins.dummyplugin']);
}).then(function () {
return install('android', project1, plugins['A']);
}).then(function () {
return install('android', project2, plugins['C']);
Expand All @@ -73,7 +71,7 @@ describe('plugman/uninstall', () => {
}).then(function (result) {
expect(result).toEqual(true);
});
});
}, 20000);

beforeEach(() => {
uninstall = rewire('../src/plugman/uninstall');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"devDependencies": {
"codecov": "^3.2.0",
"cordova-android": "^8.1.0",
"delay": "^4.1.0",
"eslint": "^5.15.1",
"eslint-config-semistandard": "^13.0.0",
Expand All @@ -48,8 +49,7 @@
"jasmine": "^3.3.1",
"jasmine-spec-reporter": "^4.2.1",
"nyc": "^14.1.1",
"rewire": "^4.0.1",
"shelljs": "^0.8.3"
"rewire": "^4.0.1"
},
"scripts": {
"test": "npm run eslint && npm run unit-tests && npm run e2e-tests",
Expand Down
22 changes: 0 additions & 22 deletions spec/cordova/fixtures/base/.cordova/config.json

This file was deleted.

Empty file.
Empty file.
16 changes: 0 additions & 16 deletions spec/cordova/fixtures/base/www/config.xml

This file was deleted.

0 comments on commit 293b9c0

Please sign in to comment.