Settings & Configurationjest.config.js

The jest.config.js file is used for configuring Jest, the JavaScript testing library used for writing unit and integration tests in Pup.

The modulePaths property tells Jest where it can resolve NPM modules used inside of the code you're testing. This is utilized for mocking (creating fake test versions of a package) so that code you're testing is isolated.

The moduleNameMapper property tells Jest to map certain files in your application to other modules. In Pup, images and other media files are mapped to a fileMock which creates mock versions of static files. Additionally, any .css and .scss files in your project are mapped to the identity-obj-proxy package which resolves these dependencies correctly when used in code being tested by Jest.

For Meteor dependencies imported via the meteor/author:package syntax, Jest is instructed to load mocks from the /tests/__mocks__/meteor directory. Because the : in package names is not supported by all operating systems, this is recast as author_package and mock files are stored in /tests/__mocks__/meteor with this naming convention (e.g., /tests/__mocks__/meteor/themeteorchef_bert.js is a mock for the meteor/themeteorchef:bert dependency.

The unmockedModulePathPatterns property tells Jest which paths it should not automock. In Pup, we tell Jest to ignore the node_modules directory at the root of the project so mocks for these dependencies can be handled on a case-by-case basis.

module.exports = {
  modulePaths: ['<rootDir>/node_modules/', '<rootDir>/tests/__mocks__/'],
  moduleNameMapper: {
    '\\.(css|scss)$': 'identity-obj-proxy', // NOTE: https://jestjs.io/docs/en/webpack#mocking-css-modules
    '^meteor/(.*):(.*)$': '<rootDir>/tests/__mocks__/meteor/$1_$2',
  unmockedModulePathPatterns: ['/^node_modules/'],