Skip to content

Commit

Permalink
Improve JS Travis testing
Browse files Browse the repository at this point in the history
Summary:
Build emscripten js file on travis
Closes facebook#397

Reviewed By: arcanis

Differential Revision: D4579563

Pulled By: emilsjolander

fbshipit-source-id: fa5f92fd26f758fb617e428c07aabf2dccd63b37
  • Loading branch information
Maël Nison authored and facebook-github-bot committed Feb 20, 2017
1 parent 3f68b4f commit 78ade6c
Show file tree
Hide file tree
Showing 23 changed files with 10,804 additions and 10,796 deletions.
110 changes: 62 additions & 48 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,86 +19,100 @@ env:
- TARGET=android

before_install:
- brew update
- brew update > /dev/null
- brew tap facebook/fb
- brew install buck

# Java
- |
if [[ $TARGET = "java" ]]; then
brew cask install java;
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);
export PATH=$JAVA_HOME/bin:$PATH;
brew cask install java &&
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) &&
export PATH=$JAVA_HOME/bin:$PATH
fi
# .NET
- |
if [[ $TARGET = "net" ]]; then
brew install mono;
brew install mono
fi
# iOS
- |
if [[ $TARGET = "ios" ]]; then
brew outdated xctool || brew upgrade xctool;
brew outdated xctool || brew upgrade xctool
fi
# JavaScript
# Emscripten (used for js tests)
# Note: cannot be ran on Linux (because it will compile Clang from its sources :|)
- |
if [[ $TARGET = "js" ]]; then
cd javascript;
npm install;
wget -O /tmp/emsdk-portable.tar.gz https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz &&
tar xf /tmp/emsdk-portable.tar.gz -C /tmp/ &&
/tmp/emsdk_portable/emsdk install latest >& /dev/null &&
/tmp/emsdk_portable/emsdk activate latest
fi
# Android
- |
if [[ $TARGET = "android" ]]; then
brew cask install java;
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);
export PATH=$JAVA_HOME/bin:$PATH;
brew install android-sdk;
export ANDROID_SDK=/usr/local/opt/android-sdk
brew cask install java &&
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) &&
export PATH=$JAVA_HOME/bin:$PATH &&
brew install android-sdk &&
export ANDROID_SDK=/usr/local/opt/android-sdk &&
export ANDROID_HOME=/usr/local/opt/android-sdk
$ANDROID_SDK/tools/android update sdk --filter android-19,addon-google_apis-google-19
fi
# JavaScript
- |
if [[ $TARGET = "js" ]]; then (
cd javascript &&
npm install &&
unset CC && unset CXX && unset LINK &&
source /tmp/emsdk_portable/emsdk_env.sh &&
npm run build:browser
) fi
script:
# C
- |
if [[ $TARGET = "c" ]]; then
buck test --verbose 0 //:yoga &&
buck run --verbose 0 //benchmark:benchmark &&
git checkout HEAD^ &&
buck run --verbose 0 //benchmark:benchmark;
fi
# C
- |
if [[ $TARGET = "c" ]]; then
buck test --verbose 0 //:yoga &&
buck run --verbose 0 //benchmark:benchmark &&
git checkout HEAD^ &&
buck run --verbose 0 //benchmark:benchmark
fi
# Java
- |
if [[ $TARGET = "java" ]]; then
buck test --verbose 0 //java:java;
fi
# Java
- |
if [[ $TARGET = "java" ]]; then
buck test --verbose 0 //java:java
fi
# .NET
- |
if [[ $TARGET = "net" ]]; then
sh csharp/tests/Facebook.Yoga/test_macos.sh;
fi
# .NET
- |
if [[ $TARGET = "net" ]]; then
sh csharp/tests/Facebook.Yoga/test_macos.sh
fi
# iOS
- |
if [[ $TARGET = "ios" ]]; then
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64;
fi
# iOS
- |
if [[ $TARGET = "ios" ]]; then
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64
fi
# JavaScript
- |
if [[ $TARGET = "js" ]]; then
npm run test:all &&
npm run bench;
fi
# Android
- |
if [[ $TARGET = "android" ]]; then
buck build --verbose 0 //android/sample:sample
fi
# Android
- |
if [[ $TARGET = "android" ]]; then
buck build --verbose 0 //android/sample:sample
fi
# JavaScript
- |
if [[ $TARGET = "js" ]]; then (
cd javascript &&
npm run test:all &&
npm run bench
) fi
22 changes: 14 additions & 8 deletions gentest/gentest-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,40 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {

if (experiments.length > 0) {
for (var i in experiments) {
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.FEATURE_' + toJavascriptUpper(experiments[i]) + ', true);');
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_' + toJavascriptUpper(experiments[i]) + ', true);');
}
this.push('');
}

this.push('try {');
this.pushIndent();
}},

emitTestTreePrologue:{value:function(nodeName) {
this.push('var ' + nodeName + ' = Yoga.Node.create();');
}},

emitTestEpilogue:{value:function(experiments) {
this.push('');
this.push('if (typeof root !== "undefined")');
this.popIndent();
this.push('} finally {');
this.pushIndent();

this.push('if (typeof root !== "undefined") {');
this.pushIndent();
this.push('root.freeRecursive();');
this.popIndent();

this.push('');
this.push('(typeof gc !== "undefined") && gc();');
this.AssertEQ('0', 'Yoga.getInstanceCount()');
this.push('}');

if (experiments.length > 0) {
this.push('');
for (var i in experiments) {
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.FEATURE_' + toJavascriptUpper(experiments[i]) + ', false);');
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_' + toJavascriptUpper(experiments[i]) + ', false);');
}
}

this.popIndent();
this.push('}');

this.popIndent();
this.push('});');
}},
Expand Down
3 changes: 0 additions & 3 deletions javascript/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ node_modules

/dist
/build/*
!/build/Release
/build/Release/*
!/build/Release/nbind.js
/sources/yoga

npm-debug.log*
19 changes: 0 additions & 19 deletions javascript/build/Release/nbind.js

This file was deleted.

1 change: 1 addition & 0 deletions javascript/final-flags.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

"ldflags": [
"--memory-init-file", "0",
"-s", "PRECISE_F32=1",
"-s", "TOTAL_MEMORY=134217728"
],

Expand Down
25 changes: 17 additions & 8 deletions javascript/sources/entry-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function (bind, lib) {

case constants.UNIT_PERCENT:
return `${this.value}%`;

case constants.UNIT_AUTO:
return `auto`;

Expand All @@ -129,20 +129,22 @@ module.exports = function (bind, lib) {

for (let fnName of [ `setPosition`, `setMargin`, `setFlexBasis`, `setWidth`, `setHeight`, `setMinWidth`, `setMinHeight`, `setMaxWidth`, `setMaxHeight`, `setPadding` ]) {

let methods = { [constants.UNIT_POINT]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`] };

if (Object.keys(methods).some(method => methods[method] == null))
throw new Error(`Assertion failed; some unit derivates of ${fnName} seem missing`);
let methods = { [constants.UNIT_POINT]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`], [constants.UNIT_AUTO]: lib.Node.prototype[`${fnName}Auto`] };

patch(lib.Node.prototype, fnName, function (original, ... args) {

// We patch all these functions to add support for the following calls:
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth())
// .setWidth(100) / .setWidth("100%") / .setWidth(.getWidth()) / .setWidth("auto")

let value = args.pop();
let unit, asNumber;

if (value instanceof Value) {
if (value === `auto`) {

unit = constants.UNIT_AUTO;
asNumber = undefined;

} else if (value instanceof Value) {

unit = value.unit;
asNumber = value.valueOf();
Expand All @@ -154,7 +156,14 @@ module.exports = function (bind, lib) {

}

return methods[unit].call(this, ... args, asNumber);
if (!Object.prototype.hasOwnProperty.call(methods, unit))
throw new Error(`Failed to execute "${fnName}": Unsupported unit.`);

if (asNumber !== undefined) {
return methods[unit].call(this, ... args, asNumber);
} else {
return methods[unit].call(this, ... args);
}

});

Expand Down
Loading

0 comments on commit 78ade6c

Please sign in to comment.