Repository: tailwindlabs/tailwindcss
File: integrations/utils.ts (TypeScript)

Code before:
                return [file, content]
              }),
            )
          },
          async expectFileToContain(filePath, contents) {
            return retryUntil(async () => {
              let fileContent = await this.read(filePath)
              for (let content of contents) {
                expect(fileContent).toContain(content)
              }
            })
          },
        },
      } satisfies TestContext

      for (let [filename, content] of Object.entries(config.fs)) {
        await context.fs.write(filename, content)
      }

      try {
        // In debug mode, the directory is going to be inside the pnpm workspace
        // of the tailwindcss package. This means that `pnpm install` will run
        // pnpm install on the workspace instead (expect if the root dir defines
        // a seperate workspace). We work around this by using the
        // --ignore-workspace flag.
        let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
        context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
      } catch (error: any) {
        console.error(error)
        throw error
      }

      let disposables: (() => Promise<void>)[] = []

      async function dispose() {
        await Promise.all(disposables.map((dispose) => dispose()))

        // Skip removing the directory in CI beause it can stall on Windows
        if (!process.env.CI && !debug) {
          await fs.rm(root, { recursive: true, force: true })
        }
      }

      options.onTestFinished(dispose)

      return await testCallback(context)
    },
  )
}
test.only = (name: string, config: TestConfig, testCallback: TestCallback) => {
  return test(name, config, testCallback, { only: true })

Review comment (bug):
This fixes an unrelated problem when `test.debug` is used without setting up a custom pnpm workspace

Code after:
                return [file, content]
              }),
            )
          },
          async expectFileToContain(filePath, contents) {
            return retryUntil(async () => {
              let fileContent = await this.read(filePath)
              for (let content of contents) {
                expect(fileContent).toContain(content)
              }
            })
          },
        },
      } satisfies TestContext

      for (let [filename, content] of Object.entries(config.fs)) {
        await context.fs.write(filename, content)
      }

      try {
        // In debug mode, the directory is going to be inside the pnpm workspace
        // of the tailwindcss package. This means that `pnpm install` will run
        // pnpm install on the workspace instead (expect if the root dir defines
        // a separate workspace). We work around this by using the
        // `--ignore-workspace` flag.
        let ignoreWorkspace = debug && !config.fs['pnpm-workspace.yaml']
        context.exec(`pnpm install${ignoreWorkspace ? ' --ignore-workspace' : ''}`)
      } catch (error: any) {
        console.error(error)
        throw error
      }

      let disposables: (() => Promise<void>)[] = []

      async function dispose() {
        await Promise.all(disposables.map((dispose) => dispose()))

        // Skip removing the directory in CI beause it can stall on Windows
        if (!process.env.CI && !debug) {
          await fs.rm(root, { recursive: true, force: true })
        }
      }

      options.onTestFinished(dispose)

      return await testCallback(context)
    },
  )
}
test.only = (name: string, config: TestConfig, testCallback: TestCallback) => {
  return test(name, config, testCallback, { only: true })