Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions test/unit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,48 @@ const transpiledPackageNames = glob(
return relative.split( path.sep )[ 1 ];
} );

const dependenciesToTransform = [
'@ariakit/test',
'@ariakit/utils',
'@preact',
'comctx',
'docker-compose',
'marked',
'parsel-js',
'preact',
'uuid',
'yaml',
];

// Make sure the tests run in UTC timezone, regardless of the system timezone.
process.env.TZ = 'UTC';

/*
* Resolved rather than hardcoded to `<rootDir>/node_modules`,
* which is empty under non-hoisting installs.
*/
const ariakitTestDir = path.dirname(
require.resolve( '@ariakit/test/package.json', {
paths: [ path.join( ROOT_DIR, 'packages/components' ) ],
} )
);
const ariakitUtilsDir = path.dirname(
require.resolve( '@ariakit/utils/package.json', {
paths: [ ariakitTestDir ],
} )
);

module.exports = {
rootDir: '../../',
rootDir: ROOT_DIR,
moduleNameMapper: {
/**
* Specific mappings first (before generic patterns)
*/
// Jest resolves dependencies from CommonJS and cannot select import-only
// package exports. Map Ariakit's ESM test helpers explicitly.
'^@ariakit/test$': '<rootDir>/node_modules/@ariakit/test/dist/index.js',
'^@ariakit/test/react$':
'<rootDir>/node_modules/@ariakit/test/dist/react.js',
'^@ariakit/utils$':
'<rootDir>/node_modules/@ariakit/utils/dist/index.js',
'^@ariakit/test$': path.join( ariakitTestDir, 'dist/index.js' ),
'^@ariakit/test/react$': path.join( ariakitTestDir, 'dist/react.js' ),
'^@ariakit/utils$': path.join( ariakitUtilsDir, 'dist/index.js' ),
// Mock @wordpress/vips/worker before the general pattern so it doesn't try to load the real file.
// The worker-code.ts file is auto-generated during full builds and is gitignored.
'@wordpress/vips/worker':
Expand All @@ -42,15 +71,20 @@ module.exports = {
// The worker-code.ts file is auto-generated during full builds and is gitignored.
'@wordpress/video-conversion/worker':
'<rootDir>/test/unit/config/video-conversion-worker-code-stub.js',
[ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })$` ]:
'packages/$1/src',
'@wordpress/theme/design-tokens.js':
'<rootDir>/packages/theme/prebuilt/js/design-tokens.mjs',
'@wordpress/block-library/build-module/(.*).mjs':
'<rootDir>/packages/block-library/src/$1.js',
'.+\\.wasm$': '<rootDir>/test/unit/config/wasm-stub.js',
// Map deep paths (e.g., @wordpress/block-editor/src/hooks/list-view)
[ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })\\/(.+)$` ]:
'packages/$1/$2',
// Then map exact package imports (e.g., @wordpress/compose)
[ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })$` ]:
'packages/$1/src',
},
preset: require.resolve( '@wordpress/jest-preset-default' ),
testEnvironment: require.resolve( 'jest-environment-jsdom' ),
setupFiles: [
'<rootDir>/test/unit/config/global-mocks.js',
'<rootDir>/test/unit/config/gutenberg-env.js',
Expand Down Expand Up @@ -78,7 +112,7 @@ module.exports = {
'^.+\\.m?[jt]sx?$': '<rootDir>/test/unit/scripts/babel-transformer.js',
},
transformIgnorePatterns: [
'/node_modules/(?!(docker-compose|yaml|preact|@preact|parsel-js|comctx|uuid|marked|@ariakit/(test|utils))/)',
`/node_modules/(?!(${ dependenciesToTransform.join( '|' ) })/)`,
'\\.pnp\\.[^\\/]+$',
],
snapshotSerializers: [
Expand Down
Loading