From 65d8c23628947dad7c5c5396890f2b84ea11250c Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Tue, 28 Feb 2023 23:05:50 -0800 Subject: [PATCH] Updates resource injector tests to be ESM-compatible. Refs #33. This mostly required dropping the Jasmine spy on the `fs` module. --- tools/binaries/resource_injector/BUILD.bazel | 4 ++-- tools/binaries/resource_injector/injector.ts | 14 +++++++++----- tools/binaries/resource_injector/injector_test.ts | 11 +++++++---- .../resource_injector/resource_injector_test.ts | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/binaries/resource_injector/BUILD.bazel b/tools/binaries/resource_injector/BUILD.bazel index 6c557fa5..095e14f7 100644 --- a/tools/binaries/resource_injector/BUILD.bazel +++ b/tools/binaries/resource_injector/BUILD.bazel @@ -53,7 +53,7 @@ ts_project( data = ["//:node_modules/node-html-parser"], deps = [ ":config", - "//common:fs", + "//common:file_system", "//common:prerender_annotation_walker", ], ) @@ -65,7 +65,7 @@ ts_project( deps = [ ":config", ":injector", - "//common:fs", + "//common:file_system_fake", "//common/models:prerender_annotation", "//:node_modules/@types/jasmine", ], diff --git a/tools/binaries/resource_injector/injector.ts b/tools/binaries/resource_injector/injector.ts index 6cb613ed..a815243c 100644 --- a/tools/binaries/resource_injector/injector.ts +++ b/tools/binaries/resource_injector/injector.ts @@ -1,7 +1,7 @@ -import * as fs from '../../../common/fs'; import { HTMLElement, parse } from 'node-html-parser'; import { InjectorConfig, InjectScript } from './config'; import { AnnotationNode, walkAllAnnotations } from '../../../common/prerender_annotation_walker'; +import { FileSystem, diskFs } from '../../../common/file_system'; /** * Parses the given HTML document and injects all the resources specified by the @@ -14,8 +14,11 @@ import { AnnotationNode, walkAllAnnotations } from '../../../common/prerender_an * injected into the HTML document. * @returns A new HTML document with all the resources injected into it. */ -export async function inject(html: string, config: InjectorConfig): - Promise { +export async function inject( + html: string, + config: InjectorConfig, + fs: FileSystem = diskFs, +): Promise { // Parse input HTML. const root = parse(html, { comment: true, @@ -40,7 +43,7 @@ export async function inject(html: string, config: InjectorConfig): } // Inject `