Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer committed Sep 27, 2024
1 parent 7cb9d26 commit d05b043
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const commonConfig = {
tsconfig: 'tsconfig.test.json',
}]
},
resolver: './jest.resolver.cjs',
moduleFileExtensions: ['ts', 'tsx', 'cts', 'js', 'json'],
modulePathIgnorePatterns: ['<rootDir>/packages/magicbell/dist', '<rootDir>/packages/playground', '<rootDir>/packages/embeddable/cypress'],
globals: {
__PACKAGE_NAME__: 'TEST',
Expand All @@ -41,16 +43,22 @@ const commonConfig = {
moduleNameMapper,
};

const projectConfigs = {
'@magicbell/user-client': {
testEnvironment: 'node',
}
};

/** @type {import('jest').Config} */
module.exports = {
projects: packages.map(([name, dir]) => ({
...commonConfig,
displayName: name,
testEnvironment: name === '@magicbell/user-client' ? 'node' : "jest-environment-jsdom",
testMatch: [
`${dir}/src/**/*.test.[jt]s?(x)"`,
`${dir}/test/**/*.[jt]s?(x)"`,
`${dir}/tests/**/*.spec.[jt]s?(x)"`,
],
...projectConfigs[name],
}))
};
12 changes: 12 additions & 0 deletions jest.resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs');

module.exports = (request, options) => {
const { defaultResolver } = options;
const resolvedPath = defaultResolver(request, options);

// try resolve tshy module resolution polyfills
const cjsPath = resolvedPath.replace(/\.ts$/, '-cjs.cts');
if (fs.existsSync(cjsPath)) return cjsPath;

return resolvedPath;
}

0 comments on commit d05b043

Please sign in to comment.