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-create.git
The following commit(s) were added to refs/heads/master by this push:
new 3d21f05 Refactor tests (#16)
3d21f05 is described below
commit 3d21f05e4195e4b5363b419306e75f2268c362e6
Author: Raphael von der Grün <[email protected]>
AuthorDate: Sun Jun 17 14:28:38 2018 +0200
Refactor tests (#16)
* Factor out common checks
* Check more artifacts
* Simplify Checks
Co-authored-by: Christopher J. Brody <[email protected]>
Co-authored-by: Raphael von der Grün <[email protected]>
---
spec/create.spec.js | 139 ++++++++++-----------
spec/templates/config_in_www/www/config.xml | 2 +-
spec/templates/no_content_config.xml | 2 +-
spec/templates/nopackage_json/config.xml | 2 +-
spec/templates/withpackage_json/config.xml | 2 +-
.../templates/withsubdirectory/template/config.xml | 2 +-
.../template/config.xml | 2 +-
7 files changed, 69 insertions(+), 82 deletions(-)
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 68e924a..8ab5b41 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -29,9 +29,10 @@ var CordovaError = require('cordova-common').CordovaError;
var ConfigParser = require('cordova-common').ConfigParser;
const {tmpDir, createWith, createWithMockFetch, expectRejection} =
require('./helpers');
-var appName = 'TestBase';
-var appId = 'org.testing';
-var project = path.join(tmpDir, appName);
+const appName = 'TestBase';
+const appId = 'org.testing';
+const appVersion = '1.0.0';
+const project = path.join(tmpDir, appName);
// Setup and teardown test dirs
beforeEach(function () {
@@ -57,93 +58,82 @@ describe('cordova create checks for valid-identifier',
function () {
describe('create end-to-end', function () {
- function checkProject () {
- // Check if top level dirs exist.
+ function checkCommonArtifacts () {
+ // Check that top level dirs exist
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
dirs.forEach(function (d) {
expect(path.join(project, d)).toExist();
});
+ // Check that README.md exists inside of hooks
expect(path.join(project, 'hooks', 'README.md')).toExist();
- // Check if www files exist.
+ // Check that index.html exists inside of www
expect(path.join(project, 'www', 'index.html')).toExist();
- // Check that config.xml was updated.
- var configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.packageName()).toEqual(appId);
-
- // TODO (kamrik): check somehow that we got the right config.xml from
the fixture and not some place else.
- // expect(configXml.name()).toEqual('TestBase');
- }
-
- function checkConfigXml () {
- // Check if top level dirs exist.
- var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function (d) {
- expect(path.join(project, d)).toExist();
- });
- expect(path.join(project, 'hooks', 'README.md')).toExist();
+ // Check that www files don't get copied to the top level
+ expect(path.join(project, 'index.html')).not.toExist();
- // index.js and template subdir folder should not exist (inner files
should be copied to the project folder)
+ // index.js and template subdir folder should not exist in top level
+ // (inner files should be copied to the project top level folder)
expect(path.join(project, 'index.js')).not.toExist();
expect(path.join(project, 'template')).not.toExist();
- // Check if www files exist.
- expect(path.join(project, 'www', 'index.html')).toExist();
+ // Check that config.xml does not exist inside of www
+ expect(path.join(project, 'www', 'config.xml')).not.toExist();
+
+ // Check that config.xml was updated correctly
var configXml = new ConfigParser(path.join(project, 'config.xml'));
expect(configXml.packageName()).toEqual(appId);
- expect(configXml.version()).toEqual('1.0.0');
+ expect(configXml.name()).toEqual(appName);
+ expect(configXml.version()).toEqual(appVersion);
+ }
- // Check that config.xml does not exist inside of www
- expect(path.join(project, 'www', 'config.xml')).not.toExist();
+ // Check that we got package.json and it was updated correctly
+ function checkPackageJson () {
+ const pkg = requireFresh(path.join(project, 'package.json'));
+ expect(pkg.name).toEqual(appId);
+ expect(pkg.displayName).toEqual(appName);
+ expect(pkg.version).toEqual(appVersion);
+ }
- // Check that we got no package.json
+ // Check that we got no package.json
+ function checkNoPackageJson () {
expect(path.join(project, 'package.json')).not.toExist();
-
- // Check that we got the right config.xml from the template and not
stock
- expect(configXml.description()).toEqual('this is the correct
config.xml');
}
- function checkSubDir () {
- // Check if top level dirs exist.
- var dirs = ['hooks', 'platforms', 'plugins', 'www'];
- dirs.forEach(function (d) {
- expect(path.join(project, d)).toExist();
- });
- expect(path.join(project, 'hooks', 'README.md')).toExist();
+ // Check that we did use the default template
+ function checkDefaultTemplate () {
+ const pkg = requireFresh(path.join(project, 'package.json'));
+ expect(pkg.author).toEqual('Apache Cordova Team');
- // index.js and template subdir folder should not exist (inner files
should be copied to the project folder)
- expect(path.join(project, 'index.js')).not.toExist();
- expect(path.join(project, 'template')).not.toExist();
+ const configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.author()).toEqual('Apache Cordova Team');
+ }
- // Check if config files exist.
- expect(path.join(project, 'www', 'index.html')).toExist();
+ // Check that we did not use the default template
+ function checkNotDefaultTemplate () {
+ const configXml = new ConfigParser(path.join(project, 'config.xml'));
+ expect(configXml.author()).not.toEqual('Apache Cordova Team');
+ }
- // Check that config.xml was updated.
- var configXml = new ConfigParser(path.join(project, 'config.xml'));
- expect(configXml.packageName()).toEqual(appId);
- expect(configXml.version()).toEqual('1.0.0');
- // Check that we got package.json (the correct one)
- var pkjson = requireFresh(path.join(project, 'package.json'));
- // Pkjson.displayName should equal config's name.
- expect(pkjson.displayName).toEqual(appName);
- expect(pkjson.valid).toEqual('true');
-
- // Check that we got the right config.xml
- expect(configXml.description()).toEqual('this is the correct
config.xml');
+ function checkProjectCreatedWithFixtureTemplate () {
+ checkCommonArtifacts();
+ checkNoPackageJson();
+ checkNotDefaultTemplate();
+ }
+
+ function checkProjectCreatedWithDefaultTemplate () {
+ checkCommonArtifacts();
+ checkPackageJson();
+ checkDefaultTemplate();
}
it('should successfully run without template and use default hello-world
app', function () {
// Create a real project with no template
// use default cordova-app-hello-world app
return create(project, appId, appName, {}, events)
- .then(checkProject)
- .then(function () {
- var pkgJson = requireFresh(path.join(project, 'package.json'));
- // confirm default hello world app copies over package.json
and it matched appId
- expect(pkgJson.name).toEqual(appId);
- });
+ .then(checkProjectCreatedWithDefaultTemplate);
});
it('should successfully run with Git URL', function () {
@@ -161,7 +151,7 @@ describe('create end-to-end', function () {
expect(fetchSpy).toHaveBeenCalledTimes(1);
expect(fetchSpy.calls.argsFor(0)[0]).toBe(config.lib.www.url);
})
- .then(checkProject);
+ .then(checkProjectCreatedWithDefaultTemplate);
});
it('should successfully run with NPM package', function () {
@@ -179,7 +169,7 @@ describe('create end-to-end', function () {
expect(fetchSpy).toHaveBeenCalledTimes(1);
expect(fetchSpy.calls.argsFor(0)[0]).toBe(config.lib.www.url);
})
- .then(checkProject);
+ .then(checkProjectCreatedWithDefaultTemplate);
});
it('should successfully run with NPM package and explicitly fetch latest
if no version is given', function () {
@@ -198,7 +188,7 @@ describe('create end-to-end', function () {
expect(fetchSpy).toHaveBeenCalledTimes(1);
expect(fetchSpy.calls.argsFor(0)[0]).toBe(config.lib.www.url +
'@latest');
})
- .then(checkProject);
+ .then(checkProjectCreatedWithDefaultTemplate);
});
it('should successfully run with template not having a package.json at
toplevel', function () {
@@ -211,12 +201,7 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkProject)
- .then(function () {
- // Check that we got the right config.xml
- var configXml = new ConfigParser(path.join(project,
'config.xml'));
- expect(configXml.description()).toEqual('this is the very
correct config.xml');
- });
+ .then(checkProjectCreatedWithFixtureTemplate);
});
it('should successfully run with template having package.json and no sub
directory', function () {
@@ -229,7 +214,7 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkProject);
+ .then(checkProjectCreatedWithFixtureTemplate);
});
it('should successfully run with template having package.json, and
subdirectory, and no package.json in subdirectory', function () {
@@ -242,7 +227,7 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkProject);
+ .then(checkProjectCreatedWithFixtureTemplate);
});
it('should successfully run with template having package.json, and
subdirectory, and package.json in subdirectory', function () {
@@ -255,7 +240,9 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkSubDir);
+ .then(checkCommonArtifacts)
+ .then(checkPackageJson)
+ .then(checkNotDefaultTemplate);
});
it('should successfully run config.xml in the www folder and move it
outside', function () {
@@ -268,7 +255,7 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkConfigXml);
+ .then(checkProjectCreatedWithFixtureTemplate);
});
it('should successfully run with www folder as the template', function () {
@@ -281,13 +268,13 @@ describe('create end-to-end', function () {
}
};
return create(project, appId, appName, config, events)
- .then(checkConfigXml);
+ .then(checkProjectCreatedWithFixtureTemplate);
});
it('should successfully run with existing, empty destination', function ()
{
shell.mkdir('-p', project);
return create(project, appId, appName, {}, events)
- .then(checkProject);
+ .then(checkProjectCreatedWithDefaultTemplate);
});
describe('when --link-to is provided', function () {
diff --git a/spec/templates/config_in_www/www/config.xml
b/spec/templates/config_in_www/www/config.xml
index 0efe8c6..ccf0e68 100644
--- a/spec/templates/config_in_www/www/config.xml
+++ b/spec/templates/config_in_www/www/config.xml
@@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to
https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
diff --git a/spec/templates/no_content_config.xml
b/spec/templates/no_content_config.xml
index 7c4ef3d..2ef7ae4 100644
--- a/spec/templates/no_content_config.xml
+++ b/spec/templates/no_content_config.xml
@@ -10,7 +10,7 @@
</description>
<author href="http://cordova.io" email="[email protected]">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<access origin="*" />
diff --git a/spec/templates/nopackage_json/config.xml
b/spec/templates/nopackage_json/config.xml
index 3a9cb3c..1e821e0 100644
--- a/spec/templates/nopackage_json/config.xml
+++ b/spec/templates/nopackage_json/config.xml
@@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the very correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to
https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
diff --git a/spec/templates/withpackage_json/config.xml
b/spec/templates/withpackage_json/config.xml
index 02e616c..4b7e53e 100644
--- a/spec/templates/withpackage_json/config.xml
+++ b/spec/templates/withpackage_json/config.xml
@@ -23,7 +23,7 @@
A sample Apache Cordova application that responds to the deviceready
event.
</description>
<author email="[email protected]" href="http://cordova.io">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to
https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
diff --git a/spec/templates/withsubdirectory/template/config.xml
b/spec/templates/withsubdirectory/template/config.xml
index 02e616c..4b7e53e 100644
--- a/spec/templates/withsubdirectory/template/config.xml
+++ b/spec/templates/withsubdirectory/template/config.xml
@@ -23,7 +23,7 @@
A sample Apache Cordova application that responds to the deviceready
event.
</description>
<author email="[email protected]" href="http://cordova.io">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to
https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
diff --git a/spec/templates/withsubdirectory_package_json/template/config.xml
b/spec/templates/withsubdirectory_package_json/template/config.xml
index 0efe8c6..ccf0e68 100644
--- a/spec/templates/withsubdirectory_package_json/template/config.xml
+++ b/spec/templates/withsubdirectory_package_json/template/config.xml
@@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
- Apache Cordova Team
+ Apache Cordova Test Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to
https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
--
To stop receiving notification emails like this one, please contact
[email protected].
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]