feat(tests): Add a test to validate scripts/migration/renamings.js (#5980)

* feat(tests): Add a test script for the renamings file

* Make scripts/migration/renamings.js a valid JSON5 file.
* Add a schema for it in tests/migration/renamings-schema.json.
* Add a script to test one against the other, as
  tests/migration/validate-renamings.  It is a node.js script
  that will exit 0 if the renamings file is valid, or 1 if it
  is not (and print a not-very-helpful error message from which
  is possible, with some effort, to deduce what the error is.)

* fix: convert to JSON5 and refactor example

* fix: convert keys to new key names

* fix: change versions to arrays instead of objects

* fix: fix version numbers

* fix: associate renames with the version where they were added

* fix: fixup example

* fix: put older renames at the bottom, and newer renames at the top

* fix: enable renamings test in run_all_tests

* fix: put newer renames back at the bottom

This reverts commit efe070e344.

* fix(tests): add missing additionalProperties: false to schema

And fix the resulting validation error in the example entry.

* chore(tests): Improve wording of example entry; add extra examples

Tweaked line wrapping of some existing entries (example and
acutal) that were otherwise untouched.

* feat: add dropDownDiv renaming to new database

* feat(tests): Check for duplicate entries for the same module

Also fixed extraneous whitespace in run_all_tests.sh

* fix(tests): Make validate-renamings.js compatible with node.js v12

Also remove success message, to adhere to usual unix convention
(silence implies success) as eslint does, and reduce unecessary
npm test output clutter.

* fix(tests): Fixes for PR #5980

* Fix typos.
* Remove redundant check.

Co-authored-by: Beka Westberg <bwestberg@google.com>
This commit is contained in:
Christopher Allen
2022-03-09 19:29:43 +00:00
committed by GitHub
parent 01d45972d4
commit 3c723f0199
7 changed files with 1667 additions and 1084 deletions

193
package-lock.json generated
View File

@@ -15,6 +15,7 @@
"@blockly/block-test": "^2.0.1",
"@blockly/dev-tools": "^3.0.1",
"@blockly/theme-modern": "^2.1.1",
"@hyperjump/json-schema": "^0.18.4",
"@wdio/selenium-standalone-service": "^7.10.1",
"chai": "^4.2.0",
"clang-format": "^1.6.0",
@@ -36,6 +37,7 @@
"gulp-umd": "^2.0.0",
"http-server": "^14.0.0",
"js-green-licenses": "^3.0.0",
"json5": "^2.2.0",
"mocha": "^9.1.1",
"readline-sync": "^1.4.10",
"rimraf": "^3.0.2",
@@ -371,6 +373,68 @@
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
"dev": true
},
"node_modules/@hyperjump/json-pointer": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/@hyperjump/json-pointer/-/json-pointer-0.9.2.tgz",
"integrity": "sha512-PGCyTWO+WTkNWhMdlgE7OiQYPVkme9/e6d7K2xiZxH1wMGxGgZEEDNCe8hox7rkuD1equ4eZM+K3eoPCexckmA==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"just-curry-it": "^3.2.1"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/jdesrosiers"
}
},
"node_modules/@hyperjump/json-schema": {
"version": "0.18.4",
"resolved": "https://registry.npmjs.org/@hyperjump/json-schema/-/json-schema-0.18.4.tgz",
"integrity": "sha512-FVdSlOrOio/sWCbVbAP3yH/gKKddvrIvKzLS/id6/CidWH0r0x5ZTPM1zBS0Su7gU6OOjFRxDYhrIhnNBI5ODg==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"@hyperjump/json-schema-core": "^0.23.4",
"fastest-stable-stringify": "^2.0.2"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/jdesrosiers"
}
},
"node_modules/@hyperjump/json-schema-core": {
"version": "0.23.6",
"resolved": "https://registry.npmjs.org/@hyperjump/json-schema-core/-/json-schema-core-0.23.6.tgz",
"integrity": "sha512-X0IzGRi5K4c91awB3xNt5bvbs34UyHwOpRKKFFJ2nWDWW7e22VNGvibqo/S2rdFyta3wqOHTICFNTQjjcVdIZg==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"@hyperjump/json-pointer": "^0.9.1",
"@hyperjump/pact": "^0.2.0",
"content-type": "^1.0.4",
"node-fetch": "^2.6.5",
"pubsub-js": "^1.9.1",
"url-resolve-browser": "^1.2.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/jdesrosiers"
}
},
"node_modules/@hyperjump/pact": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@hyperjump/pact/-/pact-0.2.1.tgz",
"integrity": "sha512-imzl9j1UiqM/HC3kgfS0/TdXcEFGFkq5EwjyaztLfdmia8KLBXGy3rC96K+nnyY+2fA69yA9HtnDappub5VSQQ==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"just-curry-it": "^3.1.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/jdesrosiers"
}
},
"node_modules/@sindresorhus/is": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz",
@@ -2799,6 +2863,15 @@
"node": ">=10"
}
},
"node_modules/content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
"dev": true,
"engines": {
"node": ">= 0.6"
}
},
"node_modules/convert-source-map": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz",
@@ -4230,6 +4303,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
},
"node_modules/fastest-stable-stringify": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/fastest-stable-stringify/-/fastest-stable-stringify-2.0.2.tgz",
"integrity": "sha512-bijHueCGd0LqqNK9b5oCMHc0MluJAx0cwqASgbWMvkO01lCYgIhacVRLcaDz3QnyYIRNJRDwMb41VuT6pHJ91Q==",
"dev": true
},
"node_modules/fd-slicer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
@@ -6995,6 +7074,21 @@
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"node_modules/json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"dev": true,
"dependencies": {
"minimist": "^1.2.5"
},
"bin": {
"json5": "lib/cli.js"
},
"engines": {
"node": ">=6"
}
},
"node_modules/jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
@@ -7021,6 +7115,12 @@
"node": ">=0.6.0"
}
},
"node_modules/just-curry-it": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/just-curry-it/-/just-curry-it-3.2.1.tgz",
"integrity": "sha512-Q8206k8pTY7krW32cdmPsP+DqqLgWx/hYPSj9/+7SYqSqz7UuwPbfSe07lQtvuuaVyiSJveXk0E5RydOuWwsEg==",
"dev": true
},
"node_modules/just-debounce": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/just-debounce/-/just-debounce-1.1.0.tgz",
@@ -9302,6 +9402,12 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"node_modules/pubsub-js": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/pubsub-js/-/pubsub-js-1.9.4.tgz",
"integrity": "sha512-hJYpaDvPH4w8ZX/0Fdf9ma1AwRgU353GfbaVfPjfJQf1KxZ2iHaHl3fAUw1qlJIR5dr4F3RzjGaWohYUEyoh7A==",
"dev": true
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
@@ -11589,6 +11695,12 @@
"node": ">=4"
}
},
"node_modules/url-resolve-browser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/url-resolve-browser/-/url-resolve-browser-1.2.0.tgz",
"integrity": "sha512-L9PBPnlKNDFzt9ElK4br8I8Tufdm1xgv1GhMeiP7ZC87x0b7mr+4vSh13kmPq5km80JKX+UD2BeEFTCrFZ6xDA==",
"dev": true
},
"node_modules/use": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",
@@ -12647,6 +12759,48 @@
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
"dev": true
},
"@hyperjump/json-pointer": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/@hyperjump/json-pointer/-/json-pointer-0.9.2.tgz",
"integrity": "sha512-PGCyTWO+WTkNWhMdlgE7OiQYPVkme9/e6d7K2xiZxH1wMGxGgZEEDNCe8hox7rkuD1equ4eZM+K3eoPCexckmA==",
"dev": true,
"requires": {
"just-curry-it": "^3.2.1"
}
},
"@hyperjump/json-schema": {
"version": "0.18.4",
"resolved": "https://registry.npmjs.org/@hyperjump/json-schema/-/json-schema-0.18.4.tgz",
"integrity": "sha512-FVdSlOrOio/sWCbVbAP3yH/gKKddvrIvKzLS/id6/CidWH0r0x5ZTPM1zBS0Su7gU6OOjFRxDYhrIhnNBI5ODg==",
"dev": true,
"requires": {
"@hyperjump/json-schema-core": "^0.23.4",
"fastest-stable-stringify": "^2.0.2"
}
},
"@hyperjump/json-schema-core": {
"version": "0.23.6",
"resolved": "https://registry.npmjs.org/@hyperjump/json-schema-core/-/json-schema-core-0.23.6.tgz",
"integrity": "sha512-X0IzGRi5K4c91awB3xNt5bvbs34UyHwOpRKKFFJ2nWDWW7e22VNGvibqo/S2rdFyta3wqOHTICFNTQjjcVdIZg==",
"dev": true,
"requires": {
"@hyperjump/json-pointer": "^0.9.1",
"@hyperjump/pact": "^0.2.0",
"content-type": "^1.0.4",
"node-fetch": "^2.6.5",
"pubsub-js": "^1.9.1",
"url-resolve-browser": "^1.2.0"
}
},
"@hyperjump/pact": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@hyperjump/pact/-/pact-0.2.1.tgz",
"integrity": "sha512-imzl9j1UiqM/HC3kgfS0/TdXcEFGFkq5EwjyaztLfdmia8KLBXGy3rC96K+nnyY+2fA69yA9HtnDappub5VSQQ==",
"dev": true,
"requires": {
"just-curry-it": "^3.1.0"
}
},
"@sindresorhus/is": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz",
@@ -14594,6 +14748,12 @@
}
}
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
"dev": true
},
"convert-source-map": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz",
@@ -15759,6 +15919,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
},
"fastest-stable-stringify": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/fastest-stable-stringify/-/fastest-stable-stringify-2.0.2.tgz",
"integrity": "sha512-bijHueCGd0LqqNK9b5oCMHc0MluJAx0cwqASgbWMvkO01lCYgIhacVRLcaDz3QnyYIRNJRDwMb41VuT6pHJ91Q==",
"dev": true
},
"fd-slicer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
@@ -17958,6 +18124,15 @@
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"dev": true,
"requires": {
"minimist": "^1.2.5"
}
},
"jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
@@ -17979,6 +18154,12 @@
"verror": "1.10.0"
}
},
"just-curry-it": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/just-curry-it/-/just-curry-it-3.2.1.tgz",
"integrity": "sha512-Q8206k8pTY7krW32cdmPsP+DqqLgWx/hYPSj9/+7SYqSqz7UuwPbfSe07lQtvuuaVyiSJveXk0E5RydOuWwsEg==",
"dev": true
},
"just-debounce": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/just-debounce/-/just-debounce-1.1.0.tgz",
@@ -19813,6 +19994,12 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"pubsub-js": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/pubsub-js/-/pubsub-js-1.9.4.tgz",
"integrity": "sha512-hJYpaDvPH4w8ZX/0Fdf9ma1AwRgU353GfbaVfPjfJQf1KxZ2iHaHl3fAUw1qlJIR5dr4F3RzjGaWohYUEyoh7A==",
"dev": true
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
@@ -21685,6 +21872,12 @@
"prepend-http": "^2.0.0"
}
},
"url-resolve-browser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/url-resolve-browser/-/url-resolve-browser-1.2.0.tgz",
"integrity": "sha512-L9PBPnlKNDFzt9ElK4br8I8Tufdm1xgv1GhMeiP7ZC87x0b7mr+4vSh13kmPq5km80JKX+UD2BeEFTCrFZ6xDA==",
"dev": true
},
"use": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",

View File

@@ -69,6 +69,7 @@
"@blockly/block-test": "^2.0.1",
"@blockly/dev-tools": "^3.0.1",
"@blockly/theme-modern": "^2.1.1",
"@hyperjump/json-schema": "^0.18.4",
"@wdio/selenium-standalone-service": "^7.10.1",
"chai": "^4.2.0",
"clang-format": "^1.6.0",
@@ -90,6 +91,7 @@
"gulp-umd": "^2.0.0",
"http-server": "^14.0.0",
"js-green-licenses": "^3.0.0",
"json5": "^2.2.0",
"mocha": "^9.1.1",
"readline-sync": "^1.4.10",
"rimraf": "^3.0.2",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,57 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/google/blockly/tests/migration/renamings-schema.json",
"title": "Renamings",
"description": "A file containing information about module and module export renamings",
"type": "object",
"patternProperties": {
"^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$": {"$ref": "#/$defs/version"}
},
"properties": {
"develop": {"$ref": "#/$defs/version"}
},
"additionalProperties": false,
"$defs": {
"version": {
"description": "All the renamings that happened in a paricular release.",
"type": "array",
"items": {
"description": "All the renamings in/of a particular module.",
"type": "object",
"properties": {
"oldName": {"$ref": "#/$defs/dottedIdentifier"},
"newName": {"$ref": "#/$defs/dottedIdentifier"},
"newExport": {"$ref": "#/$defs/dottedIdentifier"},
"oldPath": {"$ref": "#/$defs/dottedIdentifier"},
"newPath": {"$ref": "#/$defs/dottedIdentifier"},
"exports": {
"description": "A list of the exports that have been renamed.",
"type": "object",
"patternProperties": {
"^[A-Za-z$_][A-Za-z0-9$_]*(\\.[A-Za-z$_][A-Za-z0-9$_]*)*$": {
"description": "A single renamed (or moved) export.",
"type": "object",
"properties": {
"newModule": {"$ref": "#/$defs/dottedIdentifier"},
"newExport": {"$ref": "#/$defs/dottedIdentifier"},
"oldPath": {"$ref": "#/$defs/dottedIdentifier"},
"newPath": {"$ref": "#/$defs/dottedIdentifier"},
"getMethod": {"$ref": "#/$defs/dottedIdentifier"},
"setMethod": {"$ref": "#/$defs/dottedIdentifier"}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"required": ["oldName"],
"additionalProperties": false
}
},
"dottedIdentifier": {
"type": "string",
"pattern": "^[A-Za-z$_][A-Za-z0-9$_]*(\\.[A-Za-z$_][A-Za-z0-9$_]*)*$"
}
}
}

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env node
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview A script to validate the renamings file
* (scripts/migration/renamings.json5) agaist the schema
* (renamings-schema.json).
*/
/* global require __dirname process */
const JsonSchema = require('@hyperjump/json-schema');
const JSON5 = require('json5');
const fs = require('fs');
const path = require('path');
/**
* Renaming schema filename.
* @type {string}
*/
const SCHEMA_FILENAME = path.join(__dirname, 'renamings-schema.json');
/**
* Renamings filename.
* @type {string}
*/
const RENAMINGS_FILENAME =
path.resolve(__dirname, '../../scripts/migration/renamings.json5');
// Can't use top-level await outside a module, and can't use require
// in a module, so use an IIAFE.
(async function() {
const schemaUrl = 'file://' + path.resolve(SCHEMA_FILENAME);
const schema = await JsonSchema.get(schemaUrl);
const renamingsJson5 = fs.readFileSync(RENAMINGS_FILENAME);
const renamings = JSON5.parse(renamingsJson5);
const output =
await JsonSchema.validate(schema, renamings, JsonSchema.DETAILED);
if (!output.valid) {
console.log('Renamings file is invalid.');
console.log('Maybe this validator output will help you find the problem:');
console.log(JSON5.stringify(output, undefined, ' '));
process.exit(1);
}
// File passed schema validation. Do some additional checks.
let ok = true;
Object.entries(renamings).forEach(([version, modules]) => {
// Scan through modules and check for duplicates.
const seen = new Set();
for (const {oldName} of modules) {
if (seen.has(oldName)) {
console.log(`Duplicate entry for module ${oldName} ` +
`in version ${version}.`);
ok = false;
}
seen.add(oldName);
}
});
if (!ok) {
console.log('Renamings file is invalid.');
process.exit(1);
}
// Default is a successful exit 0.
})();

View File

@@ -62,6 +62,9 @@ run_test_command "build-debug" "npm run build-debug"
# TODO(5621): Re-enable this test once typings generation is fixed.
# run_test_command "typings" "npm run typings"
# Run renaming validation test.
run_test_command "renamings" "tests/migration/validate-renamings.js"
# Check the sizes of built files for unexpected growth.
run_test_command "metadata" "tests/scripts/check_metadata.sh"
@@ -80,7 +83,6 @@ run_test_command "node" "./node_modules/.bin/mocha tests/node --config tests/nod
# Attempt advanced compilation of a Blockly app.
run_test_command "advanced_compile" "npm run test:compile:advanced"
# End of tests.
popd
echo "======================================="