Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup tests #16

Merged
merged 9 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
139 changes: 63 additions & 76 deletions spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion spec/templates/config_in_www/www/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the correct config.xml</description>
<author email="dev@cordova.apache.org" 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 -->
Expand Down
2 changes: 1 addition & 1 deletion spec/templates/no_content_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</description>

<author href="http://cordova.io" email="dev@cordova.apache.org">
Apache Cordova Team
Apache Cordova Test Team
</author>

<access origin="*" />
Expand Down
2 changes: 1 addition & 1 deletion spec/templates/nopackage_json/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the very correct config.xml</description>
<author email="dev@cordova.apache.org" 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 -->
Expand Down
2 changes: 1 addition & 1 deletion spec/templates/withpackage_json/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" 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 -->
Expand Down
2 changes: 1 addition & 1 deletion spec/templates/withsubdirectory/template/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" 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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<name>HelloCordova</name>
<description>this is the correct config.xml</description>
<author email="dev@cordova.apache.org" 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 -->
Expand Down