Make async, and test both wasm and asm using jest

This commit is contained in:
Nick Gerleman
2022-12-22 05:49:05 -08:00
parent 09f0869262
commit 5561d9e651
33 changed files with 1537 additions and 248 deletions

View File

@@ -31,12 +31,7 @@ function toJavascriptUpper(symbol) {
JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
constructor:{value:JavascriptEmitter},
emitPrologue:{value:function() {
this.push([
'var Yoga = Yoga || require("../..");',
''
]);
}},
emitPrologue:{value:function() {}},
emitTestPrologue:{value:function(name, experiments) {
this.push('it(' + JSON.stringify(name) + ', function () {');

View File

@@ -33,8 +33,7 @@ EMCCOPTS=\
-s MODULARIZE=1 \
-s STRICT=1 \
-s TEXTDECODER=0 \
-s USE_ES6_IMPORT_META=0 \
-s WASM_ASYNC_COMPILATION=0
-s USE_ES6_IMPORT_META=0
LDLIBS=\
-lembind

14
javascript/jest.config.js Normal file
View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
module.exports = {
setupFiles: ["./jest.setup.js"],
testRegex: '/tests/Facebook.Yoga/.*\\.js$',
watchman: false,
}

69
javascript/jest.setup.js Normal file
View File

@@ -0,0 +1,69 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
module.exports = async () => {
global.Yoga = process.env['WASM']
? await require("./dist/index.wasm").initialize()
: await require("./dist/index.asm").initialize();
global.getMeasureCounter = function(Yoga, cb, staticWidth, staticHeight) {
var counter = 0;
return {
inc: function(width, widthMode, height, heightMode) {
counter += 1;
return cb
? cb(width, widthMode, height, heightMode)
: {width: staticWidth, height: staticHeight};
},
get: function() {
return counter;
},
};
};
global.getMeasureCounterMax = function(Yoga) {
return getMeasureCounter(Yoga, function(
width,
widthMode,
height,
heightMode,
) {
var measuredWidth = widthMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : width;
var measuredHeight =
heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height;
return {width: measuredWidth, height: measuredHeight};
});
};
global.getMeasureCounterMin = function(Yoga) {
return getMeasureCounter(Yoga, function(
width,
widthMode,
height,
heightMode,
) {
var measuredWidth =
widthMode === Yoga.MEASURE_MODE_UNDEFINED ||
(widthMode == Yoga.MEASURE_MODE_AT_MOST && width > 10)
? 10
: width;
var measuredHeight =
heightMode === Yoga.MEASURE_MODE_UNDEFINED ||
(heightMode == Yoga.MEASURE_MODE_AT_MOST && height > 10)
? 10
: height;
return {width: measuredWidth, height: measuredHeight};
});
};
}

View File

@@ -7,29 +7,30 @@
"type": "git",
"url": "git@github.com:facebook/yoga.git"
},
"main": "./dist/index.asm.js",
"exports": {
".": {
"default": "./dist/index.asm.js",
"browser": "./dist/index.wasm.js",
"node": "./dist/index.wasm.js",
"react-native": "./dist/index.asm.js"
"react-native": "./dist/index.asm.js",
"default": "./dist/index.asm.js"
}
},
"scripts": {
"is-monolithic": "test \"$(basename \"$(pwd)\")\" = javascript",
"copy-sources": "! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)",
"build": "npm run copy-sources && make && npm run build:js",
"test": "time mocha --expose-gc -r tests/tools.js tests/Facebook.Yoga/**/*.js",
"test": "yarn test:asm && yarn test:wasm",
"test:asm": "jest",
"test:wasm": "WASM=1 jest",
"benchmark": "npm run build && node tests/run-bench $(find tests/Benchmarks -name '*.js')",
"build:js": "babel sources --source-maps --out-dir dist && flow-copy-source sources dist"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core":"^7.20.7",
"@babel/core": "^7.20.7",
"@babel/plugin-transform-flow-strip-types": "^7.19.0",
"@babel/preset-env": "^7.20.2",
"flow-copy-source": "^2.0.7",
"mocha": "^3.2.0"
"jest": "^29.3.1"
}
}

View File

@@ -76,7 +76,7 @@ class Size {
expose(this.width, this.height);
}
toString() {
toString() {s
return `<Size#${this.width}x${this.height}>`;
}
}
@@ -216,6 +216,10 @@ export type Yoga$Node = {
unsetMeasureFun(): void,
};
type YogaConstructor = {
initialize: () => Promise<Yoga>;
}
type Yoga = {
Config: {
create(): Yoga$Config,
@@ -234,7 +238,7 @@ type Yoga = {
...typeof CONSTANTS,
};
module.exports = (lib: any): Yoga => {
function wrapLib(lib: any): Yoga {
function patch(prototype, name, fn) {
let original = prototype[name];
@@ -374,3 +378,7 @@ module.exports = (lib: any): Yoga => {
...CONSTANTS,
};
};
module.exports = (libPromise: any) => ({
initialize: () => libPromise.then(wrapLib)
}: YogaConstructor);

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html
var Yoga = Yoga || require("../..");
it("absolute_layout_width_height_start_top", function () {
var config = Yoga.Config.create();

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("align_baseline_parent_using_child_in_column_as_reference", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html
var Yoga = Yoga || require("../..");
it("align_content_flex_start", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html
var Yoga = Yoga || require("../..");
it("align_items_stretch", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html
var Yoga = Yoga || require("../..");
it("align_self_center", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGAndroidNewsFeed.html
var Yoga = Yoga || require("../..");
it("android_news_feed", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html
var Yoga = Yoga || require("../..");
it("border_no_size", function () {
var config = Yoga.Config.create();

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("border_start", function () {
var root = Yoga.Node.create();
root.setWidth(100);

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("margin_start", function () {
var root = Yoga.Node.create();
root.setWidth(100);

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("padding_start", function () {
var root = Yoga.Node.create();
root.setWidth(100);

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGDimensionTest.html
var Yoga = Yoga || require("../..");
it("wrap_child", function () {
var config = Yoga.Config.create();

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("dirtied", function() {
var root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
var Yoga = Yoga || require("../..");
it("display_none", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html
var Yoga = Yoga || require("../..");
it("flex_direction_column_no_height", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
var Yoga = Yoga || require("../..");
it("flex_basis_flex_grow_column", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html
var Yoga = Yoga || require("../..");
it("wrap_column", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGGapTest.html
var Yoga = Yoga || require("../..");
it("column_gap_flexible", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html
var Yoga = Yoga || require("../..");
it("justify_content_row_flex_start", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html
var Yoga = Yoga || require("../..");
it("margin_start", function () {
var config = Yoga.Config.create();

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("measure_once_single_flexible_child", function () {
var root = Yoga.Node.create();
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
var Yoga = Yoga || require("../..");
it("dont_measure_single_grow_shrink_child", function () {
var root = Yoga.Node.create();
root.setWidth(100);

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html
var Yoga = Yoga || require("../..");
it("max_width", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html
var Yoga = Yoga || require("../..");
it("padding_no_size", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html
var Yoga = Yoga || require("../..");
it("percentage_width_height", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html
var Yoga = Yoga || require("../..");
it("rounding_flex_basis_flex_grow_row_width_of_100", function () {
var config = Yoga.Config.create();

View File

@@ -7,8 +7,6 @@
// @generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
var Yoga = Yoga || require("../..");
it("nested_overflowing_child", function () {
var config = Yoga.Config.create();

File diff suppressed because it is too large Load Diff