Skip to content

Trick to get ah-next-plugin into AH monorepo without breaking jest... #491

@mfvargo

Description

@mfvargo

In upgrading to AH 29 I followed the advice and blew up the config subdir. (a bit questionable advice???) so I lost my next.ts. When I used the one from this README it took me a while to figure out why my jest tests would all fail with actionhero.start()

This is assuming a mono repo config with "api" and "web" subdirectories with AH running in api and next running in web...

In order for the jest tests to run in the actionhero api directory, you have to disable next so actionhero.start() will work in the tests. What I had before was a jest.setup.js in the api directory that says:

process.env.NEXT_DISABLED = "true";

The next.ts example in README.md does not skip enabling the plugin for tests.

// from src/config/next.ts
// learn more about the next.js app options here https://nextjs.org/docs/advanced-features/custom-server

const namespace = "next";

declare module "actionhero" {
  export interface ActionheroConfigInterface {
    [namespace]: ReturnType<typeof DEFAULT[typeof namespace]>;
  }
}

const env = process.env.NODE_ENV ? process.env.NODE_ENV : "development";

export const DEFAULT = {
  [namespace]: () => {
    return {
      enabled: true,
      dev: process.env.NEXT_DEVELOPMENT_MODE
        ? process.env.NEXT_DEVELOPMENT_MODE === "false"
          ? false
          : true
        : env === "development",
      quiet: false,
    };
  },
};

I had to change the logic on the enable: true line to read that NEXT_ENABLED from jest.setup.js and do

      enabled: process.env.NEXT_DISABLED === "true" ? false : true,

Now my jest tests will run in api. Maybe some note of this could be made in the README?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions