{"record":{"id":"71cc7082e6749ce9","repo":"jestjs/jest","slug":"shard-globalconfig-shard-shardindex-globalcon","errorCode":null,"errorMessage":"Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.","messagePattern":"Shard (.+?)/(.+?) requested, but test sequencer (.+?) in (.+?) has no shard method\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-core/src/runJest.ts","lineNumber":293,"sourceCode":"      const matches = await getTestPaths(\n        globalConfig,\n        context.config,\n        searchSource,\n        outputStream,\n        changedFilesPromise && (await changedFilesPromise),\n        jestHooks,\n        filter,\n      );\n      allTests = [...allTests, ...matches.tests];\n\n      return {context, matches};\n    }),\n  );\n  performance.mark('jest/getTestPaths:end');\n\n  if (globalConfig.shard) {\n    if (typeof sequencer.shard !== 'function') {\n      throw new TypeError(\n        `Shard ${globalConfig.shard.shardIndex}/${globalConfig.shard.shardCount} requested, but test sequencer ${Sequencer.name} in ${globalConfig.testSequencer} has no shard method.`,\n      );\n    }\n    allTests = await sequencer.shard(allTests, globalConfig.shard);\n  }\n\n  allTests = await sequencer.sort(allTests);\n\n  if (globalConfig.onlyFailures) {\n    if (failedTestsCache) {\n      allTests = failedTestsCache.filterTests(allTests);\n    } else {\n      allTests = await sequencer.allFailedTests(allTests);\n    }\n  }\n\n  if (globalConfig.listTests) {\n    const testsPaths = [...new Set(allTests.map(test => test.path))];","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-core/src/runJest.ts#L275-L311","documentation":"Thrown when the `--shard` CLI option (or `globalConfig.shard`) is used but the configured custom test sequencer class does not implement a `shard` method. Jest checks `typeof sequencer.shard !== 'function'` at runtime before attempting to call it, because sharding is an opt-in capability that custom sequencers must explicitly support.","triggerScenarios":"Running Jest with `--shard=1/4` (e.g. for CI parallelization) while `testSequencer` in the config points to a custom class that extends `@jest/test-sequencer` but does not define a `shard(tests, shardOptions)` method.","commonSituations":"Migrating from a non-sharded CI to a sharded one without updating a custom test sequencer. Using a third-party sequencer package that predates the sharding API. Adding `--shard` to CI scripts while a project-level custom sequencer is present.","solutions":["Add a `shard` method to your custom sequencer class, or remove the custom `testSequencer` from config to use the default sequencer which supports sharding.","If the custom sequencer is from a third-party package, upgrade it or check for a newer version that implements `shard`.","Remove the `--shard` flag from the CI command if sharding is not needed."],"exampleFix":"// before: CustomSequencer.js\nconst Sequencer = require('@jest/test-sequencer').default;\nclass CustomSequencer extends Sequencer {\n  sort(tests) { /* custom sort */ return tests; }\n}\n\n// after: add shard method\nconst Sequencer = require('@jest/test-sequencer').default;\nclass CustomSequencer extends Sequencer {\n  sort(tests) { /* custom sort */ return tests; }\n  shard(tests, { shardIndex, shardCount }) {\n    const shardSize = Math.ceil(tests.length / shardCount);\n    const shardStart = (shardIndex - 1) * shardSize;\n    return tests.slice(shardStart, shardStart + shardSize);\n  }\n}","handlingStrategy":"validation","validationCode":"// Validate the custom sequencer supports sharding before running with --shard\nconst Sequencer = require('./CustomSequencer');\nfunction validateSequencerShard(SequencerClass, hasShard) {\n  if (hasShard && typeof SequencerClass.prototype.shard !== 'function') {\n    throw new Error(`${SequencerClass.name} must implement shard(tests, options)`);\n  }\n}","typeGuard":"function hasShardMethod(seq: unknown): seq is { shard(tests: unknown[], shard: {shardIndex: number; shardCount: number}): Promise<unknown[]> } {\n  return typeof (seq as any)?.shard === 'function';\n}","tryCatchPattern":null,"preventionTips":["If using --shard in CI, test the sharded run locally before pushing.","When writing a custom sequencer, always extend @jest/test-sequencer and implement shard if you need sharding.","Document in the sequencer file whether sharding is supported."],"tags":["jest-core","sharding","test-sequencer","ci","configuration"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}