Skip to content

Fix Jest CI failures: TS1343 import.meta, TS2322 Badge variants, TS2367/TS2739 type errors#128

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ci-failures-20848630333
Draft

Fix Jest CI failures: TS1343 import.meta, TS2322 Badge variants, TS2367/TS2739 type errors#128
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ci-failures-20848630333

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Jest coverage collection was failing with TypeScript compilation errors on four source files due to ts-jest using CommonJS module defaults incompatible with Vite's ESNext/import.meta patterns.

Changes

tsconfig.test.json (new)

Dedicated Jest tsconfig extending tsconfig.app.json with overrides needed for ts-jest compatibility:

  • module: "ESNext" — allows import.meta syntax (fixes TS1343 in App.tsx, AIGameSuggestion.tsx)
  • moduleResolution: "node" — restores Node-style resolution (required for Jest; tsconfig.app.json uses "bundler")
  • noEmit: false, allowImportingTsExtensions: false — incompatible with ts-jest emit

jest.config.js

Migrated from deprecated globals['ts-jest'] to transform format, pointing to tsconfig.test.json:

transform: {
  '^.+\\.tsx?$': ['ts-jest', { tsconfig: './tsconfig.test.json' }],
},

src/components/GameDetail.tsx

Introduced BadgeVariant type alias and used it to type frameworkColorMap and knowledgeLevelColor directly — eliminating repeated inline union casts (TS2322):

type BadgeVariant = 'default' | 'secondary' | 'purple' | 'success' | 'warning' | 'danger' | 'outline';
const frameworkColorMap: Record<string, BadgeVariant> = { ... };

src/components/GameCreate.tsx

Removed always-false key === 'id' check — game is Omit<Game, 'id'>, so id is never a key (TS2367).

src/data/games.ts

Added missing required Game fields (learningOutcomes, isAccessible, requiredKnowledgeLevel) to all 5 sample game objects (TS2739).

Original prompt

Create a PR to fix CI failures shown in GitHub Actions job 59898111296 (run 20848630333) for PR #120 in lorettarehm/AgileGamifAI.

Context:

  • CI workflow: .github/workflows/ci.yml runs lint, typecheck, tests (npm run test:ci), and build.
  • Failing job logs show:
    1. Jest coverage collection fails with TS1343: import.meta not allowed under TS --module option for files:
      • src/components/AIGameSuggestion.tsx (import.meta usage)
      • src/App.tsx (import.meta.env usage)
    2. TypeScript error TS2322 in src/components/GameDetail.tsx: Badge variant expects union type but received string from Record<string, string> map.
    3. TypeScript error TS2739 in src/data/games.ts: sampleGames objects do not satisfy Game type (missing required properties).
    4. Build fails with Vite/PostCSS error: using tailwindcss directly as PostCSS plugin; must install @tailwindcss/postcss and update PostCSS config.

Repo state at commit ref d0eef38.

Tasks:

  1. Fix PostCSS/Tailwind build issue:

    • Update postcss.config.js to use '@tailwindcss/postcss' instead of 'tailwindcss'.
    • Add devDependency '@tailwindcss/postcss' to package.json/package-lock.
  2. Fix Jest coverage TS1343 import.meta issue:

    • Identify Jest configuration and transformer (ts-jest/babel/swc) used by npm run test:ci.
    • Ensure coverage collection does not typecheck with a TS module target that disallows import.meta.
    • Preferred: add a tsconfig for tests (e.g., tsconfig.jest.json) extending tsconfig.app.json with compilerOptions.module set to es2022 (or esnext) and moduleResolution compatible with Vite (bundler). Configure Jest/ts-jest to use it.
    • Alternative: adjust transformer config or exclude import.meta-using files from coverage if required.
  3. Fix src/components/GameDetail.tsx typing:

    • Replace Record<string, string> maps with properly typed variant union derived from Badge props (ComponentProps['variant']) so variant prop is type-safe.
  4. Fix src/data/games.ts type mismatch:

    • Update sampleGames entries to include all required Game fields referenced by UI (learningOutcomes, requiredKnowledgeLevel, isAccessible, accessibilityNotes, etc.) OR adjust Game type definition if those fields should be optional.
    • Ensure all sampleGames objects satisfy the Game type and TypeScript passes.

Acceptance criteria:

  • npm ci && npm run lint && npx tsc --noEmit && npm run test:ci && npm run build succeeds on Node 18 and 20 in GitHub Actions.
  • No TS errors during coverage collection.
  • Tailwind build passes.
  • PR contains only the necessary changes.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing for three concrete reasons shown in the logs (plus one noisy but non-failing console.error). Fix the items below and the CI run should go green.

1) Build fails: Tailwind used directly as a PostCSS plugin

Error (from logs):

[vite:css] [postcss] It looks like you're trying to use tailwindcss directly as a PostCSS plugin… install @tailwindcss/postcss and update your PostCSS…

Where: postcss.config.js at d0eef380f43552e79965fc93975b3f3893df76e3 currently has:

export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

Fix

  1. Install the new plugin package:
npm i -D @tailwindcss/postcss
  1. Update postcss.config.js to use @tailwindcss/postcss:
export default {
  plugins: {
    '@tailwindcss/postcss': {},
    autoprefixer: {},
  },
};

That resolves the Vite/PostCSS build failure.


2) Jest coverage collection fails: import.meta not allowed under current TS module settings

Error (from logs):

TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020' ... or 'node16' ...

This happens while collecting coverage from:

  • src/components/AIGameSuggestion.tsx
  • src/App.tsx

This is a TypeScript/Jest instrumentation issue: your test run is type-checking/transpiling files for coverage with a TS module target that doesn’t allow import.meta.

Fix (recommended): make the TS config used by tests allow import.meta

In a Vite app, your app TS config usually already uses an ES module target; the failure often comes from Jest/ts-jest using the “wrong” tsconfig defaults.

Create a dedicated tsconfig.jest.json (or update your existing Jest/ts-jest config to point at the app tsconfig) with a compatible module option:

tsconfig.jest.json

{
  "extends": "./tsconfig.app.json",
  "compilerOptions": {
    "module": "es2022",
    "moduleResolution": "bundler"
  }
}

Then in your Jest config (wherever it is in this repo), ensure ts-jest uses it, e.g.:

globals: {
  '...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)

Copilot AI changed the title [WIP] Fix CI failures in GitHub Actions job 59898111296 Fix Jest CI failures: TS1343 import.meta, TS2322 Badge variants, TS2367/TS2739 type errors Mar 30, 2026
Copilot AI requested a review from lorettarehm March 30, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants