Skip to content

Commit

Permalink
test: add test case for XDG_CONFIG_HOME env
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Oct 19, 2024
1 parent ac65ce9 commit 027bc55
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,46 @@ Deno.test({
}
},
});

Deno.test({
name: 'respect global init script from XDG_CONFIG_HOME env',
permissions: {
read: true,
write: true,
run: true,
env: true,
},
async fn() {
await using sbox = await sandbox();
const xdgConfigHome = Deno.env.get('XDG_CONFIG_HOME');
try {
const cwd = Deno.cwd();
await expectCommonGitInit(cwd, true);
await expectCommonInit(cwd);

const configPath = path.join(cwd, '.config');
Deno.env.set('XDG_CONFIG_HOME', configPath);
await Deno.mkdir(path.join(configPath, 'githooks'), { recursive: true });

const initScript = '\
#!/usr/bin/env sh\n\
export GITHOOKS=0\n\
echo "hello"\n\
';
await Deno.writeTextFile(path.join(configPath, 'githooks/init'), initScript);
const { success, stderr } = await expectCommonCommit();
const err = new TextDecoder().decode(stderr);
expect(err).not.toContain('Checked 1 file');
expect(err).toContain('hello');
expect(success).toBe(true);
} finally {
await sbox[Symbol.asyncDispose]();
if (xdgConfigHome) {
Deno.env.set('XDG_CONFIG_HOME', xdgConfigHome);
} else {
Deno.env.delete('XDG_CONFIG_HOME');
}
}
},
});

0 comments on commit 027bc55

Please sign in to comment.