diff --git a/test/fixtures/test_stage.ts b/test/fixtures/test_stage.ts index 7c6eb8a..b6dbd37 100644 --- a/test/fixtures/test_stage.ts +++ b/test/fixtures/test_stage.ts @@ -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 { return await execStaged(this.cwd, tasks, TEST_STAGE_OPTIONS); } diff --git a/test/integrations/symlinks.ts b/test/integrations/symlinks.ts new file mode 100644 index 0000000..7a77128 --- /dev/null +++ b/test/integrations/symlinks.ts @@ -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((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); + }); +}); diff --git a/test/stage.ts b/test/stage.ts index ee4cd84..dbfc49e 100644 --- a/test/stage.ts +++ b/test/stage.ts @@ -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(); @@ -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( @@ -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(); @@ -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']); @@ -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']);