MCPcopy
hub / github.com/vercel/next.js / createTestDir

Method createTestDir

test/lib/next-modes/base.ts:220–492  ·  view source on GitHub ↗
({
    skipInstall = false,
    parentSpan,
  }: {
    skipInstall?: boolean
    parentSpan: Span
  })

Source from the content-addressed store, hash-verified

218 }
219
220 protected async createTestDir({
221 skipInstall = false,
222 parentSpan,
223 }: {
224 skipInstall?: boolean
225 parentSpan: Span
226 }) {
227 if (this.isDestroyed) {
228 throw new Error('next instance already destroyed')
229 }
230
231 await parentSpan
232 .traceChild('createTestDir')
233 .traceAsyncFn(async (rootSpan) => {
234 const skipIsolatedNext = !!process.env.NEXT_SKIP_ISOLATE
235 if (!skipIsolatedNext) {
236 require('console').log(
237 `Creating test directory with isolated next... (use NEXT_SKIP_ISOLATE=1 to opt-out)`
238 )
239 }
240 const tmpDir = skipIsolatedNext
241 ? path.join(__dirname, '../../tmp')
242 : process.env.NEXT_TEST_DIR || (await fs.realpath(os.tmpdir()))
243 this.testDir = path.join(
244 tmpDir,
245 `next-test-${Date.now()}-${(Math.random() * 1000) | 0}`,
246 this.subDir
247 )
248 this.distDir = getDistDir()
249
250 const reactVersion =
251 process.env.NEXT_TEST_REACT_VERSION || nextjsReactPeerVersion
252 const finalDependencies = {
253 react: reactVersion,
254 'react-dom': reactVersion,
255 '@types/react': '19.2.2',
256 '@types/react-dom': '19.2.1',
257 typescript: 'latest',
258 '@types/node': 'latest',
259 ...this.dependencies,
260 ...this.packageJson?.dependencies,
261 }
262
263 if (
264 process.env.__NEXT_ENABLE_REACT_COMPILER === 'true' &&
265 !finalDependencies['babel-plugin-react-compiler']
266 ) {
267 finalDependencies['babel-plugin-react-compiler'] =
268 '0.0.0-experimental-3fde738-20250918'
269 }
270
271 if (skipInstall || skipIsolatedNext) {
272 const pkgScripts = (this.packageJson['scripts'] as {}) || {}
273 await fs.mkdir(this.testDir, { recursive: true })
274 await fs.writeFile(
275 path.join(this.testDir, 'package.json'),
276 JSON.stringify(
277 {

Callers 3

setupMethod · 0.80
setupMethod · 0.80
setupMethod · 0.80

Calls 15

beforeInstallMethod · 0.95
getDistDirFunction · 0.90
createNextInstallFunction · 0.90
realpathMethod · 0.80
mkdirMethod · 0.80
startsWithMethod · 0.80
includesMethod · 0.80
writeFileMethod · 0.65
matchMethod · 0.65
replaceMethod · 0.65
pushMethod · 0.65
requireFunction · 0.50

Tested by

no test coverage detected