You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/07/18 07:58:26 UTC

[cordova-electron] branch master updated: refactor: improve create test spec speed (#86)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git


The following commit(s) were added to refs/heads/master by this push:
     new e451533  refactor: improve create test spec speed (#86)
e451533 is described below

commit e451533654931a1a56d52d46a20516793df30063
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Jul 18 16:58:22 2019 +0900

    refactor: improve create test spec speed (#86)
---
 tests/spec/unit/create.spec.js | 51 +++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/tests/spec/unit/create.spec.js b/tests/spec/unit/create.spec.js
index 1053044..85cd03d 100644
--- a/tests/spec/unit/create.spec.js
+++ b/tests/spec/unit/create.spec.js
@@ -28,7 +28,7 @@ const tmpDir = path.join(__dirname, '../../../temp');
 const createScriptPath = path.join(cordova_bin, 'create');
 const create = rewire(path.join(cordova_bin, 'lib', 'create'));
 
-function createAndBuild (projectname, projectid) {
+function createAndVerify (projectname, projectid) {
     let return_code = 0;
 
     // remove existing folder
@@ -53,61 +53,86 @@ function createAndBuild (projectname, projectid) {
     expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'run'))).toBe(true);
     expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'version'))).toBe(true);
 
-    // // build the project
-    command = util.format('"%s/cordova/build"', path.join(tmpDir, projectname));
-
-    return_code = shell.exec(command, { silent: true }).code;
-    expect(return_code).toBe(0);
-
     // clean-up
     fs.removeSync(tmpDir);
 }
 
+function createAndValidateProjectDirName (projectname, projectid) {
+    // remove existing folder
+    fs.removeSync(tmpDir);
+    fs.ensureDirSync(tmpDir);
+
+    const projectPath = path.join(tmpDir, projectname);
+
+    const _fs = create.__get__('fs');
+    create.__set__('fs', {
+        ensureDirSync: _fs.ensureDirSync,
+        existsSync: path => !(path === projectPath),
+        copySync: () => true
+    });
+
+    return create.createProject(projectPath, projectname, projectid, projectname)
+        .then(() => {
+            // expects the project name to be the directory name.
+            expect(_fs.readdirSync(tmpDir).includes(projectname)).toBe(true);
+
+            fs.removeSync(tmpDir);
+            create.__set__('fs', _fs);
+        });
+}
+
 describe('create', () => {
     it('has a create script in bin/cordova', () => {
         expect(fs.existsSync(createScriptPath)).toBe(true);
     });
 
+    it('create project and check for bin files', () => {
+        const projectname = 'testcreate';
+        const projectid = 'com.test.app1';
+
+        createAndVerify(projectname, projectid);
+    });
+
     it('create project with ascii name, no spaces', () => {
         const projectname = 'testcreate';
         const projectid = 'com.test.app1';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('create project with ascii name, and spaces', () => {
         const projectname = 'test create';
         const projectid = 'com.test.app2';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('create project with unicode name, no spaces', () => {
         const projectname = '応応応応用用用用';
         const projectid = 'com.test.app3';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('create project with unicode name, and spaces', () => {
         const projectname = '応応応応 用用用用';
         const projectid = 'com.test.app4';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('create project with ascii+unicode name, no spaces', () => {
         const projectname = '応応応応hello用用用用';
         const projectid = 'com.test.app5';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('create project with ascii+unicode name, and spaces', () => {
         const projectname = '応応応応 hello 用用用用';
         const projectid = 'com.test.app6';
 
-        createAndBuild(projectname, projectid);
+        return createAndValidateProjectDirName(projectname, projectid);
     });
 
     it('should stop creating project when project destination already exists', () => {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org