gtsop / babel-jest-boost

🐠 🃏 🚀 - Brings tree-shaking to Jest, speeding up your test runs, using Babel
GNU Affero General Public License v3.0
8 stars 1 forks source link

How to use this with Angular? #1

Open anandtiwary opened 1 month ago

anandtiwary commented 1 month ago

Hi @gtsop

This is an excellent initiative. Could you share an example of how I can use your tool with an angular application? Here is my jest.config.ts

const { pathsToModuleNameMapper } = require('ts-jest');
const { paths } = require('./tsconfig.json').compilerOptions;

const { jestConfig } = require("@gtsopanoglou/babel-jest-boost/config"); // I added this. Is this correct? 

process.env.TZ = 'UTC'; // Tests should always run in UTC, no time zone dependencies

globalThis.ngJest = {
  skipNgcc: true,
  tsconfig: 'tsconfig.spec.json',
};

module.exports = {
  ...jestConfig, // I added this. Is this correct? 
  rootDir: '.',
  preset: 'jest-preset-angular',
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
  globalSetup: 'jest-preset-angular/global-setup',
  watchPathIgnorePatterns: ['test-results'],
  collectCoverageFrom: [
    'src/**/*.ts',
    'projects/*/src/**/*.ts',
    '!**/*.d.ts',
    '!src/main.ts',
    '!src/environments/**',
    '!**/*/test/**',
    '!src/app/routes/**/*.ts',
    '!**/*.module.ts',
  ],
  modulePathIgnorePatterns: ['<rootDir>/dist/'], // Need to reset from app project, but empty is merged
  testMatch: ['<rootDir>/(src|projects)/**/+(*.)+(spec|test).ts'],
  moduleNameMapper: {
    '^lodash-es$': 'lodash',
    '^uuid$': 'uuid',
    ...pathsToModuleNameMapper(paths, { prefix: '<rootDir>' }),
  },
};
gtsop-d commented 1 month ago

Hello @anandtiwary , i am not familiar with Angular's environment but I am willing to put in some effort to ensure it works. Would you be able to create a baseline angular repository with minimal code so we can test this plugin integration on it?

const { jestConfig } = require("@gtsopanoglou/babel-jest-boost/config"); // I added this. Is this correct?

This is not correct, this code is meant to be used inside your babel transformer, which by default it seems like you're not using any. If I had an example repository it would make it easier for me to figure it out and let you know.