Skip to content

Commit

Permalink
breaking: replace shell.exec w/ superspawn in create.spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed May 20, 2020
1 parent a0dc993 commit a28bed7
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tests/spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,38 @@
under the License.
*/

const shell = require('shelljs');
const spec = __dirname;
const path = require('path');
const fs = require('fs-extra');
const util = require('util');
const { events } = require('cordova-common');
const { superspawn } = require('cordova-common');

const cordova_bin = path.join(spec, '../..', 'bin');
const tmp = require('tmp').dirSync().name;

function createAndBuild (projectname, projectid) {
let return_code = 0;
let command;

// remove existing folder
command = path.join(tmp, projectname);
fs.removeSync(command);

// create the project
command = util.format('"%s/create" "%s/%s" %s "%s"', cordova_bin, tmp, projectname, projectid, projectname);
events.emit('log', command);
return_code = shell.exec(command).code;
expect(return_code).toBe(0);

// build the project
command = util.format('"%s/cordova/build" --emulator', path.join(tmp, projectname));
events.emit('log', command);
return_code = shell.exec(command, { silent: true }).code;
expect(return_code).toBe(0);

// clean-up
command = path.join(tmp, projectname);
fs.removeSync(command);
const projectTempDir = path.join(`${tmp}/${projectname}`);
const createBin = path.join(`${cordova_bin}/create`);
const buildBin = path.join(`${projectTempDir}/cordova/build`);

// Remove any pre-existing temp projects
fs.removeSync(projectTempDir);

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

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);
});
}

describe('create', () => {
Expand Down

0 comments on commit a28bed7

Please sign in to comment.