From a28bed7e29b0f14028faf04c45fb7e43ea982698 Mon Sep 17 00:00:00 2001 From: Erisu Date: Tue, 21 Apr 2020 15:47:14 +0900 Subject: [PATCH] breaking: replace shell.exec w/ superspawn in create.spec.js --- tests/spec/create.spec.js | 49 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/spec/create.spec.js b/tests/spec/create.spec.js index 7498695ed0..528733c4a1 100644 --- a/tests/spec/create.spec.js +++ b/tests/spec/create.spec.js @@ -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', () => {