Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(ci): changedSinceMergeBase builds its repositories once, and each lookup gets its own test budget (#9073)

Christopher Chedeaub450ce680920
diff --git a/.github/scripts/a11y-pr-contracts.test.mjs b/.github/scripts/a11y-pr-contracts.test.mjs
index a7d3ebf2f1..85a362edc2 100644
--- a/.github/scripts/a11y-pr-contracts.test.mjs
+++ b/.github/scripts/a11y-pr-contracts.test.mjs
@@ -9,7 +9,15 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
-import {describe, expect, it} from 'vitest';
+import {
+ afterAll,
+ afterEach,
+ beforeAll,
+ beforeEach,
+ describe,
+ expect,
+ it,
+} from 'vitest';
import {
auditArgs,
@@ -416,30 +424,47 @@ describe('changedSinceMergeBase', () => {
);
};
- it("lists the branch's own changes and never makes a full clone shallow", () => {
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-pr-a11y-'));
- const cwd = process.cwd();
- try {
- const origin = path.join(dir, 'origin');
- fs.mkdirSync(origin);
- git(origin, 'init', '-q', '-b', 'main');
- for (const n of ['1', '2', '3']) commit(origin, 'base.txt', n);
- const clone = path.join(dir, 'clone');
- git(dir, 'clone', '-q', origin, clone);
- git(clone, 'checkout', '-qb', 'feature');
- commit(clone, 'feature.txt', 'f');
- git(clone, 'push', '-q', 'origin', 'feature');
- commit(origin, 'later.txt', 'l');
- process.chdir(clone);
- expect(changedSinceMergeBase('main')).toEqual(['feature.txt']);
- expect(changedSinceMergeBase('origin/main')).toEqual(['feature.txt']);
- expect(git(clone, 'rev-parse', '--is-shallow-repository')).toBe('false');
- expect(changedSinceMergeBase('no-such-ref')).toBeNull();
- expect(changedSinceMergeBase(undefined)).toBeNull();
- } finally {
- process.chdir(cwd);
- fs.rmSync(dir, {recursive: true, force: true});
- }
+ // An origin whose main has three commits, and a full clone whose feature
+ // branch adds one file; main then moves on. Built once: each lookup below
+ // gets its own test budget, since every git call is a process of its own.
+ const cwd = process.cwd();
+ let dir = '';
+ let clone = '';
+ beforeAll(() => {
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-pr-a11y-'));
+ const origin = path.join(dir, 'origin');
+ fs.mkdirSync(origin);
+ git(origin, 'init', '-q', '-b', 'main');
+ for (const n of ['1', '2', '3']) commit(origin, 'base.txt', n);
+ clone = path.join(dir, 'clone');
+ git(dir, 'clone', '-q', origin, clone);
+ git(clone, 'checkout', '-qb', 'feature');
+ commit(clone, 'feature.txt', 'f');
+ git(clone, 'push', '-q', 'origin', 'feature');
+ commit(origin, 'later.txt', 'l');
+ });
+ afterAll(() => {
+ fs.rmSync(dir, {recursive: true, force: true});
+ });
+ beforeEach(() => {
+ process.chdir(clone);
+ });
+ afterEach(() => {
+ process.chdir(cwd);
+ });
+
+ it("lists the branch's own changes against a local base", () => {
+ expect(changedSinceMergeBase('main')).toEqual(['feature.txt']);
+ });
+
+ it('lists them against the remote base, and never makes a full clone shallow', () => {
+ expect(changedSinceMergeBase('origin/main')).toEqual(['feature.txt']);
+ expect(git(clone, 'rev-parse', '--is-shallow-repository')).toBe('false');
+ });
+
+ it('lists nothing for a base it cannot find, or no base', () => {
+ expect(changedSinceMergeBase('no-such-ref')).toBeNull();
+ expect(changedSinceMergeBase(undefined)).toBeNull();
});
});