From 34195cf0237ca6d15440fb24d54943875d45d80f Mon Sep 17 00:00:00 2001 From: Hiroshige Hayashizaki Date: Tue, 3 Dec 2019 16:06:58 -0800 Subject: [PATCH] [Import Maps] Migrate Jest-based resolution tests into JSON-based tests This CL - Defines JSON test object format (see README.md) that describes the configurations and specifiers to be tested, - Implements the WPT test helper for executing the tests based on the JSON test objects (common-test-helper.js), - Converts Jest-based resolution tests into JSONs (with some refinement, and removing test cases depending on interoperability issues of underlying URL parsers), and - Removes imported resolution tests. The dependency to Blink internals remains after this CL. Removing this dependency is planned and discussed at https://github.com/WICG/import-maps/issues/170. Bug: 1026809, https://github.com/WICG/import-maps/issues/170 Change-Id: I993cc9cd7746d7175142f8296ac434571f5d7157 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1927852 Commit-Queue: Hiroshige Hayashizaki Reviewed-by: Domenic Denicola Cr-Commit-Position: refs/heads/master@{#721239} --- import-maps/common/README.md | 79 ++++++ import-maps/common/resolving.tentative.html | 23 ++ .../common/resources/common-test-helper.js | 163 ++++++++++++ .../common/resources/data-base-url.json | 17 ++ .../common/resources/empty-import-map.json | 56 +++++ .../common/resources/overlapping-entries.json | 25 ++ .../packages-via-trailing-slashes.json | 43 ++++ .../resources/scopes-exact-vs-prefix.json | 134 ++++++++++ import-maps/common/resources/scopes.json | 171 +++++++++++++ .../common/resources/tricky-specifiers.json | 43 ++++ .../common/resources/url-specifiers.json | 52 ++++ import-maps/common/tools/format_json.py | 27 ++ .../imported/resolving-scopes.tentative.html | 11 - import-maps/imported/resolving.tentative.html | 11 - .../imported/resources/resolving-scopes.js | 222 ----------------- import-maps/imported/resources/resolving.js | 232 ------------------ lint.whitelist | 1 + 17 files changed, 834 insertions(+), 476 deletions(-) create mode 100644 import-maps/common/README.md create mode 100644 import-maps/common/resolving.tentative.html create mode 100644 import-maps/common/resources/common-test-helper.js create mode 100644 import-maps/common/resources/data-base-url.json create mode 100644 import-maps/common/resources/empty-import-map.json create mode 100644 import-maps/common/resources/overlapping-entries.json create mode 100644 import-maps/common/resources/packages-via-trailing-slashes.json create mode 100644 import-maps/common/resources/scopes-exact-vs-prefix.json create mode 100644 import-maps/common/resources/scopes.json create mode 100644 import-maps/common/resources/tricky-specifiers.json create mode 100644 import-maps/common/resources/url-specifiers.json create mode 100644 import-maps/common/tools/format_json.py delete mode 100644 import-maps/imported/resolving-scopes.tentative.html delete mode 100644 import-maps/imported/resolving.tentative.html delete mode 100644 import-maps/imported/resources/resolving-scopes.js delete mode 100644 import-maps/imported/resources/resolving.js diff --git a/import-maps/common/README.md b/import-maps/common/README.md new file mode 100644 index 00000000000000..cda42d06099f16 --- /dev/null +++ b/import-maps/common/README.md @@ -0,0 +1,79 @@ +# Import maps test JSON format + +In this directory, test inputs and expectations are expressed as JSON files. +This is in order to share the same JSON files between WPT tests and Jest-based +tests for the reference JavaScript implementation at [WICG repository](https://github.com/WICG/import-maps/tree/master/reference-implementation). + +## Basics + +A **test object** describes a set of parameters (import maps and base URLs) and specifiers to be tested. +Each JSON file under [resources/](resources/) directory consists of a test object. +A minimum test object would be: + +```json +{ + "name": "Main test name", + "importMapBaseURL": "https://example.com/import-map-base-url/index.html", + "importMap": { + "imports": { + "a": "/mapped-a.mjs" + } + }, + "baseURL": "https://example.com/base-url/app.mjs", + "expectedResults": { + "a": "https://example.com/mapped-a.mjs", + "b": null + } +} +``` + +Required fields: + +- `name`: Test name. + - In WPT tests, this is used for the test name of `promise_test()` together with specifier to be resolved, like `"Main test name: a"`. +- `importMap` (object or string): the import map to be attached. +- `importMapBaseURL` (string): the base URL used for [parsing the import map](https://wicg.github.io/import-maps/#parse-an-import-map-string). +- `baseURL` (string): the base URL used in [resolving a specifier](https://wicg.github.io/import-maps/#resolve-a-module-specifier) for each specifiers. +- `expectedResults` (object; string to (string or null)): test cases. + - The keys are specifiers to be resolved. + - The values are expected resolved URLs. If `null`, resolution should fail. + +Optional fields: + +- `link` and `details` can be used for e.g. linking to specs or adding more detailed descriptions. + - Currently they are simply ignored by the WPT test helper. + +## Nesting and inheritance + +We can organize tests by nesting test objects. +A test object can contain child test objects (*subtests*) using `tests` field. +The Keys of the `tests` value are the names of subtests, and values are test objects. + +For example: + +```json +{ + "name": "Main test name", + "importMapBaseURL": "https://example.com/import-map-base-url/index.html", + "importMap": { + "imports": { + "a": "/mapped-a.mjs" + } + }, + "tests": { + "Subtest1": { + "baseURL": "https://example.com/base-url1/app.mjs", + "expectedResults": { "a": "https://example.com/mapped-a.mjs" } + }, + "Subtest2": { + "baseURL": "https://example.com/base-url2/app.mjs", + "expectedResults": { "b": null } + } + } +} +``` + +The top-level test object contains two sub test objects, named as `Subtest1` and `Subtest2`, respectively. + +Child test objects inherit fields from their parent test object. +In the example above, the child test objects specifies `baseURL` fields, while they inherits other fields (e.g. `importMapBaseURL`) from the top-level test object. diff --git a/import-maps/common/resolving.tentative.html b/import-maps/common/resolving.tentative.html new file mode 100644 index 00000000000000..c947232e06322a --- /dev/null +++ b/import-maps/common/resolving.tentative.html @@ -0,0 +1,23 @@ + + + + + + diff --git a/import-maps/common/resources/common-test-helper.js b/import-maps/common/resources/common-test-helper.js new file mode 100644 index 00000000000000..002c4b51fd06a6 --- /dev/null +++ b/import-maps/common/resources/common-test-helper.js @@ -0,0 +1,163 @@ +setup({allow_uncaught_exception : true}); + +// Creates a new Document (via