From 13866dd43dc16d4bd36977ca7b8541408e74e311 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:01:05 +0000 Subject: [PATCH 1/2] Migrate tests to import from @jest/globals instead of using globals Co-authored-by: ecraig12345 <5864305+ecraig12345@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/just/sessions/435fed0c-a4b7-44ed-8107-d94b7ec81d0e --- package.json | 1 + packages/just-scripts/src/__tests__/getMockScript.ts | 1 + .../just-scripts/src/copy/__tests__/CopyInstruction.spec.ts | 1 + .../src/copy/__tests__/executeCopyInstructions.spec.ts | 1 + .../just-scripts/src/tasks/__tests__/getNormalizedSpawnArgs.ts | 1 + packages/just-scripts/src/tasks/__tests__/nodeExecTask.test.ts | 1 + packages/just-scripts/src/tasks/__tests__/tscTask.spec.ts | 3 ++- packages/just-scripts/src/utils/__tests__/exec.spec.ts | 1 + .../just-scripts/src/utils/__tests__/mergePackageJson.spec.ts | 1 + packages/just-scripts/src/utils/__tests__/paths.spec.ts | 1 + .../just-scripts/src/utils/__tests__/readPackageJson.spec.ts | 1 + packages/just-task/src/__tests__/chain.spec.ts | 1 + packages/just-task/src/__tests__/logger.spec.ts | 1 + packages/just-task/src/__tests__/resolve.spec.ts | 1 + packages/just-task/src/__tests__/task.spec.ts | 1 + packages/just-task/src/__tests__/watch.spec.ts | 3 ++- scripts/jest.config.js | 1 + tsconfig.json | 2 +- yarn.lock | 2 +- 19 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6bbe6aa8..766d60e5 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "node": ">=14" }, "devDependencies": { + "@jest/globals": "^29.5.0", "@microsoft/api-extractor": "7.52.9", "@types/fs-extra": "^11.0.0", "@types/jest": "^29.4.0", diff --git a/packages/just-scripts/src/__tests__/getMockScript.ts b/packages/just-scripts/src/__tests__/getMockScript.ts index 37154b86..964eb30b 100644 --- a/packages/just-scripts/src/__tests__/getMockScript.ts +++ b/packages/just-scripts/src/__tests__/getMockScript.ts @@ -1,3 +1,4 @@ +import { expect } from '@jest/globals'; import * as fs from 'fs'; import * as path from 'path'; diff --git a/packages/just-scripts/src/copy/__tests__/CopyInstruction.spec.ts b/packages/just-scripts/src/copy/__tests__/CopyInstruction.spec.ts index 9ea964af..34afb39f 100644 --- a/packages/just-scripts/src/copy/__tests__/CopyInstruction.spec.ts +++ b/packages/just-scripts/src/copy/__tests__/CopyInstruction.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from '@jest/globals'; import { copyFilesToDestinationDirectory } from '../CopyInstruction'; import { normalize } from 'path'; diff --git a/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts b/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts index 1b685b83..ab2ee7f8 100644 --- a/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts +++ b/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, beforeEach, afterEach } from '@jest/globals'; import * as mockfs from 'mock-fs'; import * as path from 'path'; import * as fs from 'fs'; diff --git a/packages/just-scripts/src/tasks/__tests__/getNormalizedSpawnArgs.ts b/packages/just-scripts/src/tasks/__tests__/getNormalizedSpawnArgs.ts index e71c54ce..8985455e 100644 --- a/packages/just-scripts/src/tasks/__tests__/getNormalizedSpawnArgs.ts +++ b/packages/just-scripts/src/tasks/__tests__/getNormalizedSpawnArgs.ts @@ -1,3 +1,4 @@ +import { expect, jest } from '@jest/globals'; import * as path from 'path'; import type { spawn } from '../../utils/exec'; diff --git a/packages/just-scripts/src/tasks/__tests__/nodeExecTask.test.ts b/packages/just-scripts/src/tasks/__tests__/nodeExecTask.test.ts index fed9562c..22f3e8f6 100644 --- a/packages/just-scripts/src/tasks/__tests__/nodeExecTask.test.ts +++ b/packages/just-scripts/src/tasks/__tests__/nodeExecTask.test.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, beforeEach, afterEach, afterAll } from '@jest/globals'; import { fail } from 'assert'; import type { TaskFunction } from 'just-task'; import * as path from 'path'; diff --git a/packages/just-scripts/src/tasks/__tests__/tscTask.spec.ts b/packages/just-scripts/src/tasks/__tests__/tscTask.spec.ts index c78d0078..0f8fcb2b 100644 --- a/packages/just-scripts/src/tasks/__tests__/tscTask.spec.ts +++ b/packages/just-scripts/src/tasks/__tests__/tscTask.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, beforeEach, afterEach } from '@jest/globals'; import * as mockfs from 'mock-fs'; import { spawn } from '../../utils'; import { tscTask, tscWatchTask } from '../tscTask'; @@ -6,7 +7,7 @@ import { getNormalizedSpawnArgs } from './getNormalizedSpawnArgs'; // Jest will hoist these before the imports above, so these modules will be mocked first jest.mock('../../utils/exec', () => { - const originalModule = jest.requireActual('../../utils/exec'); + const originalModule = jest.requireActual('../../utils/exec') as typeof import('../../utils/exec'); return { // Use real implementation of most exports ...originalModule, diff --git a/packages/just-scripts/src/utils/__tests__/exec.spec.ts b/packages/just-scripts/src/utils/__tests__/exec.spec.ts index 67e9e3b4..57b07d3d 100644 --- a/packages/just-scripts/src/utils/__tests__/exec.spec.ts +++ b/packages/just-scripts/src/utils/__tests__/exec.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, afterEach } from '@jest/globals'; import * as cp from 'child_process'; import * as path from 'path'; import { encodeArgs, spawn } from '../exec'; diff --git a/packages/just-scripts/src/utils/__tests__/mergePackageJson.spec.ts b/packages/just-scripts/src/utils/__tests__/mergePackageJson.spec.ts index 4664620d..603e32ff 100644 --- a/packages/just-scripts/src/utils/__tests__/mergePackageJson.spec.ts +++ b/packages/just-scripts/src/utils/__tests__/mergePackageJson.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from '@jest/globals'; import { mergePackageJson, _shouldUpdateDep } from '../mergePackageJson'; import { PackageJson } from '../../interfaces/PackageJson'; diff --git a/packages/just-scripts/src/utils/__tests__/paths.spec.ts b/packages/just-scripts/src/utils/__tests__/paths.spec.ts index 82b02336..788becfb 100644 --- a/packages/just-scripts/src/utils/__tests__/paths.spec.ts +++ b/packages/just-scripts/src/utils/__tests__/paths.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, afterEach } from '@jest/globals'; import * as path from 'path'; import * as os from 'os'; import { paths } from '../paths'; diff --git a/packages/just-scripts/src/utils/__tests__/readPackageJson.spec.ts b/packages/just-scripts/src/utils/__tests__/readPackageJson.spec.ts index f52ab0fd..5553444a 100644 --- a/packages/just-scripts/src/utils/__tests__/readPackageJson.spec.ts +++ b/packages/just-scripts/src/utils/__tests__/readPackageJson.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, beforeEach, afterEach } from '@jest/globals'; import { readPackageJson } from '../readPackageJson'; import * as mockfs from 'mock-fs'; diff --git a/packages/just-task/src/__tests__/chain.spec.ts b/packages/just-task/src/__tests__/chain.spec.ts index 61cdf02e..9efec91d 100644 --- a/packages/just-task/src/__tests__/chain.spec.ts +++ b/packages/just-task/src/__tests__/chain.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest } from '@jest/globals'; import { task } from '../task'; import { chain } from '../chain'; import { parallel } from '../undertaker'; diff --git a/packages/just-task/src/__tests__/logger.spec.ts b/packages/just-task/src/__tests__/logger.spec.ts index eff00ed0..9f5ab308 100644 --- a/packages/just-task/src/__tests__/logger.spec.ts +++ b/packages/just-task/src/__tests__/logger.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, beforeAll, beforeEach, afterAll } from '@jest/globals'; import { logger } from '../logger'; import chalk = require('chalk'); diff --git a/packages/just-task/src/__tests__/resolve.spec.ts b/packages/just-task/src/__tests__/resolve.spec.ts index 99e735f6..db01b429 100644 --- a/packages/just-task/src/__tests__/resolve.spec.ts +++ b/packages/just-task/src/__tests__/resolve.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, afterEach, beforeEach } from '@jest/globals'; import * as path from 'path'; import { _isFileNameLike, diff --git a/packages/just-task/src/__tests__/task.spec.ts b/packages/just-task/src/__tests__/task.spec.ts index 1f586e6d..16db6e39 100644 --- a/packages/just-task/src/__tests__/task.spec.ts +++ b/packages/just-task/src/__tests__/task.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, jest, beforeAll, beforeEach, afterAll } from '@jest/globals'; import { task } from '../task'; import { parallel, undertaker } from '../undertaker'; import { logger } from '../logger'; diff --git a/packages/just-task/src/__tests__/watch.spec.ts b/packages/just-task/src/__tests__/watch.spec.ts index 0f33c22d..13c70eac 100644 --- a/packages/just-task/src/__tests__/watch.spec.ts +++ b/packages/just-task/src/__tests__/watch.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from '@jest/globals'; import { watch } from '../watch'; import * as fs from 'fs'; import * as path from 'path'; @@ -25,7 +26,7 @@ describe('watch', () => { done(); } catch (error) { cleanup(); - done(error); + done(error instanceof Error ? error : new Error(String(error))); } }; diff --git a/scripts/jest.config.js b/scripts/jest.config.js index 70ff3212..4264db08 100644 --- a/scripts/jest.config.js +++ b/scripts/jest.config.js @@ -10,6 +10,7 @@ module.exports = { testEnvironment: 'node', testMatch: ['**/?(*.)+(spec|test).[jt]s'], verbose: true, + injectGlobals: false, transform: { '^.+\\.tsx?$': [ 'ts-jest', diff --git a/tsconfig.json b/tsconfig.json index d311d550..12fa6c27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,6 @@ "skipLibCheck": true, "esModuleInterop": false, "allowSyntheticDefaultImports": false, - "types": ["node", "jest"] + "types": ["node"] } } diff --git a/yarn.lock b/yarn.lock index 549479e6..4cbe7823 100644 --- a/yarn.lock +++ b/yarn.lock @@ -427,7 +427,7 @@ jest-mock "^29.7.0" jest-util "^29.7.0" -"@jest/globals@^29.7.0": +"@jest/globals@^29.5.0", "@jest/globals@^29.7.0": version "29.7.0" resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-29.7.0.tgz#8d9290f9ec47ff772607fa864ca1d5a2efae1d4d" integrity sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ== From 69a9d15b387b77aacd273ec46407d6acf8eb9f53 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Thu, 26 Mar 2026 06:07:36 -0700 Subject: [PATCH 2/2] claude --- CLAUDE.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index ee7bdcc7..b8a73410 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -70,7 +70,10 @@ Task functions can: return a Promise, call a `done` callback, or return a stream - TypeScript target: `es2019`, module: `commonjs`, strict mode - Prettier: 120 print width, single quotes, trailing commas, 2-space indent -- Tests: Jest with ts-jest, test files in `src/**/__tests__/*.(test|spec).ts` +- Tests: + - Jest with ts-jest + - Test files in `src/**/__tests__/*.(test|spec).ts` + - Functions such as `describe`, `it`, `expect` must be imported from `@jest/globals` (they are not implicitly available) - Each package compiles to `lib/` directory ## CI / Release