Instruction file imported from microsoft/atlas-design (
.github/instructions/js.instructions.md). Copyright stays with the author.
Atlas JS - Copilot Instructions
applyTo: "js/**"
This is the @microsoft/atlas-js package, providing TypeScript/JavaScript behaviors for the Atlas Design System.
Package Overview
- Name:
@microsoft/atlas-js - Type: TypeScript library
- Build Tool: TypeScript compiler (tsc)
- Output: ES modules with declarations
Project Structure
js/
├── src/
│ ├── behaviors/ # Behavior modules (e.g., popover, modal)
│ ├── elements/ # Custom elements / web components
│ ├── utilities/ # Shared utility functions
│ └── index.ts # Main entry point
├── test/ # Unit tests (mirrors src/ structure)
└── dist/ # Compiled JavaScript output
Key Commands
npm run build- Compile TypeScript to JavaScriptnpm run lint- Run ESLint on TypeScript filesnpm run test- Run unit tests with Vitestnpm run test:cov- Run unit tests with code coverage reportnpm run prepublishOnly- Lint and build before publishing
When to Add JavaScript
Atlas prioritizes CSS-only solutions. Add JavaScript only when:
- Accessibility requirements - Markup/attributes must change on interaction for screen readers
- Web components - Pattern is a good candidate for a reusable, lightweight web component
Coding Guidelines
TypeScript Conventions
- Use strict TypeScript - Enable all strict checks
- Export from index.ts - All public APIs must be exported from the main entry
- JSDoc comments - Document public functions and classes
- Avoid dependencies - Keep the package lightweight
Accessibility First
- Always include ARIA attributes where appropriate
- Test with screen readers when modifying interactive behaviors
- Follow WAI-ARIA patterns for component implementations
File Organization
- behaviors/: Modules that attach behavior to existing DOM elements
- elements/: Custom elements that extend HTMLElement
- utilities/: Pure functions with no side effects
Integration Testing
Behavioral tests are in the integration package:
- Tests use Playwright
- Run from repository root:
npm run integration
Unit Testing
Unit tests use Vitest with a jsdom environment for DOM APIs.
For detailed conventions, jsdom gotchas, teardown patterns, and the [ai generated] spec tag, see unit-testing.instructions.md. Reusable Copilot prompts live in .github/prompts/ — invoke /write-unit-tests or /improve-test-coverage.
Running Tests
npm run test- Run all unit tests (fromjs/folder or repo root)npm run test:cov- Run tests with code coverage reportnpx vitest --watch- Watch mode during development (fromjs/folder)npx vitest run test/utilities/util.test.ts- Run a specific test file
Writing Tests
- Place test files in
test/- Mirror thesrc/folder structure (e.g.,test/utilities/util.test.tsforsrc/utilities/util.ts) - Import from vitest - Use
import { describe, it, expect } from 'vitest' - Use jsdom for DOM tests - The test environment provides
document,window, etc. - Test pure functions directly - For utilities, test inputs and outputs
- Test DOM behaviors - For behaviors/elements, create DOM fixtures and assert side effects
Coverage
- Coverage uses the
v8provider via@vitest/coverage-v8 - Reports are generated in
js/coverage/(text, JSON summary, and HTML) - Coverage runs automatically in CI and is reported in the GitHub Actions job summary
When Making Changes
- Run
npm run lintbefore committing - Build with
npm run buildto verify compilation - Run
npm run testto ensure all unit tests pass - Test interactively with the site package
- Add unit tests for new utilities and pure functions
- Add integration tests for new behaviors in the
integrationpackage