Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-jest 23.xx.xx never finishes during CI tests but 22.xx.xx does #845

Closed
justinkchen opened this issue Nov 1, 2018 · 17 comments
Closed
Labels
🤷‍♂️ Needs More Info waiting for more information from author of the issue Performance Severe performance issue

Comments

@justinkchen
Copy link

Issue:

I've got a setup using CircleCI. The tests all pass locally but when I tried to upgrade to 23.10.4, the tests in CI say that it has been Too long with no output (exceeded 10m0s). The tests normally only take like 20 seconds. There is no error, but it just says that it has timed out. For some reason, it works totally fine with 22.0.1 though.

FYI, I'm using the command CI=true yarn test

Expected behavior:

Tests should end when running the from CI.

@huafu huafu added the 🤷‍♂️ Needs More Info waiting for more information from author of the issue label Nov 1, 2018
@huafu
Copy link
Collaborator

huafu commented Nov 1, 2018

Hi @jussikinnula, to be able to help you, we need more information, like your jest and ts config, project structure, ... or even better, a link to your repository, or to a minimal repository reproducing your issue.

@justinkchen
Copy link
Author

justinkchen commented Nov 1, 2018

I'm using an ejected version of create-react-app that is a little older than the current version. The tsconfig is

  "compilerOptions": {
    "outDir": "./build/",
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": false,
    "preserveConstEnums": true,
    "skipLibCheck": true
  },
  "include": [
    "./src/**/*"
  ]
}

I don't really know if I have any other custom jest configs though

@huafu
Copy link
Collaborator

huafu commented Nov 1, 2018

I don't really know if I have any other custom jest configs though

create-react-app does make some custom config, also CI=true yarn test is starting some script which itself starts jest with some specific options, without those, the help will be hard.

@lluzak
Copy link

lluzak commented Nov 8, 2018

Hi

After upgrading from 23.1.4 to 23.10.4, we are having the same problem on CircleCI. Locally with --no-cache option we are unable to reproduce it.

$ jest
 PASS  src/Creator/Common/lib/__tests__/FlowingTextTransformer.test.ts (15.356s)
 PASS  src/Creator/WildCard/reducers/__tests__/index.test.ts (15.754s)
 PASS  src/Core/components/__tests__/Experiment.test.tsx (61.291s)
  ● Console

    console.warn node_modules/styled-components/dist/styled-components.cjs.js:1713
      Warning: The "extend" API will be removed in the upcoming v4.0 release. Use styled(StyledComponent) instead. You can find more information here: https://github.com/styled-components/styled-components/issues/1546

 PASS  src/Creator/Common/components/StepFlow/__tests__/EditableLineLimitTextBox.test.tsx (61.272s)
  ● Console

    console.warn node_modules/styled-components/dist/styled-components.cjs.js:1713
      Warning: The "extend" API will be removed in the upcoming v4.0 release. Use styled(StyledComponent) instead. You can find more information here: https://github.com/styled-components/styled-components/issues/1546

 PASS  src/Creator/ImageSelection/lib/__tests__/image.test.ts (105.148s)
 PASS  src/Creator/BoomfBomb/reducers/__tests__/creator.test.ts (104.724s)
 PASS  src/Creator/ImageTool/__tests__/touch.test.ts (105.499s)
 PASS  src/Creator/ImageSelection/actions/__tests__/index.test.ts (104.958s)
 PASS  src/Creator/ImageTool/__tests__/Canvas.test.ts (106.152s)
 PASS  src/Creator/BoomfBomb/containers/__tests__/Header.test.tsx (147.178s)
  ● Console

    console.warn node_modules/styled-components/dist/styled-components.cjs.js:1713
      Warning: The "extend" API will be removed in the upcoming v4.0 release. Use styled(StyledComponent) instead. You can find more information here: https://github.com/styled-components/styled-components/issues/1546

 PASS  src/Creator/BoomfBalloon/containers/__tests__/Header.test.tsx (147.703s)
  ● Console

    console.warn node_modules/styled-components/dist/styled-components.cjs.js:1713
      Warning: The "extend" API will be removed in the upcoming v4.0 release. Use styled(StyledComponent) instead. You can find more information here: https://github.com/styled-components/styled-components/issues/1546

Too long with no output (exceeded 10m0s)

With each tests, time of running tests goes up, locally on my Macbook it always finish in around 120s.

Config of jest: ( for 23.10.4 we remove transformandmatchRegex` and replace it with preset )

  "jest": {
    "setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
    "unmockedModulePathPatterns": [
      "react",
      "enzyme",
      "jest-enzyme"
    ],
    "testEnvironmentOptions": {
      "resources": "usable"
    },
    "setupFiles": [
      "<rootDir>/test/setupTests.js"
    ],
    "moduleNameMapper": {
      "^([A-Z]{1}[a-z]+)/(.+)$": "<rootDir>/src/$1/$2",
      "@components/(.*)": "<rootDir>/src/Core/components/$1",
      "@components": "<rootDir>/src/Core/components",
      "^Authentication": "<rootDir>/src/Authentication",
      "^Home": "<rootDir>/src/Home",
      "^Shipping": "<rootDir>/src/Shipping",
      "^Products": "<rootDir>/src/Products",
      "^pages": "<rootDir>/src/pages",
      "^lib/(.*)": "<rootDir>/src/lib/$1",
      "^fixtures/(.*)\\.png": "<rootDir>/test/__fixtures__/$1.js",
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/__mocks__/fileMock.js",
      "\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js"
    },
    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!lodash-es)"
    ],
    "transform": {
      "^.+\\.js?$": "babel-jest",
      "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json"
    ],
    "globals": {
      "NODE_ENV": "test"
    }
  }

@justinkchen
Copy link
Author

So I was only able to "fix" it by going through a brand new create-react-app with all the scripts and packages updated and then ts-jest new version worked fine

@adrienharnay
Copy link

Hey, I have the same thing and I'm not using create-react-app. Here is my config, please let me know if I can provide more info:

jest.config.js

const path = require('path');
const { defaults } = require('jest-config');

const babelConfig = require('../../configs/.babelrc.base.js');

module.exports = {
  cacheDirectory: path.join(__dirname, 'node_modules/.cache/jest'),
  collectCoverageFrom: [
    '**/(utils|libs)/**/*.{js,ts}',
  ],
  coverageDirectory: path.join(__dirname, 'coverage'),
  globals: Object.assign(
    {
      __NODE_ENV__: 'test',
      'ts-jest': {
        babelConfig,
        tsConfig: path.join(__dirname, 'tsconfig.json'),
      },
    },
  ),
  moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'],
  moduleNameMapper: {
    '\\.(css|scss)$': 'identity-obj-proxy',
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(
      __dirname,
      'libs/jest/fileMock.js',
    ),
  },
  moduleDirectories: ['node_modules'],
  modulePaths: [__dirname],
  rootDir: __dirname,
  roots: [__dirname],
  testRegex: '\\.test\\.(j|t)s$',
  transform: {
    '^.+\\.js$': path.join(__dirname, '../../configs/jestPreprocess.js'),
    '^.+\\.ts$': 'ts-jest',
  },
  transformIgnorePatterns: ['/node_modules/'],
  watchPlugins: ['jest-watch-master'],
};

.babelrc.base.js

const pkg = require('../package.json');

const ENVS = {
  WEB_CLIENT_DEVELOPMENT: 'web-client-development',
  WEB_CLIENT_PRODUCTION: 'web-client-production',
  WEB_SERVER_DEVELOPMENT: 'web-server-development',
  WEB_SERVER_PRODUCTION: 'web-server-production',
  TEST: 'test',
};

module.exports = (api) => {
  api.cache(true);

  const env = process.env.NODE_ENV;

  const presets = [
    [
      '@babel/env',
      {
        modules: [ENVS.TEST].includes(env) ? 'commonjs' : false,
        useBuiltIns: [ENVS.TEST].includes(env) ? 'usage' : 'entry',
        ...([
          ENVS.WEB_SERVER_DEVELOPMENT,
          ENVS.WEB_SERVER_PRODUCTION,
          ENVS.TEST,
        ].includes(env)
          ? { targets: { node: pkg.engines.node } }
          : {}),
      },
    ],
    '@babel/react',
    '@babel/typescript',
  ];

  const plugins = [
    '@babel/proposal-class-properties',
    '@babel/plugin-syntax-dynamic-import',
    [ENVS.WEB_CLIENT_DEVELOPMENT, ENVS.WEB_SERVER_DEVELOPMENT].includes(env)
      && '@babel/transform-react-jsx-source',
  ].filter(Boolean);

  return {
    presets,
    plugins,
  };
};

package.json

"test": "cross-env CI=true jest --ci --coverage --expand --forceExit --detectOpenHandles"

@ahnpnl
Copy link
Collaborator

ahnpnl commented Nov 16, 2018

@lluzak @adrienharnay any chances we can have your sample repo ?

@adrienharnay
Copy link

Yeah I will try to set one up... Jest is so painful to set up on a new project, so much variables :( Will get back to you after the week-end!

@adrienharnay
Copy link

After trying to reproduce the issue for 2 hours, I gave up and switched to using @babel/preset-typescript alone, which got rid of the 10s timeout. Sorry about this, and I hope someone will be able to reproduce it in a minimal repository!

@davebrace
Copy link

We have the same issue on our project when upgrading from "ts-jest": "23.1.4" to "ts-jest": "23.10.5". Tests run fine locally on OSX, but stall out when running on Codeship.

Unfortunately, I don't have a good sample project to share. However, I did want to share the fact that for us this started happening between 23.1.4 and 23.10.5.

@taylortdixon
Copy link

I had a similar problem, where it was taking forever to run through my tests. As it turned out, ts-jest was hitting my lodash-es imports, and attempting to run and cache the entire of lodash.

In my project I had the luxury of being able to remove all of lodash as it was underutilized, so I don't have a "fix", but that was certainly the culprit for me.

@GeeWee
Copy link
Collaborator

GeeWee commented Dec 6, 2018

I definitely think someone has to provide a sample repo - otherwise we've got no way to try and fix this.

@IOuser
Copy link
Contributor

IOuser commented Jan 8, 2019

Maybe this issue relates to #908?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 19, 2020

Hi guys, would you please help testing with changes mentioned in #1310 (comment)

@camsjams
Copy link

camsjams commented Mar 25, 2020

Not sure who else this helps, but I had the exact same issue as described in this issue regarding Circle CI, and the best fix that worked for me was to update the jest.config to use:

{
  'ts-jest': {
    globals: {
      isolatedModules: true 
    }
  }
}

Which I found via: #908 (comment)

The testing time in Circle literally went from 10 minutes and timing out to 15 seconds! Same coverage and test results.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 13, 2020

I had a similar problem, where it was taking forever to run through my tests. As it turned out, ts-jest was hitting my lodash-es imports, and attempting to run and cache the entire of lodash.

In my project I had the luxury of being able to remove all of lodash as it was underutilized, so I don't have a "fix", but that was certainly the culprit for me.

The whole lodash is cached because jest passes the whole lodash module to transformer. ts-jest handles anything that is passed to transformer by jest.

I will close this issue as not clear to reproduce. If anyone has a repo to share, we would love to help.

@ahnpnl ahnpnl closed this as completed Apr 13, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Apr 21, 2020

FYI: #1549 will be in alpha version of ts-jest (possibly today). Anyone who is using ts-jest please help to test the alpha version and give us some feedbacks for #1115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤷‍♂️ Needs More Info waiting for more information from author of the issue Performance Severe performance issue
Projects
None yet
Development

No branches or pull requests

10 participants