From 99de99a1be20f40633d42e5764b15593024da510 Mon Sep 17 00:00:00 2001 From: Ross Bender Date: Wed, 25 Sep 2019 21:49:40 -0500 Subject: [PATCH 1/3] add watch app/extension test coverage --- test/addWatchApp.js | 139 ++++++++++++++++++++++++++++++++++++ test/addWatchExtension.js | 143 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 test/addWatchApp.js create mode 100644 test/addWatchExtension.js diff --git a/test/addWatchApp.js b/test/addWatchApp.js new file mode 100644 index 0000000..b51a290 --- /dev/null +++ b/test/addWatchApp.js @@ -0,0 +1,139 @@ +/** + 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 fullProject = require('./fixtures/full-project') + fullProjectStr = JSON.stringify(fullProject), + pbx = require('../lib/pbxProject'), + pbxFile = require('../lib/pbxFile'), + proj = new pbx('.'); + +function cleanHash() { + return JSON.parse(fullProjectStr); +} + +var TARGET_NAME = 'TestWatchApp', + TARGET_TYPE = 'watch2_app', + TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; + +exports.setUp = function (callback) { + proj.hash = cleanHash(); + callback(); +} + +exports.addWatchApp = { + 'should create a new watch app target': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.done(); + }, + 'should create a new watch app target without needing a subfolder name': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.done(); + }, + 'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), + options = { 'target' : target.uuid }; + + var sourceFile = proj.addSourceFile('Plugins/file.m', options), + sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), + resourceFile = proj.addResourceFile('assets.bundle', options), + resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), + frameworkFile = proj.addFramework('libsqlite3.dylib', options); + frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), + headerFile = proj.addHeaderFile('file.h', options); + + test.ok(sourcePhase); + test.ok(resourcePhase); + test.ok(frameworkPhase); + + test.equal(sourceFile.constructor, pbxFile); + test.equal(resourceFile.constructor, pbxFile); + test.equal(frameworkFile.constructor, pbxFile); + test.equal(headerFile.constructor, pbxFile); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.done(); + }, + 'should create a new watch app target and add watch build phase': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp2"'); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid); + + test.ok(buildPhase); + test.ok(buildPhase.files); + test.equal(buildPhase.files.length, 1); + test.ok(buildPhase.dstPath); + test.equal(buildPhase.dstPath, '"$(CONTENTS_FOLDER_PATH)/Watch"'); + test.equal(buildPhase.dstSubfolderSpec, 16); + + test.done(); + } +} diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js new file mode 100644 index 0000000..aa55cc0 --- /dev/null +++ b/test/addWatchExtension.js @@ -0,0 +1,143 @@ +/** + 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 fullProject = require('./fixtures/full-project') + fullProjectStr = JSON.stringify(fullProject), + pbx = require('../lib/pbxProject'), + pbxFile = require('../lib/pbxFile'), + proj = new pbx('.'); + +function cleanHash() { + return JSON.parse(fullProjectStr); +} + +var TARGET_NAME = 'TestWatchExtension', + TARGET_TYPE = 'watch2_extension', + TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; + +exports.setUp = function (callback) { + proj.hash = cleanHash(); + callback(); +} + +exports.addWatchExtension = { + 'should create a new watch extension target': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.done(); + }, + 'should create a new watch extension target and add source, framework, resource and header files and the corresponding build phases': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME), + options = { 'target' : target.uuid }; + + var sourceFile = proj.addSourceFile('Plugins/file.m', options), + sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid), + resourceFile = proj.addResourceFile('assets.bundle', options), + resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid), + frameworkFile = proj.addFramework('libsqlite3.dylib', options); + frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid), + headerFile = proj.addHeaderFile('file.h', options); + + test.ok(sourcePhase); + test.ok(resourcePhase); + test.ok(frameworkPhase); + + test.equal(sourceFile.constructor, pbxFile); + test.equal(resourceFile.constructor, pbxFile); + test.equal(frameworkFile.constructor, pbxFile); + test.equal(headerFile.constructor, pbxFile); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + test.done(); + }, + 'should not create a new watch extension build phase if no watch app exists': function (test) { + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + test.ok(typeof target == 'object'); + test.ok(target.uuid); + test.ok(target.pbxNativeTarget); + test.ok(target.pbxNativeTarget.isa); + test.ok(target.pbxNativeTarget.name); + test.ok(target.pbxNativeTarget.productName); + test.ok(target.pbxNativeTarget.productReference); + test.ok(target.pbxNativeTarget.productType); + test.ok(target.pbxNativeTarget.buildConfigurationList); + test.ok(target.pbxNativeTarget.buildPhases); + test.ok(target.pbxNativeTarget.buildRules); + test.ok(target.pbxNativeTarget.dependencies); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + + test.ok(!buildPhase); + + test.done(); + }, + 'should create a new watch extension build phase if watch app exists': function (test) { + proj.addTarget('TestWatchApp', 'watch2_app'); + var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); + + var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) + + test.ok(buildPhase); + test.ok(buildPhase.files); + test.equal(buildPhase.files.length, 1); + test.ok(buildPhase.dstPath); + test.equal(buildPhase.dstSubfolderSpec, 13); + + test.done(); + }, + 'should create a new watch extension and add to existing watch app build phase and dependency': function (test) { + var watchApp = proj.addTarget('TestWatchApp', 'watch2_app'); + + var nativeTargets = proj.pbxNativeTargetSection(); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); + + proj.addTarget(TARGET_NAME, TARGET_TYPE); + + test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 1); + test.equal(nativeTargets[watchApp.uuid].dependencies.length, 1); + + test.done(); + } +} From 69c5cfdf87072e855d7e6a550d174c733faaa591 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Thu, 17 Oct 2019 14:47:34 -0400 Subject: [PATCH 2/3] updated to test existing WatchKit support --- test/addWatchApp.js | 16 ++++------------ test/addWatchExtension.js | 31 +------------------------------ 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/test/addWatchApp.js b/test/addWatchApp.js index b51a290..2909a5c 100644 --- a/test/addWatchApp.js +++ b/test/addWatchApp.js @@ -26,7 +26,7 @@ function cleanHash() { } var TARGET_NAME = 'TestWatchApp', - TARGET_TYPE = 'watch2_app', + TARGET_TYPE = 'watch_app', TARGET_SUBFOLDER_NAME = 'TestWatchAppFiles'; exports.setUp = function (callback) { @@ -107,7 +107,8 @@ exports.addWatchApp = { test.done(); }, - 'should create a new watch app target and add watch build phase': function (test) { + 'should create a new watch app target that has the correct product type': function (test) { + // (with no subfolder name) var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -123,16 +124,7 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); - test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp2"'); - - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Watch Content', target.uuid); - - test.ok(buildPhase); - test.ok(buildPhase.files); - test.equal(buildPhase.files.length, 1); - test.ok(buildPhase.dstPath); - test.equal(buildPhase.dstPath, '"$(CONTENTS_FOLDER_PATH)/Watch"'); - test.equal(buildPhase.dstSubfolderSpec, 16); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp"'); test.done(); } diff --git a/test/addWatchExtension.js b/test/addWatchExtension.js index aa55cc0..9410488 100644 --- a/test/addWatchExtension.js +++ b/test/addWatchExtension.js @@ -26,7 +26,7 @@ function cleanHash() { } var TARGET_NAME = 'TestWatchExtension', - TARGET_TYPE = 'watch2_extension', + TARGET_TYPE = 'watch_extension', TARGET_SUBFOLDER_NAME = 'TestWatchExtensionFiles'; exports.setUp = function (callback) { @@ -109,35 +109,6 @@ exports.addWatchExtension = { test.ok(!buildPhase); - test.done(); - }, - 'should create a new watch extension build phase if watch app exists': function (test) { - proj.addTarget('TestWatchApp', 'watch2_app'); - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - - var buildPhase = proj.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed App Extensions', target.uuid) - - test.ok(buildPhase); - test.ok(buildPhase.files); - test.equal(buildPhase.files.length, 1); - test.ok(buildPhase.dstPath); - test.equal(buildPhase.dstSubfolderSpec, 13); - - test.done(); - }, - 'should create a new watch extension and add to existing watch app build phase and dependency': function (test) { - var watchApp = proj.addTarget('TestWatchApp', 'watch2_app'); - - var nativeTargets = proj.pbxNativeTargetSection(); - - test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 0); - test.equal(nativeTargets[watchApp.uuid].dependencies.length, 0); - - proj.addTarget(TARGET_NAME, TARGET_TYPE); - - test.equal(nativeTargets[watchApp.uuid].buildPhases.length, 1); - test.equal(nativeTargets[watchApp.uuid].dependencies.length, 1); - test.done(); } } From 299bf5aceb8bf80183c301ea00ba25e65cdf65ce Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Thu, 17 Oct 2019 14:56:50 -0400 Subject: [PATCH 3/3] refactor to check watchapp product type in the beginning (and remove some extra test code) --- test/addWatchApp.js | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/test/addWatchApp.js b/test/addWatchApp.js index 2909a5c..b1b603d 100644 --- a/test/addWatchApp.js +++ b/test/addWatchApp.js @@ -35,7 +35,7 @@ exports.setUp = function (callback) { } exports.addWatchApp = { - 'should create a new watch app target': function (test) { + 'should create a new watch app target with the correct product type': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME); test.ok(typeof target == 'object'); @@ -51,9 +51,11 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp"'); + test.done(); }, - 'should create a new watch app target without needing a subfolder name': function (test) { + 'should create a new watch app target with the correct product type, without needing a subfolder name': function (test) { var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); test.ok(typeof target == 'object'); @@ -69,6 +71,8 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); + test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp"'); + test.done(); }, 'should create a new watch app target and add source, framework, resource and header files and the corresponding build phases': function (test) { @@ -105,27 +109,6 @@ exports.addWatchApp = { test.ok(target.pbxNativeTarget.buildRules); test.ok(target.pbxNativeTarget.dependencies); - test.done(); - }, - 'should create a new watch app target that has the correct product type': function (test) { - // (with no subfolder name) - var target = proj.addTarget(TARGET_NAME, TARGET_TYPE); - - test.ok(typeof target == 'object'); - test.ok(target.uuid); - test.ok(target.pbxNativeTarget); - test.ok(target.pbxNativeTarget.isa); - test.ok(target.pbxNativeTarget.name); - test.ok(target.pbxNativeTarget.productName); - test.ok(target.pbxNativeTarget.productReference); - test.ok(target.pbxNativeTarget.productType); - test.ok(target.pbxNativeTarget.buildConfigurationList); - test.ok(target.pbxNativeTarget.buildPhases); - test.ok(target.pbxNativeTarget.buildRules); - test.ok(target.pbxNativeTarget.dependencies); - - test.equal(target.pbxNativeTarget.productType, '"com.apple.product-type.application.watchapp"'); - test.done(); } }