Skip to content

Commit

Permalink
test(create): remove binary usage
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Nov 4, 2021
1 parent a6044dd commit 728558b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 132 deletions.
74 changes: 0 additions & 74 deletions bin/create

This file was deleted.

26 changes: 0 additions & 26 deletions bin/create.bat

This file was deleted.

78 changes: 46 additions & 32 deletions tests/spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,66 @@
under the License.
*/

const spec = __dirname;
const path = require('path');
const fs = require('fs-extra');
const { superspawn } = require('cordova-common');
const os = require('os');
const rewire = require('rewire');
const create = rewire('../../bin/lib/create');
const xcode = require('xcode');

const cordova_bin = path.join(spec, '../..', 'bin');
const tmp = require('tmp').dirSync().name;
function makeTempDir () {
return path.join(os.tmpdir(), 'cordova-ios-create-test');
}

function createAndBuild (projectname, projectid) {
const projectTempDir = path.join(`${tmp}/${projectname}`);
const createBin = path.join(`${cordova_bin}/create`);
const buildBin = path.join(`${projectTempDir}/cordova/build`);
function verifySomeFiles (tmpDir, projectName) {
[
projectName,
`${projectName}.xcodeproj`,
`${projectName}.xcworkspace`,
'CordovaLib'
].forEach(i => {
expect(fs.existsSync(path.join(tmpDir, projectName))).toBe(true);
});
}

// Remove any pre-existing temp projects
fs.removeSync(projectTempDir);
function verifyProjectBundleIdentifier (tmpDir, projectName, expectedBundleIdentifier) {
const pbxproj = path.join(tmpDir, `${projectName}.xcodeproj/project.pbxproj`);

return superspawn.spawn(createBin, [projectTempDir, projectid, projectname], { printCommand: true }).then(
() => {
expect(true).toBe(true); // It is expected that create is successful
const xcodeproj = xcode.project(pbxproj);
xcodeproj.parseSync();

return superspawn.spawn(buildBin, ['--emulator'], { printCommand: true }).then(
() => {
expect(true).toBe(true); // It is expected that build is successful
},
() => fail('Project Build has failed and is not expected.')
);
},
() => fail('Project create has failed and is not expected.')
).finally(() => {
// Delete Temp Project
fs.removeSync(projectTempDir);
});
const actualBundleIdentifier = xcodeproj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER');
expect(actualBundleIdentifier).toBe(`"${expectedBundleIdentifier}"`);
}

describe('create', () => {
fdescribe('create', () => {
let tmpDir;

beforeEach(function () {
tmpDir = makeTempDir();
});

afterEach(() => {
fs.removeSync(tmpDir);
});

it('Test#001 : create project with ascii name, no spaces', () => {
const projectname = 'testcreate';
const projectid = 'com.test.app1';
const packageName = 'com.test.app1';
const projectName = 'testcreate';

return createAndBuild(projectname, projectid);
return create.createProject(tmpDir, packageName, projectName, {}, undefined).then(() => {
verifySomeFiles(tmpDir, projectName);
verifyProjectBundleIdentifier(tmpDir, projectName, packageName);
});
}, 240 * 1000); // first build takes longer (probably cold caches)

it('Test#002 : create project with complicated name', () => {
const projectname = '応応応応 hello & إثرا 用用用用';
const projectid = 'com.test.app2';
const packageName = 'com.test.app2';
const projectName = '応応応応 hello & إثرا 用用用用';

return createAndBuild(projectname, projectid);
return create.createProject(tmpDir, packageName, projectName, {}, undefined).then(() => {
verifySomeFiles(tmpDir, projectName);
verifyProjectBundleIdentifier(tmpDir, projectName, packageName);
});
}, 120 * 1000);
});

0 comments on commit 728558b

Please sign in to comment.