kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
https://kulshekhar.github.io/ts-jest
MIT License
6.88k stars 447 forks source link

[Bug]: Tests fail only when running on Github Actions (locally runs fine) #4056

Open jsoneaday opened 1 year ago

jsoneaday commented 1 year ago

Version

28.0

Steps to reproduce

  1. Create yarn workspace with two workspaces inside packages folder
  2. Create test in first workspace that has a dependency on second workspace
  3. Run yarn test locally, no issue
  4. Run on Github Actions error: Unable to process '/home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts', please make sure that outDir in your tsconfig is neither '' or '.'. You can also configure Jest config option transformIgnorePatterns to inform ts-jest to transform /home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts

    at TsCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:165:27) at TsJestCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:13:39) at TsJestTransformer.processWithTs (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:232:37) at TsJestTransformer.process (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:161:24) at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:619:31) at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:765:40) at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:822:19)

Expected behavior

Should run to completion like it does on local machine.

Actual behavior

Fails saying it cannot process a typescript file. It would help to know what the precise failure in processing the typescript file is. My outDir is set (again it works locally)

Debug log

11s Run yarn test:core FAIL src/archwayclient-rewards.spec.ts ● Test suite failed to run

Unable to process '/home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform /home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts

  at TsCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:[1](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:1)65:27)
  at TsJestCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:13:39)
  at TsJestTransformer.processWithTs (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:232:37)
  at TsJestTransformer.process (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:161:2[4](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:5))
  at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:619:31)
  at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:76[5](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:6):40)
  at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:822:19)

FAIL src/archwayclient.spec.ts ● Test suite failed to run

Unable to process '/home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform /home/runner/work/arch3.js/arch3.js/packages/arch3-core/src/archwayclient.ts

  at TsCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:1[6](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:7)5:2[7](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:8))
  at TsJestCompiler.getCompiledOutput (../../node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:13:39)
  at TsJestTransformer.processWithTs (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:232:37)
  at TsJestTransformer.process (../../node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:161:24)
  at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:619:31)
  at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
  at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:[8](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:9)22:1[9](https://github.com/archway-network/arch3.js/actions/runs/4473280460/jobs/7860484202?pr=48#step:6:10))
------------------ --------- ---------- --------- --------- ------------------- File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 0 0 0 0
archwayclient.ts 0 0 0 0 1-138
index.ts 0 0 0 0 1-2
------------------ --------- ---------- --------- --------- -------------------

Test Suites: 2 failed, 2 total Tests: 0 total Snapshots: 0 total Time: 5.769 s Ran all test suites. Error: Process completed with exit code 1.

Additional context

Github runner is ubuntu latest

Environment

Here's my local machine setup and then the github action yml.

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 18.12.1 - /usr/local/bin/node
    Yarn: 3.2.1 - /usr/local/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
  npmPackages:
    jest: ^28.1 => 28.1.3 

name: Test

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: ["*"]

concurrency:
  group: ${{github.workflow}}-${{github.ref}}
  cancel-in-progress: true

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 14
          cache: yarn
      - run: yarn install --immutable
      - run: yarn build:all
      - run: yarn test:core
ArTiSTiX commented 10 months ago

I have a very similar issue. Tests are running ok locally (windows and macos, not tried ubuntu), but in a Github Actions workflow, i have the following message:

FAIL src/__tests__/App.test.tsx
  ● Test suite failed to run

    Unable to process '/home/runner/work/midi-jar/midi-jar/src/__tests__/App.test.tsx', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform /home/runner/work/midi-jar/midi-jar/src/__tests__/App.test.tsx

      at TsCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:173:27)
      at TsJestCompiler.getCompiledOutput (node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:14:39)
      at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.processWithTs (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:265:37)
      at TsJestTransformer.exports.TsJestTransformer.TsJestTransformer.process (node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:188:[24](https://github.com/la-jarre-a-son/midi-jar/actions/runs/6013973240/job/16312644447#step:9:25))
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:7[26](https://github.com/la-jarre-a-son/midi-jar/actions/runs/6013973240/job/16312644447#step:9:27):19)

The test:

import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import App from '../renderer/App';

describe('App', () => {
  it('should render', () => {
    expect(render(<App />)).toBeTruthy();
  });
});

Versions:

    "jest": "^29.6.4",,
    "ts-jest": "^29.1.1",

Config:

{
  "testEnvironment": "jsdom",
  "testEnvironmentOptions": {
    "url": "http://localhost/"
  },
  "transform": {"\\.[jt]sx?$": "ts-jest"},
  "moduleNameMapper": {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/.erb/mocks/fileMock.js",
    "\\.(css|less|sass|scss)$": "identity-obj-proxy"
  },
  "moduleFileExtensions": [
    "js",
    "jsx",
    "ts",
    "tsx",
    "json"
  ],
  "moduleDirectories": [
    "node_modules",
    "release/app/node_modules",
    "src"
  ],
  "testMatch": [
    "**/*.test.[jt]s?(x)"
  ],
  "testPathIgnorePatterns": [
    "release/app/dist"
  ],
  "setupFiles": [
    "./.erb/scripts/check-build-exists.ts"
  ],
  "setupFilesAfterEnv": [
    "./src/__tests__/setup.ts"
  ]
}

TSConfig:

{
  "compilerOptions": {
    "incremental": true,
    "target": "es2015",
    "module": "commonjs",
    "lib": ["dom", "es2021"],
    "jsx": "react-jsx",
    "strict": true,
    "sourceMap": true,
    "baseUrl": "./src",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "allowJs": true,
    "skipLibCheck": true,
    "outDir": ".erb/dll",
  },
  "exclude": ["release/build", "release/app/dist", ".erb/dll"]
}

Funny thing (not so much): Github action fails if running windows-latest or ubuntu-latest, but passes when running macos-latest. I spent 2 days trying to reproduce locally, or fixing it without success. I just enabled tests only on macos-latest, until there is another workaround (or new ideas).

louisgv commented 5 months ago

Having the same issue but with snapshot testing. Local runs fine, but when running in -ci mode, jest couldn't find the snapshot file it seems...