fix: Fix the compiler test, and check if it worked. (#6638)

* Add tsick.js to rewrite enums.

tsc generates JavaScript which is incompatible with the Closure Compiler's advanced optimizations.

* Remove unused 'outputCode' variable.

* Rename 'run_X_in_browser.js' to 'webdriver.js'

The Mocha and generator tests can both be run either manually or via our webdriver.  In all cases they run in a browser.  These two 'run_X_in_browser.js' files only apply to webdriver, thus they are confusingly named.

Also delete completely unused (and broken) `run_all_tests.sh`

* Linting improvements to mocha/webdriver.js

Still not at 100%.  Complains about require/module/process/__dirname not being defined in multiple places.

* runTestBlock -> runTestFunction

'Block' means something very different in Blockly.

* Removal of `var` from scripts.

* Add webdriver test to verify compile test worked.

* Resolve conficts with 'develop'.

* Address PR comments.
This commit is contained in:
Neil Fraser
2022-11-25 20:45:00 +01:00
committed by GitHub
parent be4b8323c5
commit 5a64a9a7f7
14 changed files with 349 additions and 154 deletions

View File

@@ -8,27 +8,27 @@
* @fileoverview Gulp script to build Blockly for Node & NPM.
*/
var gulp = require('gulp');
const gulp = require('gulp');
gulp.replace = require('gulp-replace');
gulp.rename = require('gulp-rename');
gulp.sourcemaps = require('gulp-sourcemaps');
var path = require('path');
var fs = require('fs');
const path = require('path');
const fs = require('fs');
const {exec, execSync} = require('child_process');
var through2 = require('through2');
const through2 = require('through2');
const clangFormat = require('clang-format');
const clangFormatter = require('gulp-clang-format');
var closureCompiler = require('google-closure-compiler').gulp();
var closureDeps = require('google-closure-deps');
var argv = require('yargs').argv;
var rimraf = require('rimraf');
const closureCompiler = require('google-closure-compiler').gulp();
const closureDeps = require('google-closure-deps');
const argv = require('yargs').argv;
const rimraf = require('rimraf');
var {BUILD_DIR, DEPS_FILE, RELEASE_DIR, TEST_DEPS_FILE, TSC_OUTPUT_DIR, TYPINGS_BUILD_DIR} = require('./config');
var {getPackageJson} = require('./helper_tasks');
const {BUILD_DIR, DEPS_FILE, RELEASE_DIR, TEST_DEPS_FILE, TSC_OUTPUT_DIR, TYPINGS_BUILD_DIR} = require('./config');
const {getPackageJson} = require('./helper_tasks');
var {posixPath} = require('../helpers');
const {posixPath} = require('../helpers');
////////////////////////////////////////////////////////////
// Build //
@@ -173,9 +173,9 @@ function stripApacheLicense() {
}
/**
* Closure compiler diagnostic groups we want to be treated as errors.
* Closure Compiler diagnostic groups we want to be treated as errors.
* These are effected when the --debug or --strict flags are passed.
* For a full list of closure compiler groups, consult the output of
* For a full list of Closure Compiler groups, consult the output of
* google-closure-compiler --help or look in the source here:
* https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/DiagnosticGroups.java#L117
*
@@ -185,7 +185,7 @@ function stripApacheLicense() {
* appearing on any list will default to setting provided by the
* compiler, which may vary depending on compilation level.
*/
var JSCOMP_ERROR = [
const JSCOMP_ERROR = [
// 'accessControls', // Deprecated; means same as visibility.
// 'checkPrototypalTypes', // override annotations are stripped by tsc.
'checkRegExp',
@@ -235,25 +235,25 @@ var JSCOMP_ERROR = [
];
/**
* Closure compiler diagnostic groups we want to be treated as warnings.
* Closure Compiler diagnostic groups we want to be treated as warnings.
* These are effected when the --debug or --strict flags are passed.
*
* For most (all?) diagnostic groups this is the default level, so
* it's generally sufficient to remove them from JSCOMP_ERROR.
*/
var JSCOMP_WARNING = [
const JSCOMP_WARNING = [
];
/**
* Closure compiler diagnostic groups we want to be ignored. These
* Closure Compiler diagnostic groups we want to be ignored. These
* suppressions are always effected by default.
*
* Make sure that anything added here is commented out of JSCOMP_ERROR
* above, as that takes precedence.)
*/
var JSCOMP_OFF = [
const JSCOMP_OFF = [
/* The removal of Closure type system types from our JSDoc
* annotations means that the closure compiler now generates certain
* annotations means that the Closure Compiler now generates certain
* diagnostics because it no longer has enough information to be
* sure that the input code is correct. The following diagnostic
* groups are turned off to suppress such errors.
@@ -315,6 +315,7 @@ function buildJavaScript(done) {
execSync(
`tsc -outDir "${TSC_OUTPUT_DIR}" -declarationDir "${TYPINGS_BUILD_DIR}"`,
{stdio: 'inherit'});
execSync(`node scripts/tsick.js "${TSC_OUTPUT_DIR}"`, {stdio: 'inherit'});
done();
}
@@ -452,7 +453,7 @@ function buildLangfiles(done) {
}
/**
* A helper method to return an closure compiler chunk wrapper that
* A helper method to return an Closure Compiler chunk wrapper that
* wraps the compiler output for the given chunk in a Universal Module
* Definition.
*/
@@ -612,7 +613,7 @@ function getChunkOptions() {
const pathSepRegExp = new RegExp(path.sep.replace(/\\/, '\\\\'), "g");
/**
* Helper method for calling the Closure compiler, establishing
* Helper method for calling the Closure Compiler, establishing
* default options (that can be overridden by the caller).
* @param {*} options Caller-supplied options that will override the
* defaultOptions.
@@ -663,7 +664,7 @@ function buildCompiled() {
const packageJson = getPackageJson(); // For version number.
const options = {
// The documentation for @define claims you can't use it on a
// non-global, but the closure compiler turns everything in to a
// non-global, but the Closure Compiler turns everything in to a
// global - you just have to know what the new name is! With
// declareLegacyNamespace this was very straightforward. Without
// it, we have to rely on implmentation details. See
@@ -688,11 +689,19 @@ function buildCompiled() {
/**
* This task builds Blockly core, blocks and generators together and uses
* closure compiler's ADVANCED_COMPILATION mode.
* Closure Compiler's ADVANCED_COMPILATION mode.
*
* Prerequisite: buildDeps.
*/
function buildAdvancedCompilationTest() {
// If main_compressed.js exists (from a previous run) delete it so that
// a later browser-based test won't check it should the compile fail.
try {
fs.unlinkSync('./tests/compile/main_compressed.js');
} catch (_e) {
// Probably it didn't exist.
}
const srcs = [
TSC_OUTPUT_DIR + '/closure/goog/base_minimal.js',
TSC_OUTPUT_DIR + '/closure/goog/goog.js',