{"size": 1675, "ext": "js", "max_stars_repo_path": "test/windows-test-app/parseResources.test.js", "max_stars_repo_name": "Shivakumar-SG/react-native-test-app", "max_stars_repo_stars_event_min_datetime": "2021-07-06T01:59:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T01:59:34.000Z", "max_issues_repo_path": "test/windows-test-app/parseResources.test.js", "max_issues_repo_name": "Shivakumar-SG/react-native-test-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/windows-test-app/parseResources.test.js", "max_forks_repo_name": "Shivakumar-SG/react-native-test-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.9166666667, "max_line_length": 76, "alphanum_fraction": 0.5755223881}
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//
// @ts-check

jest.mock("fs");

describe("parseResources", () => {
  const { mockFiles } = require("../mockFiles");
  const { parseResources } = require("../../windows/test-app");

  afterEach(() => mockFiles());

  test("returns empty strings for no resources", () => {
    expect(parseResources(undefined, "", "")).toEqual(["", ""]);
    expect(parseResources([], "", "")).toEqual(["", ""]);
    expect(parseResources({}, "", "")).toEqual(["", ""]);
    expect(parseResources({ windows: [] }, "", "")).toEqual(["", ""]);
  });

  test("returns references to existing assets", () => {
    mockFiles(["dist/assets", "directory"], ["dist/main.jsbundle", "text"]);

    expect(
      parseResources(
        ["dist/assets", "dist/main.jsbundle"],
        ".",
        "node_modules/.generated/windows/ReactTestApp"
      )
    ).toEqual([
      "../../../../dist/assets\\**\\*;",
      "../../../../dist/main.jsbundle;",
    ]);
  });

  test("skips missing assets", () => {
    const warnSpy = jest.spyOn(global.console, "warn").mockImplementation();

    expect(
      parseResources(
        ["dist/assets", "dist/main.bundle"],
        ".",
        "node_modules/.generated/windows/ReactTestApp"
      )
    ).toEqual(["", ""]);

    expect(warnSpy).toHaveBeenCalledWith(
      "warning: resource with path 'dist/assets' was not found"
    );
    expect(warnSpy).toHaveBeenCalledWith(
      "warning: resource with path 'dist/main.bundle' was not found"
    );

    warnSpy.mockRestore();
  });
});
