Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8e57f52
test(create): remove create & build binary usage
erisu Nov 4, 2021
e1959a4
refactor!: remove create binaries
erisu Nov 4, 2021
7c4fe54
refactor!: remove build binaries
erisu Nov 4, 2021
f70692b
refactor: update platform
erisu Nov 4, 2021
335605f
chore: cleanup update platform error message
erisu Nov 4, 2021
2246228
refactor!: remove update binaries
erisu Nov 4, 2021
76cea59
refactor!: remove check_reqs binaries & usage
erisu Nov 4, 2021
9ae23d1
refactor!: remove clean binaries
erisu Nov 4, 2021
3e5ac4f
refactor!: remove run binaries
erisu Nov 4, 2021
0d6ef4f
refactor!: remove test binaries
erisu Nov 4, 2021
53bfd82
refactor!: remove log binaries
erisu Nov 4, 2021
8d29122
refactor: cleanup version binaries
erisu Nov 4, 2021
f13996e
refactor!: remove uncrustify binary & config
erisu Nov 4, 2021
5e153ad
refactor!: remove binary help methods for build & run
erisu Nov 4, 2021
4d99320
refactor!: remove version.bat binary
erisu Nov 4, 2021
57dea23
fix: get realpathSync of os tmp dir
erisu Nov 5, 2021
381ed72
refactor: cleanup verify create & build methods
erisu Nov 5, 2021
0808169
refactor(create.spec): use expectAsync toBeResolved
erisu Nov 5, 2021
d0e7d59
refactor!: remove uncrustify pre-commit hook
erisu Nov 5, 2021
e7e1877
refactor!: remove list-emulator-build-targets binary
erisu Nov 5, 2021
e3f4d15
refactor!: remove list-started-emulators binary
erisu Nov 5, 2021
cfaf4ff
refactor!: remove start-emulator binary
erisu Nov 5, 2021
6e50686
chore: cleanup eslint ignore
erisu Nov 5, 2021
f732de5
refactor!: remove bat files
erisu Nov 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 80 additions & 34 deletions tests/spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,98 @@
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 path = require('path');
const xcode = require('xcode');
const create = require('../../bin/lib/create');

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

function createAndBuild (projectname, projectid) {
const projectTempDir = path.join(`${tmp}/${projectname}`);
const createBin = path.join(`${cordova_bin}/create`);
const buildBin = path.join(`${projectTempDir}/cordova/build`);
/**
* Verifies that some of the project file exists. Not all will be tested.
* E.g. App's resource directory, xcodeproj, xcworkspace, and CordovaLib.
*
* @param {String} tmpDir
* @param {String} projectName
*/
function verifyProjectFiles (tmpDir, projectName) {
expect(fs.existsSync(path.join(tmpDir, projectName))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, `${projectName}.xcodeproj`))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, `${projectName}.xcworkspace`))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, 'CordovaLib'))).toBe(true);
}

// Remove any pre-existing temp projects
fs.removeSync(projectTempDir);
/**
* Verifies that the set bundle id matches with the expected.
*
* @param {String} tmpDir
* @param {String} projectName
* @param {String} expectedBundleIdentifier
*/
function verifyProjectBundleIdentifier (tmpDir, projectName, expectedBundleIdentifier) {
const pbxproj = path.join(tmpDir, `${projectName}.xcodeproj/project.pbxproj`);
const xcodeproj = xcode.project(pbxproj);
xcodeproj.parseSync();
const actualBundleIdentifier = xcodeproj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER');
expect(actualBundleIdentifier).toBe(`"${expectedBundleIdentifier}"`);
}

return superspawn.spawn(createBin, [projectTempDir, projectid, projectname], { printCommand: true }).then(
() => {
expect(true).toBe(true); // It is expected that create is successful
/**
* Runs and expects for a successful build.
*
* @param {String} tmpDir
* @returns {Promise}
*/
function verifyBuild (tmpDir) {
const Api = require(path.join(tmpDir, 'cordova/Api.js'));

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);
});
return new Api()
.build({ emulator: true })
.then(
() => {
expect(true).toBe(true);
},
err => fail(`Project Build has failed and is not expected.: ${err}`)
);
}

/**
* Runs various create and buid checks.
*
* @param {String} tmpDir
* @param {String} packageName
* @param {String} projectName
* @returns
*/
function verifyCreateAndBuild (tmpDir, packageName, projectName) {
verifyProjectFiles(tmpDir, projectName);
verifyProjectBundleIdentifier(tmpDir, projectName, packageName);
return verifyBuild(tmpDir);
}

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

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

return createAndBuild(projectname, projectid);
afterEach(() => {
fs.removeSync(tmpDir);
});

it('Test#001 : create project with ascii name, no spaces', () => {
const packageName = 'com.test.app1';
const projectName = 'testcreate';
return create.createProject(tmpDir, packageName, projectName, {}, undefined)
.then(() => verifyCreateAndBuild(tmpDir, packageName, projectName));
}, 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';

return createAndBuild(projectname, projectid);
const packageName = 'com.test.app2';
const projectName = '応応応応 hello & إثرا 用用用用';
return create.createProject(tmpDir, packageName, projectName, {}, undefined)
.then(() => verifyCreateAndBuild(tmpDir, packageName, projectName));
}, 120 * 1000);
});