Skip to content

Commit

Permalink
Enable unit test execution from 'npm test'
Browse files Browse the repository at this point in the history
  • Loading branch information
hideya committed Dec 5, 2015
1 parent a39ea87 commit 67b4204
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 88 deletions.
100 changes: 41 additions & 59 deletions LoopBack.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions LoopBack.xcodeproj/xcshareddata/xcschemes/LoopBackOSX.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC2E1AD6F9C800D70046"
BuildableName = "LoopBack.framework"
BlueprintName = "LoopBackOSX"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC381AD6F9C800D70046"
BuildableName = "LoopBackOSXTests.xctest"
BlueprintName = "LoopBackOSXTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC381AD6F9C800D70046"
BuildableName = "LoopBackOSXTests.xctest"
BlueprintName = "LoopBackOSXTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC2E1AD6F9C800D70046"
BuildableName = "LoopBack.framework"
BlueprintName = "LoopBackOSX"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC2E1AD6F9C800D70046"
BuildableName = "LoopBack.framework"
BlueprintName = "LoopBackOSX"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4C9BC2E1AD6F9C800D70046"
BuildableName = "LoopBack.framework"
BlueprintName = "LoopBackOSX"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
99 changes: 99 additions & 0 deletions LoopBack.xcodeproj/xcshareddata/xcschemes/SLRemotingTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "47D47190196DF4A1002E2358"
BuildableName = "SLRemotingTests.xctest"
BlueprintName = "SLRemotingTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "47D47190196DF4A1002E2358"
BuildableName = "SLRemotingTests.xctest"
BlueprintName = "SLRemotingTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "47D47190196DF4A1002E2358"
BuildableName = "SLRemotingTests.xctest"
BlueprintName = "SLRemotingTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "47D47190196DF4A1002E2358"
BuildableName = "SLRemotingTests.xctest"
BlueprintName = "SLRemotingTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "47D47190196DF4A1002E2358"
BuildableName = "SLRemotingTests.xctest"
BlueprintName = "SLRemotingTests"
ReferencedContainer = "container:LoopBack.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1 change: 1 addition & 0 deletions LoopBackOSX/LoopBackOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "LBModel.h"
#import "LBPersistedModel.h"
#import "LBRESTAdapter.h"
#import "LBInstallation.h"
#import "LBUser.h"
Expand Down
53 changes: 53 additions & 0 deletions LoopBackTests/bin/run-unit-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -ex
trap 'kill $(jobs -p)' EXIT

# record the build environment
xcodebuild -version
xcodebuild -showsdks
instruments -s devices

# build for iOS
xcodebuild \
-verbose \
-project LoopBack.xcodeproj \
-scheme LoopBackFramework \
-sdk iphoneos \
-configuration Debug \
ONLY_ACTIVE_ARCH=NO \
${XCODEBUILD_ARGS} \
clean build

# prepare for running test servers
npm install

# run the test servers
node LoopBackTests/server/index.js &
node SLRemotingTests/server/index.js &

# run the unit tests on iPhone simulator
xcodebuild \
-verbose \
-project LoopBack.xcodeproj \
-scheme LoopBack \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone Retina (4-inch 64-bit),OS=latest' \
${XCODEBUILD_ARGS} \
test

# build for OS X
if [[ -n "${JENKINS_HOME}" ]]; then
# NOTE: the unit-tests fail to run against OS X on the CI, so it is temporarily skipped.
# See https://github.com/strongloop/loopback-sdk-ios/pull/79 for details.
OSX_BUILD_TARGET=build
else
OSX_BUILD_TARGET=test
fi

xcodebuild \
-verbose \
-project LoopBack.xcodeproj \
-scheme LoopBackOSX \
-sdk macosx \
${XCODEBUILD_ARGS} \
clean ${OSX_BUILD_TARGET}
12 changes: 0 additions & 12 deletions LoopBackTests/server/package.json

This file was deleted.

27 changes: 20 additions & 7 deletions SLRemoting/SLRemotingTestsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,36 @@
/**
* Marks the start of an asynchronous unit test.
*/
#define ASYNC_TEST_START XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithUTF8String:__FUNCTION__]];
// NOTE: since the CI uses Xcode 5, we cannot depend on XCTestExpectation.
// Use dispatch_semaphore instead.
//
// #define ASYNC_TEST_START XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithUTF8String:__FUNCTION__]];
#define ASYNC_TEST_START dispatch_semaphore_t sen_semaphore = dispatch_semaphore_create(0);

/**
* Marks the end of an asynchronous unit test.
*/
#define ASYNC_TEST_END [self waitForExpectationsWithTimeout:10 handler:nil];
// #define ASYNC_TEST_END [self waitForExpectationsWithTimeout:10 handler:nil];
#define ASYNC_TEST_END \
while (dispatch_semaphore_wait(sen_semaphore, DISPATCH_TIME_NOW)) \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];

/**
* Signals the completion of an asynchronous unit test.
*/
#define ASYNC_TEST_SIGNAL [expectation fulfill];
// #define ASYNC_TEST_SIGNAL [expectation fulfill];
#define ASYNC_TEST_SIGNAL dispatch_semaphore_signal(sen_semaphore);

/**
* Fails an asynchronous unit test, additionally signaling its completion.
*/
// #define ASYNC_TEST_FAILURE_BLOCK \
// ^(NSError *error) { \
// XCTFail(@"Test failed: %@", error.description); \
// [expectation fulfill]; \
// }
#define ASYNC_TEST_FAILURE_BLOCK \
^(NSError *error) { \
XCTFail(@"Test failed: %@", error.description); \
[expectation fulfill]; \
}
^(NSError *error) { \
XCTFail(@"Test failed: %@", error.description); \
ASYNC_TEST_SIGNAL \
}
1 change: 0 additions & 1 deletion SLRemotingTests/server/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions SLRemotingTests/server/package.json

This file was deleted.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,20 @@
"license": {
"name": "Dual MIT/StrongLoop",
"url": "https://github.com/strongloop/loopback-sdk-ios/blob/master/LICENSE"
},
"bugs": {
"url": "https://github.com/strongloop/loopback-sdk-ios/issues"
},
"scripts": {
"test": "LoopBackTests/bin/run-unit-tests"
},
"dependencies": {
},
"devDependencies": {
"strong-remoting": "^2.16.1",
"loopback": "^2.14.0",
"loopback-component-push": "^1.5.1",
"loopback-component-storage": "^1.3.1",
"morgan": "^1.5.2"
}
}

0 comments on commit 67b4204

Please sign in to comment.