Skip to content

Commit

Permalink
Switch from cat to type on Windows (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg committed Oct 17, 2021
1 parent ebc5278 commit c5632ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/api/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const boundImporter = bind(importer, nativeImporterDependencies);
export const findConfigurationDependencies = {
exec: childProcessExec,
importer: boundImporter,
platform: process.platform,
};

export const findOriginalConfigurationsDependencies: FindOriginalConfigurationsDependencies = {
Expand Down
19 changes: 15 additions & 4 deletions src/input/findPackagesConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { createStubExec } from "../adapters/exec.stubs";
import { findPackagesConfiguration } from "./findPackagesConfiguration";

describe("findPackagesConfiguration", () => {
it("defaults the configuration file when one isn't provided", async () => {
it("defaults the configuration file with cat when one isn't provided on a non-Windows platform", async () => {
// Arrange
const dependencies = { exec: createStubExec() };
const dependencies = { exec: createStubExec(), platform: "darwin" };

// Act
await findPackagesConfiguration(dependencies, undefined);
Expand All @@ -13,9 +13,20 @@ describe("findPackagesConfiguration", () => {
expect(dependencies.exec).toHaveBeenLastCalledWith(`cat "./package.json"`);
});

it("defaults the configuration file with type when one isn't provided on a Windows platform", async () => {
// Arrange
const dependencies = { exec: createStubExec(), platform: "win32" };

// Act
await findPackagesConfiguration(dependencies, undefined);

// Assert
expect(dependencies.exec).toHaveBeenLastCalledWith(`type "./package.json"`);
});

it("includes a configuration file in the packages command when one is provided", async () => {
// Arrange
const dependencies = { exec: createStubExec() };
const dependencies = { exec: createStubExec(), platform: "darwin" };
const config = "./custom/package.json";

// Act
Expand All @@ -27,7 +38,7 @@ describe("findPackagesConfiguration", () => {

it("applies packages defaults when none are provided", async () => {
// Arrange
const dependencies = { exec: createStubExec({ stdout: "{}" }) };
const dependencies = { exec: createStubExec({ stdout: "{}" }), platform: "darwin" };
const config = "./package.json";

// Act
Expand Down
2 changes: 1 addition & 1 deletion src/input/findPackagesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const findPackagesConfiguration = async (
): Promise<PackagesConfiguration | Error> => {
const rawConfiguration = await findReportedConfiguration<PackagesConfiguration>(
dependencies.exec,
"cat",
dependencies.platform === "win32" ? "type" : "cat",
config ?? "./package.json",
);

Expand Down
1 change: 1 addition & 0 deletions src/input/findReportedConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type DeepPartial<T> = {

export type FindReportedConfigurationDependencies = {
exec: Exec;
platform: string;
};

export const findReportedConfiguration = async <Configuration>(
Expand Down
11 changes: 7 additions & 4 deletions src/input/findTypeScriptConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ describe("findTypeScriptConfiguration", () => {
it("returns an error when one occurs", async () => {
// Arrange
const message = "error";
const dependencies = { exec: createStubThrowingExec({ stderr: message }) };
const dependencies = {
exec: createStubThrowingExec({ stderr: message }),
platform: "darwin",
};

// Act
const result = await findTypeScriptConfiguration(dependencies, undefined);
Expand All @@ -20,7 +23,7 @@ describe("findTypeScriptConfiguration", () => {

it("defaults the configuration file when one isn't provided", async () => {
// Arrange
const dependencies = { exec: createStubExec() };
const dependencies = { exec: createStubExec(), platform: "darwin" };

// Act
await findTypeScriptConfiguration(dependencies, undefined);
Expand All @@ -31,7 +34,7 @@ describe("findTypeScriptConfiguration", () => {

it("includes a configuration file in the TypeScript command when one is provided", async () => {
// Arrange
const dependencies = { exec: createStubExec() };
const dependencies = { exec: createStubExec(), platform: "darwin" };
const config = "./custom/tsconfig.json";

// Act
Expand All @@ -45,7 +48,7 @@ describe("findTypeScriptConfiguration", () => {

it("applies TypeScript defaults when none are provided", async () => {
// Arrange
const dependencies = { exec: createStubExec({ stdout: "{}" }) };
const dependencies = { exec: createStubExec({ stdout: "{}" }), platform: "darwin" };
const config = "./tsconfig.json";

// Act
Expand Down

0 comments on commit c5632ae

Please sign in to comment.