Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge branch 'sanity-tests' of https://github.com/MSOpenTech/cordova-wp8
  • Loading branch information
purplecabbage committed Jan 20, 2015
2 parents 4ea3410 + 0f6431f commit 02c42e82a566cdb908e032438390f6b6569938d3
Showing 12 changed files with 704 additions and 5 deletions.
0 node
Empty file.
@@ -26,10 +26,15 @@
"q"
],
"devDependencies": {
"jasmine-node": "~1"
"jasmine-node": "~1",
"rewire": ">=2.1.3",
"istanbul": "^0.3.4"
},
"scripts": {
"test": "RMDIR /s /q \"testcreate 応用\" & bin\\create \"testcreate 応用\" com.test.app 応用 & \".\\testcreate 応用\\cordova\\build\" && RMDIR /s /q \"testcreate 応用\""
"test": "npm run test-unit && npm run test-e2e",
"test-unit": "node node_modules/jasmine-node/lib/jasmine-node/cli.js --captureExceptions spec/unit",
"test-e2e": "node node_modules/jasmine-node/lib/jasmine-node/cli.js --captureExceptions spec/e2e",
"cover": "node node_modules/istanbul/lib/cli.js cover --root template --print detail node_modules/jasmine-node/bin/jasmine-node -- spec/unit"
},
"author": "Apache Software Foundation",
"license": "Apache Version 2.0"
@@ -0,0 +1,66 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var shell = require('shelljs'),
fs = require('fs'),
path = require('path');

describe("Cordova create and build", function(){

var projectFolder = "testcreate 応用",
buildDirectory = path.join(__dirname, '../..'),
anycpuPackageFolder = path.join(buildDirectory, projectFolder, 'Bin', 'Debug'),
x86PackageFolder = path.join(buildDirectory, projectFolder, 'Bin', 'x86', 'Debug'),
armPackageFolder = path.join(buildDirectory, projectFolder, 'Bin', 'ARM', 'Debug'),
buildScriptPath = '"' + path.join(buildDirectory, projectFolder, 'cordova', 'build') + '"';

beforeEach(function(){
shell.exec(path.join('bin', 'create') + ' "' + projectFolder + '" com.test.app 応用', {silent : true});
});

afterEach(function() {
shell.cd(buildDirectory);
shell.rm('-rf', projectFolder);
});

it("spec.1 should create new project", function(){
expect(fs.existsSync(projectFolder)).toBe(true);
});

it("spec.2 should build project", function(){
shell.exec(buildScriptPath, {silent:true});
var packages = shell.ls(anycpuPackageFolder);
expect(packages.filter(function(file) { return file.match(/.*AnyCPU\.xap$/); }).length).toBe(1);
});

it("spec.3 should build project for particular CPU", function(){
shell.exec(buildScriptPath + ' --archs=\"x86\"', {silent : true});
var x86Package = shell.ls(x86PackageFolder);
expect(x86Package.filter(function(file) { return file.match(/.*x86\.xap$/); }).length).toBe(1);
});

it("spec.4 should build project for CPUs separated by whitespaces", function(){
shell.exec(buildScriptPath + ' --archs=\"x86 arm anycpu\"', {silent : true});
var anycpuPackage = shell.ls(anycpuPackageFolder);
expect(anycpuPackage.filter(function(file) { return file.match(/.*AnyCPU\.xap$/); }).length).toBe(1);
var x86Package = shell.ls(x86PackageFolder);
expect(x86Package.filter(function(file) { return file.match(/.*x86\.xap$/); }).length).toBe(1);
var armPackage = shell.ls(armPackageFolder);
expect(armPackage.filter(function(file) { return file.match(/.*ARM\.xap$/); }).length).toBe(1);
});
});
@@ -0,0 +1,158 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var Q = require('q'),
rewire = require('rewire'),
platformRoot = '../../template',
buildTools = rewire(platformRoot + '/cordova/lib/MSBuildTools.js');

var fakeToolsPath = function (version) {
return "C:\\Program Files (x86)\\MSBuild\\" + version;
};

describe('findAvailableVersion method', function(){
var checkMSBuildVersionOriginal;

var checkMSBuildVersionFake = function (availableVersions, version) {
var MSBuildTools = buildTools.__get__('MSBuildTools');
return (availableVersions.indexOf(version) >= 0) ? Q.resolve(new MSBuildTools(version, fakeToolsPath(version))) : Q.resolve(null);
};

var versionTest = function (availableVersions, version, done) {
buildTools.__set__('checkMSBuildVersion', checkMSBuildVersionFake.bind(null, availableVersions));
buildTools.findAvailableVersion().then(function (msbuildTools) {
expect(msbuildTools).not.toBeNull();
expect(msbuildTools.version).toBeDefined();
expect(msbuildTools.path).toBeDefined();
expect(msbuildTools.version).toBe(version);
expect(msbuildTools.path).toBe(fakeToolsPath(version));
if (typeof done === 'function') {
done();
}
});
}

beforeEach(function () {
checkMSBuildVersionOriginal = buildTools.__get__('checkMSBuildVersion');
});

afterEach(function () {
buildTools.__set__('checkMSBuildVersion', checkMSBuildVersionOriginal);
});

it('spec.1 should find 14.0 available version if 12.0 is unavailable', function(done){
versionTest(['14.0'], '14.0', done);
});

it('spec.2 should select 14.0 available version even if 12.0 is also available', function(done){
versionTest(['14.0', '12.0', '4.0'], '14.0', done);
});

it('spec.3 should find 12.0 available version if 14.0 is unavailable', function(done){
versionTest(['12.0', '4.0'], '12.0', done);
});

it('spec.4 should find 4.0 available version if neither 12.0 nor 14.0 are available', function(done){
versionTest(['4.0'], '4.0', done);
});

it('spec.5 should produce an error if there is no available versions', function(done){
var resolveSpy = jasmine.createSpy();

buildTools.__set__('checkMSBuildVersion', checkMSBuildVersionFake.bind(null, []));
buildTools.findAvailableVersion()
.then(resolveSpy, function(error){
expect(error).toBeDefined();
})
.finally(function() {
expect(resolveSpy).not.toHaveBeenCalled();
done();
});
});
});

describe('checkMSBuildVersion method', function(){
var checkMSBuildVersion = buildTools.__get__('checkMSBuildVersion'),
execOriginal;

beforeEach(function () {
execOriginal = buildTools.__get__('utils.exec');
});

afterEach(function () {
buildTools.__set__('utils.exec', execOriginal);
});

it('spec.6 should return valid version and path', function(){
var version = '14.0';

buildTools.__set__('utils.exec', function(cmd) {
return Q.resolve("\r\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\12.0\r\n\tMSBuildToolsPath\tREG_SZ\t" + fakeToolsPath(version) + "\r\n\r\n");
});

checkMSBuildVersion(version).then(function (actual) {
expect(actual.version).toBe(version);
expect(actual.path).toBe(fakeToolsPath(version));
});
});

it('spec.7 should return null if no tools found for version', function(){
buildTools.__set__('utils.exec', function(cmd) {
return Q.resolve('ERROR: The system was unable to find the specified registry key or value.');
});

checkMSBuildVersion('14.0').then(function (actual) {
expect(actual).toBeNull();
});
});

it('spec.8 should return null on internal error', function(){
buildTools.__set__('utils.exec', function(cmd) {
return Q.reject();
});

checkMSBuildVersion('14.0').then(function (actual) {
expect(actual).toBeNull();
});
});
});

describe('MSBuildTools object', function(){
var MSBuildTools = buildTools.__get__('MSBuildTools'),
spawnOriginal;

beforeEach(function () {
spawnOriginal = buildTools.__get__('utils.spawn');
});

afterEach(function () {
buildTools.__set__('utils.spawn', spawnOriginal);
});

it('spec.9 should have fields and methods defined', function() {
var version = '14.0',
toolsPath = fakeToolsPath(version),
actual = new MSBuildTools(version, toolsPath);

expect(actual.path).toBeDefined();
expect(actual.path).toBe(toolsPath);
expect(actual.version).toBeDefined();
expect(actual.version).toBe(version);
expect(actual.buildProject).toBeDefined();
});
});

0 comments on commit 02c42e8

Please sign in to comment.