Skip to content

Commit

Permalink
test(replace-remix-imports): fix shell.grep call
Browse files Browse the repository at this point in the history
previously, `shell.grep` was being called with the `-r` option, which it does not recognize,
resulting in an exit ode of 1. we incorrectly interpreted that as `grep` finishing the search
without finding matches. instead, the `shell.grep` call was crashing. now we correctly pass a list
of files to `shell.grep` without the `-r` option.
  • Loading branch information
pcattori committed May 11, 2022
1 parent 0b9bc02 commit 07821af
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/remix-dev/__tests__/replace-remix-imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import os from "os";
import stripAnsi from "strip-ansi";
import type { PackageJson } from "type-fest";
import shell from "shelljs";
import glob from "fast-glob";

import { run } from "../cli/run";
import { readConfig } from "../config";

let output: string;
const ORIGINAL_IO = {
Expand Down Expand Up @@ -72,6 +74,7 @@ const replaceRemixImports = async (projectDir: string) => {
describe("`replace-remix-imports` migration", () => {
it("runs successfully", async () => {
let projectDir = makeApp();
let config = await readConfig(projectDir);
await replaceRemixImports(projectDir);

expect(output).toContain("detected `@remix-run/node`");
Expand All @@ -96,9 +99,15 @@ describe("`replace-remix-imports` migration", () => {
expect(packageJson.scripts).not.toContain("postinstall");

expect(output).toContain("✅ Your Remix imports look good!");
let { code } = shell.grep("-nri", 'from "remix"', projectDir);
// `grep` exits with status code `1` when no matches are found
expect(code).toBe(1);

let files = glob.sync("**/*.@(ts|tsx|js|jsx)", {
cwd: config.appDirectory,
absolute: true,
});
let result = shell.grep("-l", 'from "remix"', files);
expect(result.stdout.trim()).toBe("");
expect(result.stderr).toBeNull();
expect(result.code).toBe(0);

expect(output).toContain("successfully migrated");
expect(output).toContain("npm install");
Expand Down

0 comments on commit 07821af

Please sign in to comment.