diff --git a/.gitignore b/.gitignore index 4216e2f62..0dce6535c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ npm-debug.log *.pyc *.komodoproject /nbproject/private/ + +tests/compile/main_compressed.js +tests/compile/*compiler*.jar diff --git a/.travis.yml b/.travis.yml index bbc6cfcb8..6370db6d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 .. diff --git a/build.py b/build.py index 47234d347..6955cf909 100755 --- a/build.py +++ b/build.py @@ -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() diff --git a/demos/fixed-advanced/main.js b/demos/fixed-advanced/main.js deleted file mode 100644 index 5276e03d3..000000000 --- a/demos/fixed-advanced/main.js +++ /dev/null @@ -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); - diff --git a/package.json b/package.json index 95a7ea9eb..5a6e9fa18 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/compile/compile.sh b/tests/compile/compile.sh new file mode 100755 index 000000000..b5e73ec04 --- /dev/null +++ b/tests/compile/compile.sh @@ -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 diff --git a/demos/fixed-advanced/index.html b/tests/compile/index.html similarity index 52% rename from demos/fixed-advanced/index.html rename to tests/compile/index.html index a5630860d..93444421d 100644 --- a/demos/fixed-advanced/index.html +++ b/tests/compile/index.html @@ -2,7 +2,7 @@ - Blockly Demo: Fixed Blockly built with Closure Compiler's advanced optimizations + Blockly: Advanced Compilation Test -

- Blockly > - Demos > - Fixed Blockly built with Closure Compiler's advanced optimizations -

+

Blockly: Advanced Compilation Test

-

- This is a simple demo of injecting Blockly into a fixed-sized 'div' element - from a Closure-compiled source code with advanced optimizations. -

+

To run this test manually, download + closure-compiler-vxxxxxxxx.jar, + place it in this directory, then run compile.js from the command line.

-

→ More info on injecting fixed-sized Blockly

+

Measure the size of main_compressed.js (295kb as of October 2017), then reload + this page and see if Blockly works.

- - diff --git a/tests/compile/main.js b/tests/compile/main.js new file mode 100644 index 000000000..3fd1115a3 --- /dev/null +++ b/tests/compile/main.js @@ -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); diff --git a/tests/jsunit/connection_db_test.js b/tests/jsunit/connection_db_test.js index 558edf100..c9eb6add1 100644 --- a/tests/jsunit/connection_db_test.js +++ b/tests/jsunit/connection_db_test.js @@ -304,4 +304,4 @@ function helper_createConnection(x, y, type, opt_shared_workspace, conn.x_ = x; conn.y_ = y; return conn; -} \ No newline at end of file +} diff --git a/tests/jsunit/db_test.js b/tests/jsunit/db_test.js deleted file mode 100644 index 45fc62a4b..000000000 --- a/tests/jsunit/db_test.js +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/tests/jsunit/index.html b/tests/jsunit/index.html index 8ab715c6f..500f2cb37 100644 --- a/tests/jsunit/index.html +++ b/tests/jsunit/index.html @@ -8,26 +8,26 @@ - - - + - + + + + + + + + - - - - - diff --git a/tests/jsunit/input_test.js b/tests/jsunit/input_test.js index b80f44ab5..684bef43d 100644 --- a/tests/jsunit/input_test.js +++ b/tests/jsunit/input_test.js @@ -199,4 +199,4 @@ function test_insertFieldAt_prefix() { assertEquals(between, input.fieldRow[1]); assertEquals(suffix, input.fieldRow[2]); assertEquals(after, input.fieldRow[3]); -} \ No newline at end of file +} diff --git a/tests/jsunit/json_test.js b/tests/jsunit/json_test.js index 7967cd2f6..d489022b2 100644 --- a/tests/jsunit/json_test.js +++ b/tests/jsunit/json_test.js @@ -257,4 +257,3 @@ function test_json_dropdown_image() { delete Blockly.Msg['ALTTEXT']; } } - diff --git a/tests/jsunit/procedures_test.js b/tests/jsunit/procedures_test.js index 10003ec74..0284f3978 100644 --- a/tests/jsunit/procedures_test.js +++ b/tests/jsunit/procedures_test.js @@ -80,4 +80,3 @@ function test_isNameUsed_True() { assertTrue(result); proceduresTest_tearDownWithMockBlocks(); } - diff --git a/tests/jsunit/utils_test.js b/tests/jsunit/utils_test.js index 31ccfc187..4edb83fe2 100644 --- a/tests/jsunit/utils_test.js +++ b/tests/jsunit/utils_test.js @@ -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); diff --git a/tests/jsunit/widget_div_test.js b/tests/jsunit/widget_div_test.js index e43cde217..ea1260524 100644 --- a/tests/jsunit/widget_div_test.js +++ b/tests/jsunit/widget_div_test.js @@ -151,4 +151,3 @@ function test_widgetDiv_noXConflict_RTL() { anchorBBox, widgetDiv_test_widgetSize, true /* rtl */); assertEquals(anchorBBox.right - widgetDiv_test_widgetSize.width, calculated); } - diff --git a/scripts/.selenium_connect.sh.swp b/tests/scripts/.selenium_connect.sh.swp similarity index 100% rename from scripts/.selenium_connect.sh.swp rename to tests/scripts/.selenium_connect.sh.swp diff --git a/scripts/get_chromedriver.sh b/tests/scripts/get_chromedriver.sh similarity index 100% rename from scripts/get_chromedriver.sh rename to tests/scripts/get_chromedriver.sh diff --git a/scripts/get_geckdriver.sh b/tests/scripts/get_geckdriver.sh similarity index 100% rename from scripts/get_geckdriver.sh rename to tests/scripts/get_geckdriver.sh diff --git a/scripts/get_selenium.sh b/tests/scripts/get_selenium.sh similarity index 100% rename from scripts/get_selenium.sh rename to tests/scripts/get_selenium.sh diff --git a/scripts/selenium_connect.sh b/tests/scripts/selenium_connect.sh similarity index 100% rename from scripts/selenium_connect.sh rename to tests/scripts/selenium_connect.sh diff --git a/scripts/setup_linux_env.sh b/tests/scripts/setup_linux_env.sh similarity index 100% rename from scripts/setup_linux_env.sh rename to tests/scripts/setup_linux_env.sh diff --git a/scripts/setup_osx_env.sh b/tests/scripts/setup_osx_env.sh similarity index 100% rename from scripts/setup_osx_env.sh rename to tests/scripts/setup_osx_env.sh diff --git a/scripts/test_setup.sh b/tests/scripts/test_setup.sh similarity index 57% rename from scripts/test_setup.sh rename to tests/scripts/test_setup.sh index 4220923f3..e9ddf561f 100755 --- a/scripts/test_setup.sh +++ b/tests/scripts/test_setup.sh @@ -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