Skip to content

Commit

Permalink
[Import Maps] Import tests
Browse files Browse the repository at this point in the history
This CL imports post-#176 upstream reference implementation's tests
into wpt/import-maps/imported/, and
executes them under virtual/import-maps-without-builtin-modules/.

The pre-#176 existing tests are still left under
wpt/import-maps/builtin-support.tentative/imported/, which are excluded
by this CL from virtual/import-maps-without-builtin-modules.

To match with the expectation of post-#176 tests,
this CL modifies ImportMap::ToString() to output
strings (not single-element arrays) as right hand side.

WICG/import-maps#176

Bug: 990561, 1010751
Change-Id: I652b35969d48e0147d07aa869ca3a97004f2f7a1
  • Loading branch information
hiroshige-g authored and chromium-wpt-export-bot committed Oct 15, 2019
1 parent 2bd57e0 commit 1422670
Show file tree
Hide file tree
Showing 23 changed files with 1,500 additions and 385 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/parsing-addresses.js
-->
<script type="module" src="resources/parsing-addresses.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/parsing-schema.js
-->
<script type="module" src="resources/parsing-schema.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/parsing-scope-keys.js
-->
<script type="module" src="resources/parsing-scope-keys.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/parsing-specifier-keys.js
-->
<script type="module" src="resources/parsing-specifier-keys.js"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/jest-test-helper.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/jest-test-helper.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/resolving-scopes.js
-->
<script type="module" src="resources/resolving-scopes.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/jest-test-helper.js"></script>
<script type="module" src="resources/helpers/parsing.js"></script>

<!--
Imported from https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/resolving.js
-->
<script type="module" src="resources/resolving.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
const { parseFromString } = require('../../lib/parser.js');

// Local modifications from upstream:
// Currently warnings and scopes are not checked in expectSpecifierMap().
exports.expectSpecifierMap = (input, baseURL, output, warnings = []) => {
expect(parseFromString(`{ "imports": ${input} }`, baseURL))
.toEqual({ imports: output, scopes: {} });
};

exports.expectScopes = (inputArray, baseURL, outputArray, warnings = []) => {
const checkWarnings = testWarningHandler(warnings);

const inputScopesAsStrings = inputArray.map(scopePrefix => `${JSON.stringify(scopePrefix)}: {}`);
const inputString = `{ "scopes": { ${inputScopesAsStrings.join(', ')} } }`;

const outputScopesObject = {};
for (const outputScopePrefix of outputArray) {
outputScopesObject[outputScopePrefix] = {};
}

expect(parseFromString(inputString, baseURL)).toEqual({ imports: {}, scopes: outputScopesObject });

checkWarnings();
};

exports.expectBad = (input, baseURL, warnings = []) => {
const checkWarnings = testWarningHandler(warnings);
expect(() => parseFromString(input, baseURL)).toThrow(TypeError);
checkWarnings();
};

exports.expectWarnings = (input, baseURL, output, warnings = []) => {
const checkWarnings = testWarningHandler(warnings);
expect(parseFromString(input, baseURL)).toEqual(output);

checkWarnings();
};

function testWarningHandler(expectedWarnings) {
// We don't check warnings on WPT tests, because there are no
// ways to catch console warnings from JavaScript.
return () => {};
}
Loading

0 comments on commit 1422670

Please sign in to comment.