Skip to content

Commit

Permalink
Try inline
Browse files Browse the repository at this point in the history
  • Loading branch information
banga committed Dec 31, 2023
1 parent 67c5120 commit 264f500
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
14 changes: 0 additions & 14 deletions e250bec.snapshot

This file was deleted.

54 changes: 39 additions & 15 deletions test.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
import { exec } from 'child_process';
import fs from 'fs';
import { spawnSync } from 'child_process';
import assert from 'assert';
import * as util from 'util';
const execAsync = util.promisify(exec);

async function main() {
const hash = 'e250bec';
const snapshotPath = `${hash}.snapshot`;
const { stdout, stderr } = await execAsync(
`git show ${hash} | node ./build/index.mjs --color`
const input = `
commit e250bec66b6c39d4c2f9e0e52a18245f16a7195a
Author: Shrey Banga <banga.shrey@gmail.com>
Date: Fri Dec 29 11:14:25 2023 -0500
Exclude lockfiles from diffs
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..c72d334
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+# exclude lock files from git diff
+package-lock.json -diff
+yarn.lock -diff
`;
const expected = `
commit e250bec66b6c39d4c2f9e0e52a18245f16a7195a  
Author: Shrey Banga <banga.shrey@gmail.com>  
Date: Fri Dec 29 11:14:25 2023 -0500  
 
 Exclude lockfiles from diffs 
 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 ■■ .gitattributes 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -0,0 +1,3 @@ 
  1  + # exclude lock files from git diff 
  2  + package-lock.json -diff 
  3  + yarn.lock -diff 
  4  
`;
const { stdout, stderr } = spawnSync(
'node',
['./build/index.mjs', '--color'],
{ input, encoding: 'utf-8' }
);
console.log({ stdout, stderr });
if (fs.existsSync(snapshotPath)) {
const expected = fs.readFileSync(snapshotPath, 'utf-8');
assert.equal(stdout, expected);
} else {
fs.writeFileSync(snapshotPath, stdout);
console.log(`Wrote snapshot to ${snapshotPath}`);
}
assert.equal(stdout, expected);
}

main();

0 comments on commit 264f500

Please sign in to comment.