mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
`@hanzo/mascot-mode` went with the mascot easter egg, but three places still
name it: the storybook static-dir list, the vite public-assets copy, and the
jest ESM transform list. The storybook entry is fatal — `parseStaticDir`
refuses a directory that does not exist, so `storybook dev` and
`storybook build` both exit before serving anything, which is why nothing in
this repo has run a story since.
The other two are quiet: the vite plugin logs a warning and continues, and the
jest entry widens a transform pattern over a package no test can import.
common/storybook/.storybook/main.ts staticDirs entry
frontend/plugins/vite-public-assets-plugin.ts copy block
frontend/jest.config.ts esmModules entry
Verified: `pnpm --filter=@hanzo/storybook start` reaches "Storybook ready!"
and serves index.json with 200.
355 lines
15 KiB
TypeScript
355 lines
15 KiB
TypeScript
import type { Config } from 'jest'
|
|
|
|
process.env.TZ = process.env.TZ || 'UTC'
|
|
|
|
/*
|
|
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
* https://jestjs.io/docs/en/configuration.html
|
|
*/
|
|
|
|
const esmModules = [
|
|
'query-selector-shadow-dom',
|
|
// @shadcn/react ships ESM-only; @hanzo/quill-primitives chat components re-export its
|
|
// message-scroller, pulling it into frontend test module graphs via the quill barrel.
|
|
'@shadcn/react',
|
|
'@react-hook',
|
|
'@medv',
|
|
// @toon-format/toon ships ESM-only; the insights_ai widget extractors decode TOON tool output.
|
|
'@toon-format',
|
|
'monaco-editor',
|
|
// @hanzo/appearance (and the @hanzo/design tokens it reads) are ESM-only. The
|
|
// appearance settings pull them into every scene graph that reaches SettingsMap,
|
|
// which is most of them -- settingsLogic is imported by the error tracking and
|
|
// session replay scenes as well as by SettingsScene itself. Left out, the scene
|
|
// smoke test cannot even LOAD five scenes, so the gate that exists to catch a
|
|
// scene crash reported a parse error instead.
|
|
'@hanzo/appearance',
|
|
'@hanzo/design',
|
|
// @marsidev/react-turnstile ships ESM-only; the auth flow variant registry pulls it
|
|
// into test module graphs (including Exporter via the shared login ERROR_MESSAGES export).
|
|
'@marsidev/react-turnstile',
|
|
'escape-string-regexp',
|
|
'@tiptap',
|
|
'@mathjax',
|
|
'marked',
|
|
'lowlight',
|
|
'devlop',
|
|
'zwitch',
|
|
// insights-js's rrweb subpath entries are shipped as ESM; the rest of insights-js
|
|
// is CJS, so we scope the transform to just dist/rrweb* to avoid retranspiling main.js.
|
|
'insights-js/dist/rrweb',
|
|
// react-markdown and its ecosystem are all ESM-only
|
|
'react-markdown',
|
|
'remark-.*',
|
|
'rehype-.*',
|
|
'unified',
|
|
'bail',
|
|
'trough',
|
|
'vfile',
|
|
'vfile-message',
|
|
'hast-util-.*',
|
|
'mdast-util-.*',
|
|
'unist-util-.*',
|
|
'estree-util-.*',
|
|
'micromark',
|
|
'micromark-.*',
|
|
'parse-entities',
|
|
'character-entities.*',
|
|
'character-reference-invalid',
|
|
'is-plain-obj',
|
|
'is-decimal',
|
|
'is-hexadecimal',
|
|
'is-alphabetical',
|
|
'is-alphanumerical',
|
|
'decode-named-character-reference',
|
|
'trim-lines',
|
|
'comma-separated-tokens',
|
|
'space-separated-tokens',
|
|
'property-information',
|
|
'stringify-entities',
|
|
'html-void-elements',
|
|
'html-url-attributes',
|
|
'ccount',
|
|
'longest-streak',
|
|
'markdown-table',
|
|
'@mathjax/src',
|
|
// MSW v2 and its dependencies ship ESM that resolves under the forced `default` export condition
|
|
'msw',
|
|
'@mswjs/.*',
|
|
'@bundled-es-modules/.*',
|
|
'@open-draft/.*',
|
|
'rettime',
|
|
'strict-event-emitter',
|
|
'headers-polyfill',
|
|
'outvariant',
|
|
'until-async',
|
|
'is-node-process',
|
|
// yaml's browser entry (used under the jsdom env) is ESM and re-exports its CJS dist
|
|
'yaml/browser',
|
|
]
|
|
function rootDirectories(): string[] {
|
|
return [
|
|
'<rootDir>/src',
|
|
'<rootDir>/bin',
|
|
'<rootDir>/../products',
|
|
'<rootDir>/../packages/quill/packages/charts/src',
|
|
'<rootDir>/../packages/quill/packages/components/src',
|
|
]
|
|
}
|
|
|
|
const config: Config = {
|
|
// All imported modules in your tests should be mocked automatically
|
|
// automock: false,
|
|
|
|
// Stop running tests after `n` failures
|
|
// bail: 0,
|
|
|
|
// The directory where Jest should store its cached dependency information
|
|
// cacheDirectory: "/private/var/folders/30/3j86j9bx6514w18wx5gffc6r0000gn/T/jest_dx",
|
|
|
|
// Automatically clear mock calls and instances between every test
|
|
clearMocks: true,
|
|
|
|
// Indicates whether the coverage information should be collected while executing the test
|
|
// collectCoverage: false,
|
|
|
|
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
// collectCoverageFrom: undefined,
|
|
|
|
// The directory where Jest should output its coverage files
|
|
coverageDirectory: 'coverage',
|
|
|
|
// An array of regexp pattern strings used to skip coverage collection
|
|
// coveragePathIgnorePatterns: [
|
|
// "/node_modules/"
|
|
// ],
|
|
|
|
// Indicates which provider should be used to instrument code for coverage
|
|
coverageProvider: 'v8',
|
|
|
|
// A list of reporter names that Jest uses when writing coverage reports
|
|
// coverageReporters: [
|
|
// "json",
|
|
// "text",
|
|
// "lcov",
|
|
// "clover"
|
|
// ],
|
|
|
|
// An object that configures minimum threshold enforcement for coverage results
|
|
// coverageThreshold: undefined,
|
|
|
|
// A path to a custom dependency extractor
|
|
// dependencyExtractor: undefined,
|
|
|
|
// Make calling deprecated APIs throw helpful error messages
|
|
// errorOnDeprecated: false,
|
|
|
|
// Faking queueMicrotask starves the web-streams pump that MSW v2 response bodies ride on:
|
|
// each pump microtask lands in the fake queue and respawns the next one, so any
|
|
// advanceTimersByTimeAsync allocates unboundedly until the worker OOMs. Keep microtasks real.
|
|
// setImmediate drives MSW v2's interceptor response pump the same way — faking it deadlocks
|
|
// any test that awaits a mocked request under fake timers (upstream stance: mswjs/msw#1830).
|
|
// Merged into per-test `jest.useFakeTimers({...})` configs unless they pass their own doNotFake.
|
|
fakeTimers: {
|
|
doNotFake: ['queueMicrotask', 'setImmediate'],
|
|
},
|
|
|
|
// Force coverage collection from ignored files using an array of glob patterns
|
|
// forceCoverageMatch: [],
|
|
|
|
// A path to a module which exports an async function that is triggered once before all test suites
|
|
// globalSetup: undefined,
|
|
|
|
// A path to a module which exports an async function that is triggered once after all test suites
|
|
// globalTeardown: undefined,
|
|
|
|
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
// maxWorkers: "50%",
|
|
|
|
// An array of directory names to be searched recursively up from the requiring module's location
|
|
// moduleDirectories: [
|
|
// "node_modules"
|
|
// ],
|
|
|
|
// An array of file extensions your modules use
|
|
// moduleFileExtensions: [
|
|
// "js",
|
|
// "json",
|
|
// "jsx",
|
|
// "ts",
|
|
// "tsx",
|
|
// "node"
|
|
// ],
|
|
|
|
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
moduleNameMapper: {
|
|
'^.+\\.(css|less|scss|svg|png)$': '<rootDir>/src/test/mocks/styleMock.js',
|
|
// devHmrStreamAbort subscribes to Vite HMR events via import.meta, which Sucrase passes
|
|
// through into CJS and Jest then cannot compile ("Cannot use 'import.meta' outside a module").
|
|
// It is dev-server-only behavior, so stub it out rather than transform it.
|
|
devHmrStreamAbort$: '<rootDir>/src/test/mocks/emptyMock.js',
|
|
'^.+\\.sql\\?raw$': '<rootDir>/src/test/mocks/rawFileMock.js',
|
|
'^(.+)\\.yaml\\?raw$': '$1.yaml',
|
|
'^~/(.*)$': '<rootDir>/src/$1',
|
|
'^@hanzo/insightsql-parser$': '<rootDir>/node_modules/@hanzo/insightsql-parser/dist/index.cjs',
|
|
// @hanzo/scriptvm ships as ESM-only; map to the TS source so Jest (Sucrase) can handle it.
|
|
// Required for sidePanelNotificationsLogic.test.ts and other tests with a transitive
|
|
// import chain through src/lib/script.ts.
|
|
'^@hanzo/scriptvm$': '<rootDir>/node_modules/@hanzo/scriptvm/src/index.ts',
|
|
'^@hanzo/elements(|/.*)$': '<rootDir>/@hanzo/elements/src/$1',
|
|
'^lib/(.*)$': '<rootDir>/src/lib/$1',
|
|
'^react-markdown$': '<rootDir>/src/test/mocks/reactMarkdownMock.js',
|
|
'^remark-gfm$': '<rootDir>/src/test/mocks/emptyMock.js',
|
|
'^remark-breaks$': '<rootDir>/src/test/mocks/emptyMock.js',
|
|
'^mdast-util-find-and-replace$': '<rootDir>/src/test/mocks/emptyMock.js',
|
|
'^chart\\.js$': '<rootDir>/src/test/insight-testing/chartjs-mock',
|
|
'chartjs-plugin-crosshair': '<rootDir>/src/test/mocks/emptyMock.js',
|
|
'chartjs-plugin-annotation': '<rootDir>/src/test/mocks/chartjsPluginMock.js',
|
|
'chartjs-plugin-datalabels': '<rootDir>/src/test/mocks/chartjsPluginMock.js',
|
|
'chartjs-plugin-stacked100': '<rootDir>/src/test/mocks/chartjsStacked100Mock.js',
|
|
'chartjs-plugin-trendline': '<rootDir>/src/test/mocks/chartjsPluginMock.js',
|
|
'chartjs-plugin-zoom': '<rootDir>/src/test/mocks/chartjsPluginMock.js',
|
|
'chartjs-adapter-dayjs-3': '<rootDir>/src/test/mocks/emptyMock.js',
|
|
torph: '<rootDir>/src/test/mocks/torphMock.js',
|
|
'monaco-editor': '<rootDir>/node_modules/monaco-editor/esm/vs/editor/editor.api.d.ts',
|
|
'^scenes/(.*)$': '<rootDir>/src/scenes/$1',
|
|
'^products/(.*)$': '<rootDir>/../products/$1',
|
|
'^common/(.*)$': '<rootDir>/../common/$1',
|
|
'^@hanzo/replay-shared$': '<rootDir>/../common/replay-shared/src/index.ts',
|
|
'^@hanzo/replay-shared/(.*)$': '<rootDir>/../common/replay-shared/src/$1',
|
|
'^@hanzo/quill$': '<rootDir>/../packages/quill/packages/quill/src/index.ts',
|
|
'^@hanzo/quill-blocks$': '<rootDir>/../packages/quill/packages/blocks/src/index.ts',
|
|
'^@hanzo/quill-charts$': '<rootDir>/../packages/quill/packages/charts/src/index.ts',
|
|
'^@hanzo/quill-charts/testing$': '<rootDir>/../packages/quill/packages/charts/src/testing/index.ts',
|
|
'^@hanzo/quill-charts/story-helpers$': '<rootDir>/../packages/quill/packages/charts/src/story-helpers.tsx',
|
|
'^@hanzo/quill-components$': '<rootDir>/../packages/quill/packages/components/src/index.ts',
|
|
'^@hanzo/quill-components/metric$': '<rootDir>/../packages/quill/packages/components/src/metric.tsx',
|
|
'^@hanzo/quill-primitives$': '<rootDir>/../packages/quill/packages/primitives/src/index.ts',
|
|
'^@hanzo/quill-tokens$': '<rootDir>/../packages/quill/packages/tokens/src/index.ts',
|
|
'^@hanzo/shared-onboarding/(.*)$': '<rootDir>/../docs/onboarding/$1',
|
|
d3: '<rootDir>/node_modules/d3/dist/d3.min.js',
|
|
'^d3-(.*)$': `d3-$1/dist/d3-$1`,
|
|
'^@mathjax/src/(.*)$': '<rootDir>/src/test/mocks/mathjaxMock.js',
|
|
},
|
|
|
|
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
// modulePathIgnorePatterns: [],
|
|
|
|
// Activates notifications for test results
|
|
// notify: false,
|
|
|
|
// An enum that specifies notification mode. Requires { notify: true }
|
|
// notifyMode: "failure-change",
|
|
|
|
// A preset that is used as a base for Jest's configuration
|
|
// preset: undefined,
|
|
|
|
// Run tests from one or more projects
|
|
// projects: undefined,
|
|
|
|
// Emit JUnit XML for Trunk flaky-test detection only when JEST_JUNIT_OUTPUT_DIR is set.
|
|
reporters: process.env.JEST_JUNIT_OUTPUT_DIR ? ['default', 'jest-junit'] : ['default'],
|
|
|
|
// Automatically reset mock state between every test
|
|
// resetMocks: false,
|
|
|
|
// Reset the module registry before running each individual test
|
|
// resetModules: false,
|
|
|
|
// A path to a custom resolver — strips the `browser` export condition for the MSW ecosystem
|
|
// (whose Node subpaths are null under `browser`) without affecting any other package's resolution.
|
|
resolver: '<rootDir>/jest.resolver.js',
|
|
|
|
// Automatically restore mock state between every test
|
|
// restoreMocks: false,
|
|
|
|
// The root directory that Jest should scan for tests and modules within
|
|
modulePaths: ['<rootDir>/'],
|
|
|
|
// A list of paths to directories that Jest should use to search for files in
|
|
roots: rootDirectories(),
|
|
|
|
// Allows you to use a custom runner instead of Jest's default test runner
|
|
// runner: "jest-runner",
|
|
|
|
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
setupFiles: ['<rootDir>/jest.polyfills.js', '<rootDir>/jest.setup.ts', 'fake-indexeddb/auto'],
|
|
|
|
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
// jest.quarantine.ts first so it wraps the describe/it/test globals before any test file declares tests.
|
|
setupFilesAfterEnv: [
|
|
'<rootDir>/jest.quarantine.ts',
|
|
'<rootDir>/jest.setupAfterEnv.ts',
|
|
'<rootDir>/src/mocks/jest.ts',
|
|
],
|
|
|
|
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
// slowTestThreshold: 5,
|
|
|
|
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
// snapshotSerializers: [],
|
|
|
|
// The test environment that will be used for testing
|
|
testEnvironment: 'jsdom',
|
|
|
|
// Options that will be passed to the testEnvironment
|
|
testEnvironmentOptions: {},
|
|
|
|
// Adds a location field to test results
|
|
// testLocationInResults: false,
|
|
|
|
// The glob patterns Jest uses to detect test files
|
|
// testMatch: [
|
|
// "**/__tests__/**/*.[jt]s?(x)",
|
|
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
// ],
|
|
|
|
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
testPathIgnorePatterns: [
|
|
'/node_modules/',
|
|
'/services/mcp/',
|
|
'/products/[^/]+/frontend/e2e/',
|
|
'/products/visual_review/cli/',
|
|
'/products/desktop/',
|
|
],
|
|
|
|
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
// testRegex: [],
|
|
|
|
// This option allows the use of a custom results processor
|
|
// testResultsProcessor: undefined,
|
|
|
|
// This option allows use of a custom test runner
|
|
// testRunner: "jasmine2",
|
|
|
|
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
// testURL: "http://localhost",
|
|
|
|
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
// timers: "real",
|
|
|
|
// A map from regular expressions to paths to transformers
|
|
transform: {
|
|
// Include .mjs/.cjs so ESM dependencies allowed through transformIgnorePatterns (e.g. MSW's) are transpiled.
|
|
'\\.[cm]?[jt]sx?$': '@sucrase/jest-plugin',
|
|
'\\.yaml$': '<rootDir>/src/test/yamlRawTransformer.js',
|
|
},
|
|
|
|
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
transformIgnorePatterns: [`node_modules/(?!.*(${esmModules.join('|')}))`],
|
|
|
|
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
// unmockedModulePathPatterns: undefined,
|
|
|
|
// Indicates whether each individual test should be reported during the run
|
|
// verbose: undefined,
|
|
|
|
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
// watchPathIgnorePatterns: [],
|
|
|
|
// Whether to use watchman for file crawling
|
|
// watchman: true,
|
|
}
|
|
|
|
export default config
|