mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor: update service-worker tests to work with ESM (#48538)
* Updates circular dependency tests to use the `.mjs` outputs * Switches away from CommonJS specific `require` calls. * Simplifies the test helper logic since all browsers/NodeJS versions support `URL` as a global. PR Close #48538
This commit is contained in:
@@ -3,7 +3,7 @@ load("//tools/circular_dependency_test:index.bzl", "circular_dependency_test")
|
||||
|
||||
circular_dependency_test(
|
||||
name = "circular_deps_test",
|
||||
entry_point = "angular/packages/service-worker/config/index.js",
|
||||
entry_point = "angular/packages/service-worker/config/index.mjs",
|
||||
deps = ["//packages/service-worker/config"],
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ load("//tools/circular_dependency_test:index.bzl", "circular_dependency_test")
|
||||
|
||||
circular_dependency_test(
|
||||
name = "circular_deps_test",
|
||||
entry_point = "angular/packages/service-worker/index.js",
|
||||
entry_point = "angular/packages/service-worker/index.mjs",
|
||||
deps = ["//packages/service-worker"],
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ load("//tools/circular_dependency_test:index.bzl", "circular_dependency_test")
|
||||
|
||||
circular_dependency_test(
|
||||
name = "circular_deps_test",
|
||||
entry_point = "angular/packages/service-worker/worker/main.js",
|
||||
entry_point = "angular/packages/service-worker/worker/main.mjs",
|
||||
deps = ["//packages/service-worker/worker:main"],
|
||||
)
|
||||
|
||||
|
||||
@@ -15,19 +15,7 @@ import {NormalizedUrl} from '../src/api';
|
||||
* @return Whether ServiceWorker tests can be run in the current environment.
|
||||
*/
|
||||
export function envIsSupported(): boolean {
|
||||
if (typeof URL === 'function') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we're in a browser that doesn't support URL at this point, don't go any further
|
||||
// since browser builds use requirejs which will fail on the `require` call below.
|
||||
if (typeof window !== 'undefined' && window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// In older Node.js versions, the `URL` global does not exist. We can use `url` instead.
|
||||
const url = (typeof require === 'function') && require('url');
|
||||
return url && (typeof url.parse === 'function') && (typeof url.resolve === 'function');
|
||||
return typeof URL === 'function';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,9 +43,7 @@ export function normalizeUrl(url: string, relativeTo: string): NormalizedUrl {
|
||||
*/
|
||||
export function parseUrl(
|
||||
url: string, relativeTo?: string): {origin: string, path: string, search: string} {
|
||||
const parsedUrl: URL = (typeof URL === 'function') ?
|
||||
(!relativeTo ? new URL(url) : new URL(url, relativeTo)) :
|
||||
require('url').parse(require('url').resolve(relativeTo || '', url));
|
||||
const parsedUrl: URL = (!relativeTo ? new URL(url) : new URL(url, relativeTo));
|
||||
|
||||
return {
|
||||
origin: parsedUrl.origin || `${parsedUrl.protocol}//${parsedUrl.host}`,
|
||||
|
||||
Reference in New Issue
Block a user