Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add initial source map ecma426 coverage #56436

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -609,6 +609,10 @@ test-debug: BUILDTYPE_LOWER=debug ## Run tests on a debug build.
test-release test-debug: test-build ## Run tests on a release or debug build.
$(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER)

.PHONY: test-test426
test-test426: all ## Run the Web Platform Tests.
$(PYTHON) tools/test.py $(PARALLEL_ARGS) test426

.PHONY: test-wpt
test-wpt: all ## Run the Web Platform Tests.
$(PYTHON) tools/test.py $(PARALLEL_ARGS) wpt
14 changes: 14 additions & 0 deletions test/fixtures/test426/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The Source Map Tests suite ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://www.ecma-international.org/ipr FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS*.

Copyright (c) 2024, Ecma International
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* Ecma International Standards hereafter means Ecma International Standards as well as Ecma Technical Reports
55 changes: 55 additions & 0 deletions test/fixtures/test426/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Source Map Tests

This repository holds testing discussions and tests for the the Source Map debugging format. Specifically, we're looking to encourage discussion around:

- Manual and automated testing strategies for Source Maps
- Gathering a list of Soure Map generators and consumers
- General discussion around deviations between source maps

Open discussion happens in the [GitHub issues](https://github.com/source-map/source-map-tests/issues).

Source Map spec:
* Repo: https://github.com/tc39/source-map
* Rendered spec: https://tc39.es/source-map/

## Test cases

This repo also contains cross-implementation test cases that can be run in test
suites for source map implementations, including browser devtool and library test
suites.

### Running the tests

#### Tools

[Source map validator](https://github.com/jkup/source-map-validator):
* The tests are included in the validator test suite [here](https://github.com/jkup/source-map-validator/blob/main/src/spec-tests.test.ts). You can run them with `npm test`.

#### Browsers

The tests for Firefox are in the Mozilla [source-map](https://github.com/mozilla/source-map) library:
* The upstream repo has a [test file](https://github.com/mozilla/source-map/blob/master/test/test-spec-tests.js) for running the spec tests from this repo. They can be run with `npm test`.

How to run in WebKit:
* Check out [WebKit](https://github.com/WebKit/WebKit/)
* `cd` to the checked out WebKit directory.
* Run `git am <this-repo>/webkit/0001-Add-harness-for-source-maps-spec-tests.patch`
* Run `Tools/Scripts/build-webkit` (depending on the platform you may need to pass `--gtk` or other flags)
* Run `Tools/Scripts/run-webkit-tests LayoutTests/inspector/model/source-map-spec.html` (again, you may need `--gtk` on Linux)

How to run in Chrome Devtools:
1. Setup:
* Install depot_tools following this [depot_tools guide](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)
* Check out [Chrome Devtools](https://chromium.googlesource.com/devtools/devtools-frontend):
* Run `gclient config https://chromium.googlesource.com/devtools/devtools-frontend --unmanaged`
* Run `cd devtools-frontend`
* Run `gclient sync`
* Run `gn gen out/Default`
2. Build:
* Run `autoninja -C out/Default`
3. Test:
* Run `npm run auto-unittest`
4. Apply patches from this repo:
* Run `git apply <path to .patch file>` in `devtools-frontend` repo

More information about running Chrome Devtools without building Chromium can be found [here](https://chromium.googlesource.com/devtools/devtools-frontend/+/refs/heads/chromium/3965/README.md)
3,867 changes: 3,867 additions & 0 deletions test/fixtures/test426/chrome/0001-Add-source-map-specification-tests.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From bebeda0b8133fc8f44382e59edda9203c980e8f3 Mon Sep 17 00:00:00 2001
From: Asumu Takikawa <asumu@igalia.com>
Date: Thu, 11 Jul 2024 16:44:29 -0700
Subject: [PATCH 2/2] Add reverse mapping code to test

---
front_end/core/sdk/SourceMapSpec.test.ts | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/front_end/core/sdk/SourceMapSpec.test.ts b/front_end/core/sdk/SourceMapSpec.test.ts
index 93b26a2e13..402b82e4c0 100644
--- a/front_end/core/sdk/SourceMapSpec.test.ts
+++ b/front_end/core/sdk/SourceMapSpec.test.ts
@@ -12,7 +12,6 @@

**/

-const {assert} = chai;
import type * as Platform from '../platform/platform.js';
import {assertNotNullOrUndefined} from '../platform/platform.js';
import { SourceMapV3, parseSourceMap } from './SourceMap.js';
@@ -170,6 +169,21 @@ describeWithEnvironment('SourceMapSpec', () => {
assert.strictEqual(nullish(actual.sourceURL), originalSource, 'unexpected source URL');
assert.strictEqual(nullish(actual.sourceLineNumber), originalLine, 'unexpected source line number');
assert.strictEqual(nullish(actual.sourceColumnNumber), originalColumn, 'unexpected source column number');
+
+ if (originalSource != null) {
+ let reverseEntries = sourceMap.findReverseEntries(
+ originalSource as Platform.DevToolsPath.UrlString,
+ originalLine,
+ originalColumn
+ );
+
+ const anyEntryMatched = reverseEntries.some((entry) => {
+ return entry.sourceURL === originalSource &&
+ entry.sourceLineNumber === originalLine &&
+ entry.sourceColumnNumber === originalColumn;
+ });
+ assert.isTrue(anyEntryMatched, `expected any matching reverse lookup entry, got none`);
+ }
}
});
}
--
2.39.2

2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/basic-mapping-as-index-map.js
15 changes: 15 additions & 0 deletions test/fixtures/test426/resources/basic-mapping-as-index-map.js.map
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/basic-mapping-original.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function foo() {
return 42;
}
function bar() {
return 24;
}
foo();
bar();
2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/basic-mapping.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/basic-mapping.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/file-not-a-string-1.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/file-not-a-string-1.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/file-not-a-string-2.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/file-not-a-string-2.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/ignore-list-empty.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/ignore-list-empty.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/ignore-list-valid-1.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/ignore-list-valid-1.js.map
15 changes: 15 additions & 0 deletions test/fixtures/test426/resources/index-map-file-wrong-type-1.js.map
15 changes: 15 additions & 0 deletions test/fixtures/test426/resources/index-map-file-wrong-type-2.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/index-map-invalid-order.js
25 changes: 25 additions & 0 deletions test/fixtures/test426/resources/index-map-invalid-order.js.map
25 changes: 25 additions & 0 deletions test/fixtures/test426/resources/index-map-invalid-overlap.js.map
13 changes: 13 additions & 0 deletions test/fixtures/test426/resources/index-map-invalid-sub-map.js.map
2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/index-map-missing-file.js
14 changes: 14 additions & 0 deletions test/fixtures/test426/resources/index-map-missing-file.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/index-map-missing-map.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/index-map-missing-map.js.map
14 changes: 14 additions & 0 deletions test/fixtures/test426/resources/index-map-missing-offset.js.map
15 changes: 15 additions & 0 deletions test/fixtures/test426/resources/index-map-wrong-type-offset.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/mappings-missing.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/mappings-missing.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/names-missing.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/names-missing.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/names-not-a-list-1.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/names-not-a-list-1.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/names-not-a-list-2.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/names-not-a-list-2.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/names-not-string.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/names-not-string.js.map
4 changes: 4 additions & 0 deletions test/fixtures/test426/resources/second-source-original.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function baz() {
return "baz";
}
baz();
2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/source-root-resolution.js
9 changes: 9 additions & 0 deletions test/fixtures/test426/resources/source-root-resolution.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/sources-content-missing.js
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/sources-missing.js
5 changes: 5 additions & 0 deletions test/fixtures/test426/resources/sources-missing.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/sources-not-a-list-1.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/sources-not-a-list-1.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/sources-not-a-list-2.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/sources-not-a-list-2.js.map
2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/transitive-mapping.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/transitive-mapping.js.map
5 changes: 5 additions & 0 deletions test/fixtures/test426/resources/typescript-original.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type FooArg = string | number;
function foo(x : FooArg) {
return x;
}
foo("foo");
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/unrecognized-property.js
8 changes: 8 additions & 0 deletions test/fixtures/test426/resources/unrecognized-property.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/valid-mapping-large-vlq.js
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-missing.js
5 changes: 5 additions & 0 deletions test/fixtures/test426/resources/version-missing.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-not-a-number.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/version-not-a-number.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-numeric-string.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/version-numeric-string.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-too-high.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/version-too-high.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-too-low.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/version-too-low.js.map
1 change: 1 addition & 0 deletions test/fixtures/test426/resources/version-valid.js
6 changes: 6 additions & 0 deletions test/fixtures/test426/resources/version-valid.js.map
4 changes: 4 additions & 0 deletions test/fixtures/test426/resources/vlq-valid-negative-digit.js
2 changes: 2 additions & 0 deletions test/fixtures/test426/resources/vlq-valid-single-digit.js
7 changes: 7 additions & 0 deletions test/fixtures/test426/resources/vlq-valid-single-digit.js.map
1,596 changes: 1,596 additions & 0 deletions test/fixtures/test426/source-map-spec-tests.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions test/test426/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# test426 (Source Map Tests)

The tests here are drivers for running the [Source Map Tests][]. This test
suite ensures that the Node.js source map implementation conforms to the
[Source Map Specification][] ([ECMA426][]).

The [`test/fixtures/test426`](../fixtures/test426/) contains a copy of the set of
[Source Map Tests][] suite. The last updated hash is:

* <https://github.com/tc39/source-map-tests/commit/cbed127c46330ff4b52525e73b9356e2ad3d6369>

See the json files in [the `status` folder](./status) for prerequisites,
expected failures, and support status for specific tests.

[ECMA426]: https://tc39.es/ecma426/
[Source Map Specification]: https://github.com/tc39/ecma426
[Source Map Tests]: https://github.com/tc39/source-map-tests
14 changes: 14 additions & 0 deletions test/test426/status/source-map-spec-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"sourceRootResolution": {
"testActions": {
"skip": "sourceRoot is not supported"
}
},
"mappingSemanticsSingleFieldSegment": {
"testActions": {
"1": {
"skip": "Might be incorrect test"
}
}
}
}
58 changes: 58 additions & 0 deletions test/test426/test-source-map-spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';

import assert from 'node:assert';
import test from 'node:test';
import { SourceMap } from 'node:module';
import { readFileSync } from 'node:fs';

const specJson = fixtures.readSync('test426/source-map-spec-tests.json', 'utf8');
const spec = JSON.parse(specJson);

const kStatus = JSON.parse(readFileSync(new URL('./status/source-map-spec-tests.json', import.meta.url), 'utf8'));

const kActionRunner = {
checkMapping,
};

spec.tests.forEach((testSpec) => {
const sourceMapJson = fixtures.readSync(['test426/resources', testSpec.sourceMapFile], 'utf8');
const sourceMapPayload = JSON.parse(sourceMapJson);

test(testSpec.name, async (t) => {
let sourceMap;
try {
sourceMap = new SourceMap(sourceMapPayload);
} catch {
// Be lenient with invalid source maps. Some source maps are invalid spec-wise,
// let's try the best to parse them. Maybe a strict parsing mode can be introduced
// for future-proof source map format.
assert.ok(!testSpec.sourceMapIsValid);
return;
}
assert.ok(sourceMap);

const subtests = (testSpec.testActions ?? []).map((action, idx) => {
const testRunner = kActionRunner[action.actionType];
const testName = `action#${idx} - ${action.actionType}`;
if (testRunner == null) {
return t.test(testName, {
todo: true,
});
}
const skip = kStatus[testSpec.name]?.testActions?.skip || kStatus[testSpec.name]?.testActions?.[idx]?.skip;
return t.test(testName, {
skip,
}, testRunner.bind(null, sourceMap, action));
});

await Promise.all(subtests);
});
});

function checkMapping(sourceMap, action) {
const result = sourceMap.findEntry(action.generatedLine, action.generatedColumn);
assert.strictEqual(result.originalSource, action.originalSource);
assert.strictEqual(result.originalLine, action.originalLine);
assert.strictEqual(result.originalColumn, action.originalColumn);
}
6 changes: 6 additions & 0 deletions test/test426/testcfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import testpy

def GetConfiguration(context, root):
return testpy.ParallelTestConfiguration(context, root, 'test426')