Convert compile demo into a unit test. (#1360)

* Intentionally break Travis.

* Alphabetize tests, remove orphaned test, and add fail to test that's running.

* Unbreak test, disable OS X, move scripts, list compiler directory.

* Test Java, break test.

* Unbreak test, call compile script.

* Compile main_compressed.js

* Run test command using bash.

* Fix path.

* Exclude node modules.

* Be more specific about JS files to compile.

* Test failure.

* Restore OSX, undo Blockly failure, remove compilation demo, add compilation test.

* Delete manual test files.

* Ignore downloaded/generated files.

* Whitespace cleanup.
This commit is contained in:
Neil Fraser
2017-10-12 14:54:57 -07:00
committed by Rachel Fenichel
parent 4df6f11f8a
commit 82705923cb
24 changed files with 97 additions and 206 deletions

3
.gitignore vendored
View File

@@ -6,3 +6,6 @@ npm-debug.log
*.pyc
*.komodoproject
/nbproject/private/
tests/compile/main_compressed.js
tests/compile/*compiler*.jar

View File

@@ -15,16 +15,18 @@ matrix:
before_install:
- npm install google-closure-library
- npm install google-closure-compiler
- npm install webdriverio
# Symlink closure library
- ln -s $(npm root)/google-closure-library ../closure-library
before_script:
- export DISPLAY=:99.0
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then ( scripts/setup_linux_env.sh ) fi
- if [ "${TRAVIS_OS_NAME}" == "osx" ]; then ( scripts/setup_osx_env.sh ) fi
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then ( tests/scripts/setup_linux_env.sh ) fi
- if [ "${TRAVIS_OS_NAME}" == "osx" ]; then ( tests/scripts/setup_osx_env.sh ) fi
- sleep 2
script:
- set -x
- npm test
- cd tests/compile; compile.sh; cd ..

View File

@@ -60,10 +60,9 @@ for arg in sys.argv[1:len(sys.argv)]:
if (arg != 'core' and
arg != 'accessible' and
arg != 'generators' and
arg != 'langfiles' and
arg != 'demo'):
raise Exception("Invalid argument: \"" + arg + "\". Usage: build.py <0 or more of accessible," +
" core, generators, langfiles, demo>")
arg != 'langfiles'):
raise Exception("Invalid argument: \"" + arg + "\". Usage: build.py "
"<0 or more of accessible, core, generators, langfiles>")
import errno, glob, httplib, json, os, re, subprocess, threading, urllib
@@ -215,47 +214,6 @@ class Gen_compressed(threading.Thread):
self.gen_generator("dart")
self.gen_generator("lua")
if ('demo' in self.bundles):
self.gen_together()
def gen_together(self):
target_filename = os.path.join("demos", "fixed-advanced", "main_compressed.js")
# Define the parameters for the POST request.
params = [
("compilation_level", "ADVANCED_OPTIMIZATIONS"),
("use_closure_library", "true"),
("generate_exports", "true"),
("output_format", "json"),
("output_info", "compiled_code"),
("output_info", "warnings"),
("output_info", "errors"),
("output_info", "statistics"),
# debug options (to make the uglified code readable)
# ("formatting", "pretty_print"),
# ("formatting", "print_input_delimiter"),
# ("debug", "true"),
]
# Read in all the source files.
filenames = calcdeps.CalculateDependencies(self.search_paths,
[os.path.join("demos", "fixed-advanced", "main.js")])
filenames.sort() # Deterministic build.
for filename in filenames:
# Filter out the Closure files (the compiler will add them).
if filename.startswith(os.pardir + os.sep): # '../'
continue
f = open(filename)
params.append(("js_code", "".join(f.readlines())))
f.close()
externs = [os.path.join("externs", "svg-externs.js")]
for filename in externs:
f = open(filename)
params.append(("js_externs", "".join(f.readlines())))
f.close()
self.do_compile(params, target_filename, filenames, "")
def gen_core(self):
target_filename = "blockly_compressed.js"
# Define the parameters for the POST request.
@@ -610,13 +568,6 @@ developers.google.com/blockly/guides/modify/web/closure""")
if ('accessible' in args):
Gen_uncompressed(full_search_paths, 'blockly_accessible_uncompressed.js').start()
if ('demo' in args):
all_search_paths = calcdeps.ExpandDirectories(
["accessible", "core", "blocks", os.path.join("demos", "fixed-advanced"), os.path.join("msg", "js"), os.path.join(os.path.pardir, "closure-library")])
all_search_paths.sort() # Deterministic build.
print("Compressing " + str(len(all_search_paths)) + " files...")
Gen_compressed(all_search_paths, args).start()
else:
# Compressed is limited by network and server speed.
Gen_compressed(full_search_paths, args).start()

View File

@@ -1,31 +0,0 @@
/**
* @fileoverview Main file (entry point) for the advanced compilation demo.
*/
'use strict';
goog.provide('Demo');
// messages (in some language)
goog.require('Blockly.Msg.en');
// core
goog.require('Blockly');
// blocks
goog.require('Blockly.Constants.Colour');
goog.require('Blockly.Constants.Lists');
goog.require('Blockly.Constants.Logic');
goog.require('Blockly.Constants.Loops');
goog.require('Blockly.Constants.Math');
goog.require('Blockly.Blocks.procedures');
goog.require('Blockly.Constants.Text');
goog.require('Blockly.Constants.Variables');
Demo.init = function() {
Blockly.inject('blocklyDiv', {
'media': '../../media/',
'toolbox': document.getElementById('toolbox')
});
}
window.addEventListener('load', Demo.init);

View File

@@ -18,7 +18,7 @@
},
"scripts": {
"lint": "jshint .",
"pretest": "scripts/test_setup.sh",
"pretest": "tests/scripts/test_setup.sh",
"test": "node tests/jsunit/test_runner.js"
},
"license": "Apache-2.0",

34
tests/compile/compile.sh Executable file
View File

@@ -0,0 +1,34 @@
# Find the Closure Compiler.
if [ -f "$(npm root)/google-closure-compiler/compiler.jar" ]; then
# Travis test.
COMPILER="$(npm root)/google-closure-compiler/compiler.jar"
elif [ -f *compiler*.jar ]; then
# Manual test.
COMPILER="*compiler*.jar"
else
echo "ERROR: Closure Compiler not found."
echo "Download from this URL, and place jar file in current directory."
echo "https://dl.google.com/closure-compiler/compiler-latest.zip"
exit 1
fi
rm main_compressed.js 2> /dev/null
echo Compiling Blockly...
java -jar $COMPILER --js='main.js' \
--js='../../core/**.js' \
--js='../../blocks/**.js' \
--js='../../generators/**.js' \
--js='../../msg/js/**.js' \
--js='../../../closure-library/closure/goog/**.js' \
--js='../../../closure-library/third_party/closure/goog/**.js' \
--generate_exports \
--externs ../../externs/svg-externs.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--dependency_mode=STRICT --entry_point=Main \
--js_output_file main_compressed.js
if [ -s main_compressed.js ]; then
echo Compilation OK.
else
echo Compilation FAIL.
exit 1
fi

View File

@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo: Fixed Blockly built with Closure Compiler&apos;s advanced optimizations</title>
<title>Blockly: Advanced Compilation Test</title>
<script src="main_compressed.js"></script>
<style>
body {
@@ -16,21 +16,16 @@
</style>
</head>
<body>
<h1>
<a href="https://developers.google.com/blockly/">Blockly</a> &gt;
<a href="../index.html">Demos</a> &gt;
Fixed Blockly built with Closure Compiler&apos;s advanced optimizations
</h1>
<h1>Blockly: Advanced Compilation Test</h1>
<p>
This is a simple demo of injecting Blockly into a fixed-sized 'div' element
from a Closure-compiled source code with advanced optimizations.
</p>
<p>To run this test manually, download
<a href="https://dl.google.com/closure-compiler/compiler-latest.zip">closure-compiler-vxxxxxxxx.jar</a>,
place it in this directory, then run compile.js from the command line.</p>
<p>&rarr; More info on <a href="https://developers.google.com/blockly/guides/configure-blockly/web/fixed-size">injecting fixed-sized Blockly</a>&hellip;</p>
<p>Measure the size of main_compressed.js (295kb as of October 2017), then reload
this page and see if Blockly works.</p>
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
<xml id="toolbox" style="display: none">
<block type="controls_if"></block>
<block type="logic_compare"></block>
@@ -40,6 +35,5 @@
<block type="text"></block>
<block type="text_print"></block>
</xml>
</body>
</html>

17
tests/compile/main.js Normal file
View File

@@ -0,0 +1,17 @@
goog.provide('Main');
// Messages (in some language)
goog.require('Blockly.Msg.en');
// Core
goog.require('Blockly');
// Blocks
goog.require('Blockly.Constants.Logic');
goog.require('Blockly.Constants.Loops');
goog.require('Blockly.Constants.Math');
goog.require('Blockly.Constants.Text');
Main.init = function() {
Blockly.inject('blocklyDiv', {
'toolbox': document.getElementById('toolbox')
});
};
window.addEventListener('load', Main.init);

View File

@@ -304,4 +304,4 @@ function helper_createConnection(x, y, type, opt_shared_workspace,
conn.x_ = x;
conn.y_ = y;
return conn;
}
}

View File

@@ -1,76 +0,0 @@
/**
* @license
* Blockly Tests
*
* Copyright 2016 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed 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.
*/
'use strict';
function test_DB_getNeighbours() {
var db = new Blockly.ConnectionDB();
// Search an empty list.
assertEquals(helper_getNeighbours(db, 10 /* x */, 10 /* y */, 100 /* radius */).length, 0);
// Set up some connections.
for (var i = 0; i < 10; i++) {
db.addConnection_(helper_createConnection(0, i, Blockly.PREVIOUS_STATEMENT));
}
// Test block belongs at beginning
var result = helper_getNeighbours(db, 0, 0, 4);
assertEquals(5, result.length);
for (i = 0; i < result.length; i++) {
assertNotEquals(result.indexOf(db[i]), -1); // contains
}
// Test block belongs at middle
result = helper_getNeighbours(db, 0, 4, 2);
assertEquals(5, result.length);
for (i = 0; i < result.length; i++) {
assertNotEquals(result.indexOf(db[i + 2]), -1); // contains
}
// Test block belongs at end
result = helper_getNeighbours(db, 0, 9, 4);
assertEquals(5, result.length);
for (i = 0; i < result.length; i++) {
assertNotEquals(result.indexOf(db[i + 5]), -1); // contains
}
// Test block has no neighbours due to being out of range in the x direction
result = helper_getNeighbours(db, 10, 9, 4);
assertEquals(result.length, 0);
// Test block has no neighbours due to being out of range in the y direction
result = helper_getNeighbours(db, 0, 19, 4);
assertEquals(result.length, 0);
// Test block has no neighbours due to being out of range diagonally
result = helper_getNeighbours(db, -2, -2, 2);
assertEquals(result.length, 0);
}
function helper_getNeighbours(db, x, y, radius) {
return db.getNeighbours(helper_createConnection(x, y, Blockly.NEXT_STATEMENT), radius);
}
function helper_createConnection(x, y, type) {
var conn = new Blockly.Connection({workspace: {}}, type);
conn.x_ = x;
conn.y_ = y;
return conn;
}

View File

@@ -8,26 +8,26 @@
</head>
<body>
<script src="test_utilities.js"></script>
<script src="utils_test.js"></script>
<script src="connection_test.js"></script>
<script src="connection_db_test.js"></script>
<script src="extensions_test.js"></script>
<script src="connection_test.js"></script>
<script src="event_test.js"></script>
<script src="field_test.js"></script>
<script src="extensions_test.js"></script>
<script src="field_angle_test.js"></script>
<script src="field_number_test.js"></script>
<script src="field_test.js"></script>
<script src="field_variable_test.js"></script>
<script src="generator_test.js"></script>
<script src="gesture_test.js"></script>
<script src="input_test.js"></script>
<script src="json_test.js"></script>
<script src="names_test.js"></script>
<script src="procedures_test.js"></script>
<script src="utils_test.js"></script>
<script src="variable_map_test.js"></script>
<script src="variable_model_test.js"></script>
<script src="widget_div_test.js"></script>
<script src="workspace_test.js"></script>
<script src="workspace_undo_redo_test.js"></script>
<script src="xml_test.js"></script>
<script src="json_test.js"></script>
<script src="procedures_test.js"></script>
<script src="variable_model_test.js"></script>
<script src="variable_map_test.js"></script>
<script src="widget_div_test.js"></script>
</body>
</html>

View File

@@ -199,4 +199,4 @@ function test_insertFieldAt_prefix() {
assertEquals(between, input.fieldRow[1]);
assertEquals(suffix, input.fieldRow[2]);
assertEquals(after, input.fieldRow[3]);
}
}

View File

@@ -257,4 +257,3 @@ function test_json_dropdown_image() {
delete Blockly.Msg['ALTTEXT'];
}
}

View File

@@ -80,4 +80,3 @@ function test_isNameUsed_True() {
assertTrue(result);
proceduresTest_tearDownWithMockBlocks();
}

View File

@@ -42,14 +42,14 @@ function test_addClass() {
assertEquals('Adding "three"', 'one two three', p.className);
}
function test_hasClass() {
var p = document.createElement('p');
p.className = ' one three two three ';
assertTrue('Has "one"', Blockly.utils.hasClass(p, 'one'));
assertTrue('Has "two"', Blockly.utils.hasClass(p, 'two'));
assertTrue('Has "three"', Blockly.utils.hasClass(p, 'three'));
assertFalse('Has no "four"', Blockly.utils.hasClass(p, 'four'));
assertFalse('Has no "t"', Blockly.utils.hasClass(p, 't'));
function test_hasClass() {
var p = document.createElement('p');
p.className = ' one three two three ';
assertTrue('Has "one"', Blockly.utils.hasClass(p, 'one'));
assertTrue('Has "two"', Blockly.utils.hasClass(p, 'two'));
assertTrue('Has "three"', Blockly.utils.hasClass(p, 'three'));
assertFalse('Has no "four"', Blockly.utils.hasClass(p, 'four'));
assertFalse('Has no "t"', Blockly.utils.hasClass(p, 't'));
}
function test_removeClass() {
@@ -128,19 +128,19 @@ function test_tokenizeInterpolation() {
tokens = Blockly.utils.tokenizeInterpolation('Hello');
assertArrayEquals('No interpolation', ['Hello'], tokens);
tokens = Blockly.utils.tokenizeInterpolation('Hello%World');
assertArrayEquals('Unescaped %.', ['Hello%World'], tokens);
tokens = Blockly.utils.tokenizeInterpolation('Hello%%World');
assertArrayEquals('Escaped %.', ['Hello%World'], tokens);
tokens = Blockly.utils.tokenizeInterpolation('Hello %1 World');
assertArrayEquals('Interpolation.', ['Hello ', 1, ' World'], tokens);
tokens = Blockly.utils.tokenizeInterpolation('%123Hello%456World%789');
assertArrayEquals('Interpolations.', [123, 'Hello', 456, 'World', 789], tokens);
tokens = Blockly.utils.tokenizeInterpolation('%%%x%%0%00%01%');
assertArrayEquals('Torture interpolations.', ['%%x%0', 0, 1, '%'], tokens);

View File

@@ -151,4 +151,3 @@ function test_widgetDiv_noXConflict_RTL() {
anchorBBox, widgetDiv_test_widgetSize, true /* rtl */);
assertEquals(anchorBBox.right - widgetDiv_test_widgetSize.width, calculated);
}

View File

@@ -11,13 +11,13 @@ function check_command {
fi
}
check_command scripts/get_geckdriver.sh
check_command tests/scripts/get_geckdriver.sh
sleep 5
check_command scripts/get_selenium.sh
check_command tests/scripts/get_selenium.sh
sleep 5
check_command scripts/get_chromedriver.sh
check_command tests/scripts/get_chromedriver.sh
sleep 10
check_command scripts/selenium_connect.sh
check_command tests/scripts/selenium_connect.sh
sleep 10
exit $EXIT_STATUS