mirror of
https://github.com/apache/cordova-android.git
synced 2026-01-30 00:05:28 +08:00
refactor: replace fs-extra with node:fs (#1772)
* spec: add devDependencies "tmp"
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
const os = require('node:os');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { EventEmitter } = require('events');
|
||||
const { ConfigParser, PluginInfoProvider } = require('cordova-common');
|
||||
@@ -49,14 +49,15 @@ describe('E2E', function () {
|
||||
api = await makeProject(projectPath);
|
||||
});
|
||||
afterEach(() => {
|
||||
fs.removeSync(tmpDir);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('loads the API from a project directory', async () => {
|
||||
// Allow test project to find the `cordova-android` module
|
||||
fs.ensureSymlinkSync(
|
||||
path.join(__dirname, '../..'),
|
||||
path.join(tmpDir, 'node_modules/cordova-android'),
|
||||
fs.mkdirSync(path.join(tmpDir, 'node_modules'), { recursive: true });
|
||||
fs.symlinkSync(
|
||||
path.join(__dirname, '..', '..'),
|
||||
path.join(tmpDir, 'node_modules', 'cordova-android'),
|
||||
'junction'
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const rewire = require('rewire');
|
||||
const { isWindows } = require('../../../lib/utils');
|
||||
@@ -220,7 +220,7 @@ describe('ProjectBuilder', () => {
|
||||
beforeEach(() => {
|
||||
const marker = ProjectBuilder.__get__('MARKER');
|
||||
spyOn(fs, 'readFileSync').and.returnValue(`Some Header Here: ${marker}`);
|
||||
spyOn(fs, 'removeSync');
|
||||
spyOn(fs, 'rmSync');
|
||||
spyOn(builder, 'getArgs');
|
||||
execaSpy.and.returnValue(Promise.resolve());
|
||||
});
|
||||
@@ -250,7 +250,7 @@ describe('ProjectBuilder', () => {
|
||||
|
||||
it('should remove "out" folder', () => {
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(path.join(rootDir, 'out'));
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(path.join(rootDir, 'out'), { recursive: true, force: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -261,8 +261,8 @@ describe('ProjectBuilder', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.removeSync).toHaveBeenCalledWith(releaseSigningFile);
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.rmSync).toHaveBeenCalledWith(releaseSigningFile);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -273,8 +273,8 @@ describe('ProjectBuilder', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(false);
|
||||
|
||||
return builder.clean({}).then(() => {
|
||||
expect(fs.removeSync).not.toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.removeSync).not.toHaveBeenCalledWith(releaseSigningFile);
|
||||
expect(fs.rmSync).not.toHaveBeenCalledWith(debugSigningFile);
|
||||
expect(fs.rmSync).not.toHaveBeenCalledWith(releaseSigningFile);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
const rewire = require('rewire');
|
||||
const android_sdk = require('../../lib/android_sdk');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const events = require('cordova-common').events;
|
||||
const which = require('which');
|
||||
|
||||
@@ -21,7 +21,7 @@ const rewire = require('rewire');
|
||||
const utils = require('../../lib/utils');
|
||||
const create = rewire('../../lib/create');
|
||||
const check_reqs = require('../../lib/check_reqs');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
|
||||
const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
|
||||
@@ -142,8 +142,8 @@ describe('create', function () {
|
||||
spyOn(create, 'prepBuildFiles');
|
||||
revert_manifest_mock = create.__set__('AndroidManifest', Manifest_mock);
|
||||
spyOn(fs, 'existsSync').and.returnValue(false);
|
||||
spyOn(fs, 'copySync');
|
||||
spyOn(fs, 'ensureDirSync');
|
||||
spyOn(fs, 'cpSync');
|
||||
spyOn(fs, 'mkdirSync');
|
||||
spyOn(utils, 'replaceFileContents');
|
||||
config_mock = jasmine.createSpyObj('ConfigParser mock instance', ['packageName', 'android_packageName', 'name', 'android_activityName']);
|
||||
events_mock = jasmine.createSpyObj('EventEmitter mock instance', ['emit']);
|
||||
@@ -238,17 +238,17 @@ describe('create', function () {
|
||||
describe('happy path', function () {
|
||||
it('should copy project templates from a specified custom template', () => {
|
||||
return create.create(project_path, config_mock, { customTemplate: '/template/path' }, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'assets'), path.join(app_path, 'assets'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'res'), path.join(app_path, 'res'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join('/template/path', 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'assets'), path.join(app_path, 'assets'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'res'), path.join(app_path, 'res'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join('/template/path', 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
});
|
||||
});
|
||||
|
||||
it('should copy project templates from the default templates location if no custom template is provided', () => {
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'assets'), path.join(app_path, 'assets'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'res'), path.join(app_path, 'res'));
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'assets'), path.join(app_path, 'assets'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'res'), path.join(app_path, 'res'), { recursive: true });
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -261,7 +261,7 @@ describe('create', function () {
|
||||
it('should create a java src directory based on the provided project package name', () => {
|
||||
config_mock.packageName.and.returnValue('org.apache.cordova');
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.ensureDirSync).toHaveBeenCalledWith(path.join(app_path, 'java', 'org', 'apache', 'cordova'));
|
||||
expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(app_path, 'java', 'org', 'apache', 'cordova'), { recursive: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -270,7 +270,7 @@ describe('create', function () {
|
||||
config_mock.android_activityName.and.returnValue('CEEDEEVEE');
|
||||
const activity_path = path.join(app_path, 'java', 'org', 'apache', 'cordova', 'CEEDEEVEE.java');
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(fs.copySync).toHaveBeenCalledWith(path.join(default_templates, 'Activity.java'), activity_path);
|
||||
expect(fs.cpSync).toHaveBeenCalledWith(path.join(default_templates, 'Activity.java'), activity_path);
|
||||
expect(utils.replaceFileContents).toHaveBeenCalledWith(activity_path, /__ACTIVITY__/, 'CEEDEEVEE');
|
||||
expect(utils.replaceFileContents).toHaveBeenCalledWith(activity_path, /__ID__/, 'org.apache.cordova');
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const rewire = require('rewire');
|
||||
const which = require('which');
|
||||
|
||||
@@ -19,26 +19,40 @@
|
||||
const rewire = require('rewire');
|
||||
const common = rewire('../../../lib/pluginHandlers');
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const osenv = require('node:os');
|
||||
const fs = require('node:fs');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const test_dir = path.join(osenv.tmpdir(), 'test_plugman');
|
||||
tmp.setGracefulCleanup();
|
||||
|
||||
const tempdir = tmp.dirSync({ unsafeCleanup: true });
|
||||
const test_dir = path.join(tempdir.name, 'test_plugman');
|
||||
const project_dir = path.join(test_dir, 'project');
|
||||
const src = path.join(project_dir, 'src');
|
||||
const dest = path.join(project_dir, 'dest');
|
||||
const java_dir = path.join(src, 'one', 'two', 'three');
|
||||
const java_file = path.join(java_dir, 'test.java');
|
||||
const symlink_file = path.join(java_dir, 'symlink');
|
||||
const non_plugin_file = path.join(osenv.tmpdir(), 'non_plugin_file');
|
||||
const non_plugin_file = path.join(tempdir.name, 'non_plugin_file');
|
||||
|
||||
const copyFile = common.__get__('copyFile');
|
||||
const deleteJava = common.__get__('deleteJava');
|
||||
const copyNewFile = common.__get__('copyNewFile');
|
||||
|
||||
function outputFileSync (file, content) {
|
||||
const dir = path.dirname(file);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(file, content, 'utf-8');
|
||||
}
|
||||
|
||||
describe('common platform handler', function () {
|
||||
afterAll(() => {
|
||||
// Remove tempdir after all specs complete
|
||||
fs.rmSync(tempdir.name, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.removeSync(test_dir);
|
||||
fs.removeSync(non_plugin_file);
|
||||
fs.rmSync(test_dir, { recursive: true, force: true });
|
||||
fs.rmSync(non_plugin_file, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('copyFile', function () {
|
||||
@@ -48,15 +62,15 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#002 : should throw if src not in plugin directory', function () {
|
||||
fs.ensureDirSync(project_dir);
|
||||
fs.outputFileSync(non_plugin_file, 'contents');
|
||||
fs.mkdirSync(project_dir, { recursive: true });
|
||||
outputFileSync(non_plugin_file, 'contents');
|
||||
const outside_file = '../non_plugin_file';
|
||||
expect(function () { copyFile(test_dir, outside_file, project_dir, dest); })
|
||||
.toThrow(new Error('File "' + path.resolve(test_dir, outside_file) + '" is located outside the plugin directory "' + test_dir + '"'));
|
||||
});
|
||||
|
||||
it('Test#003 : should allow symlink src, if inside plugin', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
// This will fail on windows if not admin - ignore the error in that case.
|
||||
if (ignoreEPERMonWin32(java_file, symlink_file)) {
|
||||
@@ -67,8 +81,8 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#004 : should throw if symlink is linked to a file outside the plugin', function () {
|
||||
fs.ensureDirSync(java_dir);
|
||||
fs.outputFileSync(non_plugin_file, 'contents');
|
||||
fs.mkdirSync(java_dir, { recursive: true });
|
||||
outputFileSync(non_plugin_file, 'contents');
|
||||
|
||||
// This will fail on windows if not admin - ignore the error in that case.
|
||||
if (ignoreEPERMonWin32(non_plugin_file, symlink_file)) {
|
||||
@@ -80,37 +94,37 @@ describe('common platform handler', function () {
|
||||
});
|
||||
|
||||
it('Test#005 : should throw if dest is outside the project directory', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
expect(function () { copyFile(test_dir, java_file, project_dir, non_plugin_file); })
|
||||
.toThrow(new Error('Destination "' + path.resolve(project_dir, non_plugin_file) + '" for source file "' + path.resolve(test_dir, java_file) + '" is located outside the project'));
|
||||
});
|
||||
|
||||
it('Test#006 : should call mkdir -p on target path', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
it('Test#006 : should call mkdirSync target path', function () {
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
const s = spyOn(fs, 'ensureDirSync').and.callThrough();
|
||||
const s = spyOn(fs, 'mkdirSync').and.callThrough();
|
||||
const resolvedDest = path.resolve(project_dir, dest);
|
||||
|
||||
copyFile(test_dir, java_file, project_dir, dest);
|
||||
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(path.dirname(resolvedDest));
|
||||
expect(s).toHaveBeenCalledWith(path.dirname(resolvedDest), { recursive: true });
|
||||
});
|
||||
|
||||
it('Test#007 : should call cp source/dest paths', function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
|
||||
const s = spyOn(fs, 'copySync').and.callThrough();
|
||||
const s = spyOn(fs, 'cpSync').and.callThrough();
|
||||
const resolvedDest = path.resolve(project_dir, dest);
|
||||
|
||||
copyFile(test_dir, java_file, project_dir, dest);
|
||||
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(java_file, resolvedDest);
|
||||
expect(s).toHaveBeenCalledWith(java_file, resolvedDest, { recursive: true });
|
||||
});
|
||||
|
||||
it('should handle relative paths when checking for sub paths', () => {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
const relativeProjectPath = path.relative(process.cwd(), project_dir);
|
||||
|
||||
expect(() => {
|
||||
@@ -121,7 +135,7 @@ describe('common platform handler', function () {
|
||||
|
||||
describe('copyNewFile', function () {
|
||||
it('Test#008 : should throw if target path exists', function () {
|
||||
fs.ensureDirSync(dest);
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
expect(function () { copyNewFile(test_dir, src, project_dir, dest); })
|
||||
.toThrow(new Error('"' + dest + '" already exists!'));
|
||||
});
|
||||
@@ -129,11 +143,11 @@ describe('common platform handler', function () {
|
||||
|
||||
describe('deleteJava', function () {
|
||||
beforeEach(function () {
|
||||
fs.outputFileSync(java_file, 'contents');
|
||||
outputFileSync(java_file, 'contents');
|
||||
});
|
||||
|
||||
it('Test#009 : should call fs.unlinkSync on the provided paths', function () {
|
||||
const s = spyOn(fs, 'removeSync').and.callThrough();
|
||||
const s = spyOn(fs, 'rmSync').and.callThrough();
|
||||
deleteJava(project_dir, java_file);
|
||||
expect(s).toHaveBeenCalled();
|
||||
expect(s).toHaveBeenCalledWith(path.resolve(project_dir, java_file));
|
||||
|
||||
@@ -21,7 +21,7 @@ const rewire = require('rewire');
|
||||
const common = rewire('../../../lib/pluginHandlers');
|
||||
const android = common.__get__('handlers');
|
||||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const temp = path.join(os.tmpdir(), 'plugman');
|
||||
const plugins_dir = path.join(temp, 'cordova/plugins');
|
||||
@@ -56,14 +56,14 @@ describe('android project handler', function () {
|
||||
let dummyProject;
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(temp);
|
||||
fs.mkdirSync(temp, { recursive: true });
|
||||
dummyProject = AndroidProject.getProjectFile(temp);
|
||||
copyFileSpy.calls.reset();
|
||||
common.__set__('copyFile', copyFileSpy);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
fs.removeSync(temp);
|
||||
fs.rmSync(temp, { recursive: true, force: true });
|
||||
common.__set__('copyFile', copyFileOrig);
|
||||
});
|
||||
|
||||
@@ -83,7 +83,7 @@ describe('android project handler', function () {
|
||||
|
||||
describe('of <source-file> elements', function () {
|
||||
beforeEach(function () {
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
});
|
||||
|
||||
it('Test#003 : should copy stuff from one location to another by calling common.copyFile', function () {
|
||||
@@ -102,7 +102,7 @@ describe('android project handler', function () {
|
||||
it('Test#006 : should throw if target file already exists', function () {
|
||||
// write out a file
|
||||
let target = path.resolve(temp, 'app', 'src', 'main', 'java', 'com', 'phonegap', 'plugins', 'dummyplugin');
|
||||
fs.ensureDirSync(target);
|
||||
fs.mkdirSync(target, { recursive: true });
|
||||
target = path.join(target, 'DummyPlugin.java');
|
||||
fs.writeFileSync(target, 'some bs', 'utf-8');
|
||||
|
||||
@@ -192,7 +192,7 @@ describe('android project handler', function () {
|
||||
const copyNewFileSpy = jasmine.createSpy('copyNewFile');
|
||||
|
||||
beforeEach(function () {
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
|
||||
spyOn(dummyProject, 'addSystemLibrary');
|
||||
spyOn(dummyProject, 'addSubProject');
|
||||
@@ -222,7 +222,7 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#010 : should not copy anything if "custom" attribute is not set', function () {
|
||||
const framework = { src: 'plugin-lib' };
|
||||
const cpSpy = spyOn(fs, 'copySync');
|
||||
const cpSpy = spyOn(fs, 'cpSync');
|
||||
android.framework.install(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.addSystemLibrary).toHaveBeenCalledWith(someString, framework.src);
|
||||
expect(cpSpy).not.toHaveBeenCalled();
|
||||
@@ -289,23 +289,23 @@ describe('android project handler', function () {
|
||||
|
||||
describe('uninstallation', function () {
|
||||
const deleteJavaOrig = common.__get__('deleteJava');
|
||||
const originalRemoveSync = fs.removeSync;
|
||||
const originalRmSync = fs.rmSync;
|
||||
const deleteJavaSpy = jasmine.createSpy('deleteJava');
|
||||
let dummyProject;
|
||||
let removeSyncSpy;
|
||||
let rmSyncSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(temp);
|
||||
fs.ensureDirSync(plugins_dir);
|
||||
fs.copySync(android_studio_project, temp);
|
||||
fs.mkdirSync(temp, { recursive: true });
|
||||
fs.mkdirSync(plugins_dir, { recursive: true });
|
||||
fs.cpSync(android_studio_project, temp, { recursive: true });
|
||||
AndroidProject.purgeCache();
|
||||
dummyProject = AndroidProject.getProjectFile(temp);
|
||||
removeSyncSpy = spyOn(fs, 'removeSync');
|
||||
rmSyncSpy = spyOn(fs, 'rmSync');
|
||||
common.__set__('deleteJava', deleteJavaSpy);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
originalRemoveSync.call(fs, temp);
|
||||
originalRmSync.call(fs, temp, { recursive: true });
|
||||
common.__set__('deleteJava', deleteJavaOrig);
|
||||
});
|
||||
|
||||
@@ -313,7 +313,7 @@ describe('android project handler', function () {
|
||||
it('Test#017 : should remove jar files for Android Studio projects', function () {
|
||||
android['lib-file'].install(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
android['lib-file'].uninstall(valid_libs[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -321,7 +321,7 @@ describe('android project handler', function () {
|
||||
it('Test#018 : should remove files for Android Studio projects', function () {
|
||||
android['resource-file'].install(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
android['resource-file'].uninstall(valid_resources[0], dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app', 'src', 'main', 'res', 'xml', 'dummy.xml'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app', 'src', 'main', 'res', 'xml', 'dummy.xml'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -341,49 +341,49 @@ describe('android project handler', function () {
|
||||
it('Test#019b : should remove stuff by calling common.removeFile for Android Studio projects, of jar with new app target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[2], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestLib.jar'));
|
||||
});
|
||||
|
||||
it('Test#019c : should remove stuff by calling common.removeFile for Android Studio projects, of aar with new app target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[3], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestAar.aar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/TestAar.aar'));
|
||||
});
|
||||
|
||||
it('Test#019d : should remove stuff by calling common.removeFile for Android Studio projects, of xml with old target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[4], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[4], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/xml/mysettings.xml'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/xml/mysettings.xml'));
|
||||
});
|
||||
|
||||
it('Test#019e : should remove stuff by calling common.removeFile for Android Studio projects, of file with other extension with old target-dir scheme', function () {
|
||||
android['source-file'].install(valid_source[5], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[5], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/values/other.extension'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/res/values/other.extension'));
|
||||
});
|
||||
|
||||
it('Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[6], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/aidl/com/mytest/myapi.aidl'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/aidl/com/mytest/myapi.aidl'));
|
||||
});
|
||||
|
||||
it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[7], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testaar2.aar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testaar2.aar'));
|
||||
});
|
||||
|
||||
it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[8], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testjar2.jar'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/libs/testjar2.jar'));
|
||||
});
|
||||
|
||||
it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme (GH-547)', function () {
|
||||
android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
android['source-file'].uninstall(valid_source[9], dummyPluginInfo, dummyProject, { android_studio: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/jniLibs/x86/libnative.so'));
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(path.join(dummyProject.projectDir, 'app/src/main/jniLibs/x86/libnative.so'));
|
||||
});
|
||||
|
||||
it('Test#019j : should remove stuff by calling common.deleteJava for Android Studio projects, with target-dir that includes "app"', function () {
|
||||
@@ -397,7 +397,7 @@ describe('android project handler', function () {
|
||||
const someString = jasmine.any(String);
|
||||
|
||||
beforeEach(function () {
|
||||
fs.ensureDirSync(path.join(dummyProject.projectDir, dummyPluginInfo.id));
|
||||
fs.mkdirSync(path.join(dummyProject.projectDir, dummyPluginInfo.id), { recursive: true });
|
||||
|
||||
spyOn(dummyProject, 'removeSystemLibrary');
|
||||
spyOn(dummyProject, 'removeSubProject');
|
||||
@@ -424,13 +424,13 @@ describe('android project handler', function () {
|
||||
const framework = { src: 'plugin-lib', custom: true };
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(dummyProject.removeSubProject).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(someString);
|
||||
});
|
||||
|
||||
it('Test#24 : should install gradleReference using project.removeGradleReference', function () {
|
||||
const framework = { src: 'plugin-lib', custom: true, type: 'gradleReference' };
|
||||
android.framework.uninstall(framework, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(someString);
|
||||
expect(dummyProject.removeGradleReference).toHaveBeenCalledWith(dummyProject.projectDir, someString);
|
||||
});
|
||||
});
|
||||
@@ -453,14 +453,14 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#025 : should put module to both www and platform_www when options.usePlatformWww flag is specified', function () {
|
||||
android['js-module'].uninstall(jsModule, dummyPluginInfo, dummyProject, { usePlatformWww: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
|
||||
it('Test#026 : should put module to www only when options.usePlatformWww flag is not specified', function () {
|
||||
android['js-module'].uninstall(jsModule, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -481,14 +481,14 @@ describe('android project handler', function () {
|
||||
|
||||
it('Test#027 : should put module to both www and platform_www when options.usePlatformWww flag is specified', function () {
|
||||
android.asset.uninstall(asset, dummyPluginInfo, dummyProject, { usePlatformWww: true });
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
|
||||
it('Test#028 : should put module to www only when options.usePlatformWww flag is not specified', function () {
|
||||
android.asset.uninstall(asset, dummyPluginInfo, dummyProject);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(removeSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(wwwDest);
|
||||
expect(rmSyncSpy).not.toHaveBeenCalledWith(platformWwwDest);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -899,9 +899,9 @@ describe('prepare', () => {
|
||||
|
||||
// Spies
|
||||
let replaceFileContents;
|
||||
let ensureDirSyncSpy;
|
||||
let copySyncSpy;
|
||||
let removeSyncSpy;
|
||||
let mkdirSyncSpy;
|
||||
let cpSyncSpy;
|
||||
let rmSyncSpy;
|
||||
|
||||
// Mock Data
|
||||
let cordovaProject;
|
||||
@@ -1001,16 +1001,15 @@ describe('prepare', () => {
|
||||
`))
|
||||
});
|
||||
|
||||
ensureDirSyncSpy = jasmine.createSpy('ensureDirSync');
|
||||
copySyncSpy = jasmine.createSpy('copySync');
|
||||
removeSyncSpy = jasmine.createSpy('removeSync');
|
||||
mkdirSyncSpy = jasmine.createSpy('mkdirSync');
|
||||
cpSyncSpy = jasmine.createSpy('cpSync');
|
||||
rmSyncSpy = jasmine.createSpy('rmSync');
|
||||
|
||||
prepare.__set__('fs', {
|
||||
writeFileSync: jasmine.createSpy('writeFileSync'),
|
||||
writeJSONSync: jasmine.createSpy('writeJSONSync'),
|
||||
ensureDirSync: ensureDirSyncSpy,
|
||||
copySync: copySyncSpy,
|
||||
removeSync: removeSyncSpy,
|
||||
mkdirSync: mkdirSyncSpy,
|
||||
cpSync: cpSyncSpy,
|
||||
rmSync: rmSyncSpy,
|
||||
existsSync: jasmine.createSpy('existsSync')
|
||||
});
|
||||
});
|
||||
@@ -1022,9 +1021,9 @@ describe('prepare', () => {
|
||||
|
||||
await api.prepare(cordovaProject, options).then(() => {
|
||||
expect(replaceFileContents).toHaveBeenCalledWith(renamedJavaActivityPath, /package [\w.]*;/, 'package ' + packageName + ';');
|
||||
expect(ensureDirSyncSpy).toHaveBeenCalledWith(renamedPath);
|
||||
expect(copySyncSpy).toHaveBeenCalledWith(initialJavaActivityPath, renamedJavaActivityPath);
|
||||
expect(removeSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledWith(renamedPath, { recursive: true });
|
||||
expect(cpSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath, renamedJavaActivityPath);
|
||||
expect(rmSyncSpy).toHaveBeenCalledWith(initialJavaActivityPath);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1033,9 +1032,9 @@ describe('prepare', () => {
|
||||
|
||||
await api.prepare(cordovaProject, options).then(() => {
|
||||
expect(replaceFileContents).toHaveBeenCalledTimes(0);
|
||||
expect(ensureDirSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(copySyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(removeSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(cpSyncSpy).toHaveBeenCalledTimes(0);
|
||||
expect(rmSyncSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user