Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
test: add tests to path to package
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotus authored and Lotus committed Jul 13, 2021
1 parent ae39e32 commit 9a0e7da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands/changed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, flags } from "@oclif/command";
import chalk from "chalk";

import { findDiff } from "../changed/find-diff";
import { pathToPackage } from "../changed/path-to-package";
import { pathToPackage } from "../utils/path-to-package";
import { readConfig } from "../changed/read-config";

export default class Changed extends Command {
Expand Down
37 changes: 37 additions & 0 deletions src/utils/path-to-package.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import chalk from "chalk";
import jsonfile from "jsonfile";
import path from "path";

import { pathToPackage } from "./path-to-package";

describe("Path to package", () => {
afterEach(() => jest.restoreAllMocks());

test("Successful read", () => {
jest.spyOn(jsonfile, "readFileSync").mockImplementation(() => {
return { name: "Test Package" };
});

const names = pathToPackage([path.join("src", "test")]);
expect(names).toEqual(["Test Package"]);
});

test("Unsuccessful read", () => {
const result: any = [];
jest
.spyOn(process.stdout, "write")
.mockImplementation(val => result.push(String(val).trim()));

const names = pathToPackage([path.join("src", "test")]);
expect(names).toEqual([]);
expect(result).toEqual([
chalk.red(
`${path.join(
"src",
"test",
"package.json"
)} may have been removed. Not publishing.`
),
]);
});
});
File renamed without changes.

0 comments on commit 9a0e7da

Please sign in to comment.