Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/fixtures/test_stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ export class TestStage extends Stage {
fs.mkdirSync(this.resolve(relativePath), { recursive: true });
}

public rename(relativeOldPath: string, relativeNewPath: string) {
fs.renameSync(this.resolve(relativeOldPath), this.resolve(relativeNewPath));
}

public rm(relativePath: string) {
fs.rmSync(this.resolve(relativePath), { recursive: true, force: true });
}

public symlink(relativeTarget: string, relativePath: string) {
fs.symlinkSync(this.resolve(relativeTarget), this.resolve(relativePath));
}

public async execStaged(tasks: ExecStagedUserConfig): Promise<boolean> {
return await execStaged(this.cwd, tasks, TEST_STAGE_OPTIONS);
}
Expand Down
39 changes: 39 additions & 0 deletions test/integrations/symlinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { TASK_EXIT_0, TASK_EXIT_1 } from '../fixtures/tasks';
import { TestStage } from '../fixtures/test_stage';
import assert from 'node:assert';
import child_process from 'node:child_process';
import path from 'node:path';
import { describe, it } from 'node:test';

const BIN = path.resolve(import.meta.dirname, '../../dist/bin/cli.js');

describe('symlinks', () => {
it('runs with symlinked config file', async () => {
const stage = TestStage.create();
stage.writeFile(
'symlinked.config.ts',
`export default ['${TASK_EXIT_1}'];`,
);
stage.symlink('symlinked.config.ts', 'exec-staged.config.ts');

const child = child_process.spawn('node', [BIN], {
cwd: stage.cwd,
});

const closed = new Promise<void>((resolve) => {
child.once('close', () => resolve());
});

await closed;

assert.equal(child.exitCode, 1);
});

it('runs with symlinked git directory', async () => {
const stage = TestStage.create();
stage.rename('.git', '.git-symlinked');
stage.symlink('.git-symlinked', '.git');

assert.equal(await stage.execStaged([TASK_EXIT_0]), true);
});
});
15 changes: 5 additions & 10 deletions test/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ describe('Stage', () => {
stage.writeFile('test.old', 'contents');
stage.git(['add', 'test.old']);
stage.git(['commit', '-m', 'add file']);
stage.rm('test.old');
stage.writeFile('test.new', 'contents');
stage.rename('test.old', 'test.new');
stage.git(['add', 'test.old', 'test.new']);

stage.prepare();
Expand Down Expand Up @@ -246,8 +245,7 @@ describe('Stage', () => {
stage.writeFile('test.old', 'contents');
stage.git(['add', 'test.old']);
stage.git(['commit', '-m', 'add file']);
stage.rm('test.old');
stage.writeFile('test.new', 'contents');
stage.rename('test.old', 'test.new');
stage.git(['add', 'test.old', 'test.new']);

assert.equal(
Expand Down Expand Up @@ -378,8 +376,7 @@ describe('Stage', () => {
stage.writeFile('test.old', 'contents');
stage.git(['add', 'test.old']);
stage.git(['commit', '-m', 'add file']);
stage.rm('test.old');
stage.writeFile('test.new', 'contents');
stage.rename('test.old', 'test.new');
stage.git(['add', 'test.old', 'test.new']);

stage.prepare();
Expand Down Expand Up @@ -641,8 +638,7 @@ describe('Stage', () => {
stage.writeFile('test.old', 'contents');
stage.git(['add', 'test.old']);
stage.git(['commit', '-m', 'add file']);
stage.rm('test.old');
stage.writeFile('test.new', 'contents');
stage.rename('test.old', 'test.new');
stage.git(['add', 'test.old', 'test.new']);

const oldStatus = stage.git(['status', '-z']);
Expand Down Expand Up @@ -914,8 +910,7 @@ describe('Stage', () => {
stage.writeFile('test.old', 'contents');
stage.git(['add', 'test.old']);
stage.git(['commit', '-m', 'add file']);
stage.rm('test.old');
stage.writeFile('test.new', 'contents');
stage.rename('test.old', 'test.new');
stage.git(['add', 'test.old', 'test.new']);

const oldStatus = stage.git(['status', '-z']);
Expand Down